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


##########
ruby/red-arrow/test/test-tensor.rb:
##########
@@ -16,6 +16,103 @@
 # under the License.
 
 class TensorTest < Test::Unit::TestCase
+  sub_test_case("class methods") do
+    sub_test_case(".new") do
+      def setup
+        @raw_tensor = [
+          [
+            [1, 2, 3, 4],
+            [5, 6, 7, 8],
+          ],
+          [
+            [9, 10, 11, 12],
+            [13, 14, 15, 16],
+          ],
+          [
+            [17, 18, 19, 20],
+            [21, 22, 23, 24],
+          ],
+        ]
+        @shape = [3, 2, 4]
+        @strides = [8, 4, 1]
+      end
+
+      test("Array") do
+        tensor = Arrow::Tensor.new(@raw_tensor)
+        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("Array, data_type: Symbol") do
+        tensor = Arrow::Tensor.new(@raw_tensor, data_type: :int32)
+        assert_equal({
+                       value_data_type: Arrow::Int32DataType.new,
+                       buffer: @raw_tensor.flatten.pack("l*"),
+                       shape: @shape,
+                       strides: @strides.collect {|x| x * 4},
+                       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("Array, dimension_names: Array<String>") do
+        tensor = Arrow::Tensor.new(@raw_tensor,
+                                   dimension_names: ["a", "b", "c"])
+        assert_equal({
+                       value_data_type: Arrow::UInt8DataType.new,
+                       buffer: @raw_tensor.flatten.pack("C*"),
+                       shape: @shape,
+                       strides: @strides,
+                       dimension_names: ["a", "b", "c"],
+                     },
+                     {
+                       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("Array, dimension_names: Array<Symbol>") do
+        tensor = Arrow::Tensor.new(@raw_tensor,
+                                   dimension_names: [:a, :b, :c])
+        assert_equal({
+                       value_data_type: Arrow::UInt8DataType.new,
+                       buffer: @raw_tensor.flatten.pack("C*"),
+                       shape: @shape,
+                       strides: @strides,
+                       dimension_names: ["a", "b", "c"],
+                     },
+                     {
+                       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

Review Comment:
   I don't see a test passing a different `strides` explicitly. Can you add 
one? Or does it just not make sense to change the strides?



-- 
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