mrkn commented on code in PR #14381:
URL: https://github.com/apache/arrow/pull/14381#discussion_r995535048


##########
ruby/red-arrow/test/test-tensor.rb:
##########
@@ -110,6 +110,131 @@ def setup
                        dimension_names: tensor.dimension_names,
                      })
       end
+
+      test("Array, strides:") do
+        message = "strides: must not be specified: #{@strides.inspect}"
+        assert_raise(ArgumentError.new(message)) do
+          Arrow::Tensor.new(@raw_tensor, strides: @strides)
+        end
+      end
+
+      test("Arrow::Buffer, data_type:, shape:") do
+        data_type = :uint8
+        data = Arrow::Buffer.new(@raw_tensor.flatten.pack("C*").freeze)
+        tensor = Arrow::Tensor.new(data,
+                                   data_type: data_type,
+                                   shape: @shape)
+        assert_equal({
+                       value_data_type: Arrow::UInt8DataType.new,
+                       buffer: @raw_tensor.flatten.pack("C*"),
+                       shape: @shape,
+                       strides: @strides,
+                       dimension_names: ["", "", ""],
+                     },
+                     {
+                       value_data_type: tensor.value_data_type,
+                       buffer: tensor.buffer.data.to_s,
+                       shape: tensor.shape,
+                       strides: tensor.strides,
+                       dimension_names: tensor.dimension_names,
+                     })
+      end
+
+      test("String, data_type:, shape:") do
+        data_type = :uint8
+        data = @raw_tensor.flatten.pack("C*").freeze
+        tensor = Arrow::Tensor.new(data,
+                                   data_type: data_type,
+                                   shape: @shape)
+        assert_equal({
+                       value_data_type: Arrow::UInt8DataType.new,
+                       buffer: @raw_tensor.flatten.pack("C*"),
+                       shape: @shape,
+                       strides: @strides,
+                       dimension_names: ["", "", ""],
+                     },
+                     {
+                       value_data_type: tensor.value_data_type,
+                       buffer: tensor.buffer.data.to_s,
+                       shape: tensor.shape,
+                       strides: tensor.strides,
+                       dimension_names: tensor.dimension_names,
+                     })
+      end
+
+      test("String, data_type:") do
+        data_type = :uint8
+        data = @raw_tensor.flatten.pack("C*").freeze
+        message = "shape: is missing: #{data.inspect}"
+        assert_raise(ArgumentError.new(message)) do
+          Arrow::Tensor.new(data, data_type: data_type)
+        end
+      end
+
+      test("String, shape:") do
+        data = @raw_tensor.flatten.pack("C*").freeze
+        message = "data_type: is missing: #{data.inspect}"
+        assert_raise(ArgumentError.new(message)) do
+          Arrow::Tensor.new(data, shape: @shape)
+        end
+      end
+
+      test("Symbol, Arrow::Buffer, shape:") do
+        data_type = :uint8
+        data = Arrow::Buffer.new(@raw_tensor.flatten.pack("C*").freeze)
+        tensor = Arrow::Tensor.new(data_type,
+                                   data,
+                                   shape: @shape)
+        assert_equal({
+                       value_data_type: Arrow::UInt8DataType.new,
+                       buffer: @raw_tensor.flatten.pack("C*"),
+                       shape: @shape,
+                       strides: @strides,
+                       dimension_names: ["", "", ""],
+                     },
+                     {
+                       value_data_type: tensor.value_data_type,
+                       buffer: tensor.buffer.data.to_s,
+                       shape: tensor.shape,
+                       strides: tensor.strides,
+                       dimension_names: tensor.dimension_names,
+                     })
+      end
+
+      test("Symbol, String, shape:, strides: - !contiguous and column major") 
do
+        data_type = :uint8
+        raw_tensor = [
+          [1, 2, 3, 0], # 0 is padding
+          [4, 5, 6, 0], # 0 is padding
+        ]
+        data = raw_tensor.flatten.pack("C*").freeze
+        shape = [3, 2]
+        strides = [1, 4]

Review Comment:
   @kou I meant that we can create a non-contiguous column-major tensor from 
`@raw_tensor` with the `shape` and `strides` I showed above.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to