You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by ko...@apache.org on 2025/05/15 06:58:03 UTC

(arrow) branch main updated: GH-46450: [GLib] Add GArrowFixedShapeDataType#strides (#46451)

This is an automated email from the ASF dual-hosted git repository.

kou pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/main by this push:
     new 50068bcc36 GH-46450: [GLib] Add GArrowFixedShapeDataType#strides (#46451)
50068bcc36 is described below

commit 50068bcc360c4df0528deaf0c7e9e7e52e592ce8
Author: Hiroyuki Sato <hi...@gmail.com>
AuthorDate: Thu May 15 15:57:57 2025 +0900

    GH-46450: [GLib] Add GArrowFixedShapeDataType#strides (#46451)
    
    ### Rationale for this change
    
    The C++ API implemented `FixedShapeTensor::strides()` instance method. GLib was not yet supported.
    
    ### What changes are included in this PR?
    
    Add `GArrowFixedShapeDataType#strides` instance method.
    
    ### Are these changes tested?
    
    Yes.
    
    ### Are there any user-facing changes?
    
    Yes.
    
    * GitHub Issue: #46450
    
    Lead-authored-by: Hiroyuki Sato <hi...@gmail.com>
    Co-authored-by: Sutou Kouhei <ko...@cozmixng.org>
    Signed-off-by: Sutou Kouhei <ko...@clear-code.com>
---
 c_glib/arrow-glib/basic-data-type.cpp            | 20 ++++++++++++++++++++
 c_glib/arrow-glib/basic-data-type.h              |  5 +++++
 c_glib/test/test-fixed-shape-tensor-data-type.rb |  7 ++++++-
 3 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/c_glib/arrow-glib/basic-data-type.cpp b/c_glib/arrow-glib/basic-data-type.cpp
index 8494ef6dc0..458a768ac2 100644
--- a/c_glib/arrow-glib/basic-data-type.cpp
+++ b/c_glib/arrow-glib/basic-data-type.cpp
@@ -2410,6 +2410,26 @@ garrow_fixed_shape_tensor_data_type_get_dim_names(
   dim_names[n] = nullptr;
   return dim_names;
 }
+
+/**
+ * garrow_fixed_shape_tensor_data_type_get_strides:
+ * @data_type: A #GArrowFixedShapeTensorDataType.
+ * @length: (out): Return location for the number of strides of tensor shape.
+ *
+ * Returns: (array length=length): Strides in bytes for each tensor dimension.
+ *
+ * Since: 21.0.0
+ */
+const gint64 *
+garrow_fixed_shape_tensor_data_type_get_strides(GArrowFixedShapeTensorDataType *data_type,
+                                                gsize *length)
+{
+  auto arrow_data_type = std::static_pointer_cast<arrow::extension::FixedShapeTensorType>(
+    garrow_data_type_get_raw(GARROW_DATA_TYPE(data_type)));
+  const auto &arrow_strides = arrow_data_type->strides();
+  *length = arrow_strides.size();
+  return arrow_strides.data();
+}
 G_END_DECLS
 
 GArrowDataType *
diff --git a/c_glib/arrow-glib/basic-data-type.h b/c_glib/arrow-glib/basic-data-type.h
index 5bccd24ac8..014180120b 100644
--- a/c_glib/arrow-glib/basic-data-type.h
+++ b/c_glib/arrow-glib/basic-data-type.h
@@ -840,4 +840,9 @@ GARROW_AVAILABLE_IN_21_0
 gchar **
 garrow_fixed_shape_tensor_data_type_get_dim_names(
   GArrowFixedShapeTensorDataType *data_type);
+
+GARROW_AVAILABLE_IN_21_0
+const gint64 *
+garrow_fixed_shape_tensor_data_type_get_strides(GArrowFixedShapeTensorDataType *data_type,
+                                                gsize *length);
 G_END_DECLS
diff --git a/c_glib/test/test-fixed-shape-tensor-data-type.rb b/c_glib/test/test-fixed-shape-tensor-data-type.rb
index 3c48a9076a..fa7625cbae 100644
--- a/c_glib/test/test-fixed-shape-tensor-data-type.rb
+++ b/c_glib/test/test-fixed-shape-tensor-data-type.rb
@@ -40,6 +40,10 @@ class TestFixedShapeTensorDataType < Test::Unit::TestCase
     assert_equal([1, 0], @data_type.permutation)
   end
 
+  def test_strides
+    assert_equal([8, 32], @data_type.strides)
+  end
+
   def test_dim_names
     assert_equal(["x", "y"], @data_type.dim_names)
   end
@@ -55,7 +59,8 @@ class TestFixedShapeTensorDataType < Test::Unit::TestCase
                                                     [3, 4],
                                                     nil,
                                                     ["x", "y"])
-    assert_equal([], data_type.permutation)
+    assert_equal([[], [32, 8]],
+                 [data_type.permutation, data_type.strides])
   end
 
   def test_nil_dim_names