Class: Arrow::Tensor
- Inherits:
-
Object
- Object
- Arrow::Tensor
- Defined in:
- lib/arrow/tensor.rb
Instance Method Summary collapse
- #dimension_names ⇒ Object
-
#initialize(*args, data_type: nil, data: nil, shape: nil, strides: nil, dimension_names: nil) ⇒ Tensor
constructor
Creates a new Tensor.
- #initialize_raw ⇒ Object
- #to_arrow ⇒ Object
- #to_arrow_array ⇒ Object
- #to_arrow_chunked_array ⇒ Object
Constructor Details
#initialize(raw_tensor, data_type: nil, shape: nil, dimension_names: nil) ⇒ Tensor #initialize(data_type, data, shape, strides, dimension_names) ⇒ Tensor
Creates a new Arrow::Tensor.
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/arrow/tensor.rb', line 105 def initialize(*args, data_type: nil, data: nil, shape: nil, strides: nil, dimension_names: nil) n_args = args.size case n_args when 1 converter = RawTensorConverter.new(args[0], data_type: data_type, shape: shape, strides: strides, dimension_names: dimension_names) data_type = converter.data_type data = converter.data shape = converter.shape strides = converter.strides dimension_names = converter.dimension_names when 0, 2..5 data_type = args[0] || data_type data = args[1] || data shape = args[2] || shape strides = args[3] || strides dimension_names = args[4] || dimension_names if data_type.nil? raise ArgumentError, "data_type: is missing: #{data.inspect}" end else = "wrong number of arguments (given #{n_args}, expected 0..5)" raise ArgumentError, end initialize_raw(DataType.resolve(data_type), data, shape, strides, dimension_names) end |
Instance Method Details
#dimension_names ⇒ Object
144 145 146 147 148 |
# File 'lib/arrow/tensor.rb', line 144 def dimension_names n_dimensions.times.collect do |i| get_dimension_name(i) end end |
#initialize_raw ⇒ Object
22 |
# File 'lib/arrow/tensor.rb', line 22 alias_method :initialize_raw, :initialize |
#to_arrow ⇒ Object
150 151 152 |
# File 'lib/arrow/tensor.rb', line 150 def to_arrow self end |
#to_arrow_array ⇒ Object
154 155 156 157 158 159 160 161 162 |
# File 'lib/arrow/tensor.rb', line 154 def to_arrow_array if n_dimensions != 1 raise RangeError, "must be 1 dimensional tensor: #{shape.inspect}" end value_data_type.array_class.new(size, buffer, nil, 0) end |
#to_arrow_chunked_array ⇒ Object
164 165 166 |
# File 'lib/arrow/tensor.rb', line 164 def to_arrow_chunked_array ChunkedArray.new([to_arrow_array]) end |