Class: OnnxRuby::Tensor
- Inherits:
-
Object
- Object
- OnnxRuby::Tensor
- Defined in:
- lib/onnx_ruby/tensor.rb
Constant Summary collapse
- DTYPE_MAP =
{ float32: :float, float: :float, float64: :double, double: :double, int32: :int32, int: :int32, int64: :int64, bool: :bool, string: :string }.freeze
Instance Attribute Summary collapse
-
#dtype ⇒ Object
readonly
Returns the value of attribute dtype.
-
#shape ⇒ Object
readonly
Returns the value of attribute shape.
Class Method Summary collapse
- .double(data, shape: nil) ⇒ Object
- .float(data, shape: nil) ⇒ Object
- .int32(data, shape: nil) ⇒ Object
- .int64(data, shape: nil) ⇒ Object
Instance Method Summary collapse
- #flat_data ⇒ Object
-
#initialize(data, shape: nil, dtype: nil) ⇒ Tensor
constructor
A new instance of Tensor.
- #to_a ⇒ Object
Constructor Details
#initialize(data, shape: nil, dtype: nil) ⇒ Tensor
Returns a new instance of Tensor.
19 20 21 22 23 24 25 |
# File 'lib/onnx_ruby/tensor.rb', line 19 def initialize(data, shape: nil, dtype: nil) @data = data.flatten @shape = shape || infer_shape(data) @dtype = normalize_dtype(dtype || infer_dtype(@data)) validate! end |
Instance Attribute Details
#dtype ⇒ Object (readonly)
Returns the value of attribute dtype.
17 18 19 |
# File 'lib/onnx_ruby/tensor.rb', line 17 def dtype @dtype end |
#shape ⇒ Object (readonly)
Returns the value of attribute shape.
17 18 19 |
# File 'lib/onnx_ruby/tensor.rb', line 17 def shape @shape end |
Class Method Details
.double(data, shape: nil) ⇒ Object
47 48 49 |
# File 'lib/onnx_ruby/tensor.rb', line 47 def self.double(data, shape: nil) new(data, shape: shape, dtype: :double) end |
.float(data, shape: nil) ⇒ Object
35 36 37 |
# File 'lib/onnx_ruby/tensor.rb', line 35 def self.float(data, shape: nil) new(data, shape: shape, dtype: :float) end |
.int32(data, shape: nil) ⇒ Object
43 44 45 |
# File 'lib/onnx_ruby/tensor.rb', line 43 def self.int32(data, shape: nil) new(data, shape: shape, dtype: :int32) end |
.int64(data, shape: nil) ⇒ Object
39 40 41 |
# File 'lib/onnx_ruby/tensor.rb', line 39 def self.int64(data, shape: nil) new(data, shape: shape, dtype: :int64) end |
Instance Method Details
#flat_data ⇒ Object
31 32 33 |
# File 'lib/onnx_ruby/tensor.rb', line 31 def flat_data @data end |
#to_a ⇒ Object
27 28 29 |
# File 'lib/onnx_ruby/tensor.rb', line 27 def to_a reshape(@data.dup, @shape) end |