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 719be48f15 GH-46398: [GLib] Add 
GArrowFixedShapeTensorDataType#n_dimensions (#46399)
719be48f15 is described below

commit 719be48f15e1afc60dbcda477bd3f927aca06d90
Author: Hiroyuki Sato <[email protected]>
AuthorDate: Wed May 21 10:04:12 2025 +0900

    GH-46398: [GLib] Add GArrowFixedShapeTensorDataType#n_dimensions (#46399)
    
    ### Rationale for this change
    
    The C++ API implemented `FixedShapeTensor::ndim()` instance method. GLib 
was not yet supported.
    
    ### What changes are included in this PR?
    
    Add `GArrowFixedShapeTensorDataType#n_dimensions` instance method.
    
    ### Are these changes tested?
    
    Yes.
    
    ### Are there any user-facing changes?
    
    Yes.
    * GitHub Issue: #46398
    
    Lead-authored-by: Hiroyuki Sato <[email protected]>
    Co-authored-by: Sutou Kouhei <[email protected]>
    Signed-off-by: Sutou Kouhei <[email protected]>
---
 c_glib/arrow-glib/basic-data-type.cpp            | 45 ++++++++++++++++++++++++
 c_glib/test/test-fixed-shape-tensor-data-type.rb |  4 +++
 2 files changed, 49 insertions(+)

diff --git a/c_glib/arrow-glib/basic-data-type.cpp 
b/c_glib/arrow-glib/basic-data-type.cpp
index 45665b8264..8214c21346 100644
--- a/c_glib/arrow-glib/basic-data-type.cpp
+++ b/c_glib/arrow-glib/basic-data-type.cpp
@@ -2270,10 +2270,35 @@ garrow_string_view_data_type_new(void)
   return data_type;
 }
 
+enum {
+  PROP_N_DIMENSIONS = 1
+};
+
 G_DEFINE_TYPE(GArrowFixedShapeTensorDataType,
               garrow_fixed_shape_tensor_data_type,
               GARROW_TYPE_EXTENSION_DATA_TYPE)
 
+static void
+garrow_fixed_shape_tensor_data_type_get_property(GObject *object,
+                                                 guint prop_id,
+                                                 GValue *value,
+                                                 GParamSpec *pspec)
+{
+  switch (prop_id) {
+  case PROP_N_DIMENSIONS:
+    {
+      auto arrow_data_type =
+        std::static_pointer_cast<arrow::extension::FixedShapeTensorType>(
+          garrow_data_type_get_raw(GARROW_DATA_TYPE(object)));
+      g_value_set_uint64(value, arrow_data_type->ndim());
+    }
+    break;
+  default:
+    G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+    break;
+  }
+}
+
 static void
 garrow_fixed_shape_tensor_data_type_init(GArrowFixedShapeTensorDataType 
*object)
 {
@@ -2282,6 +2307,26 @@ 
garrow_fixed_shape_tensor_data_type_init(GArrowFixedShapeTensorDataType *object)
 static void
 
garrow_fixed_shape_tensor_data_type_class_init(GArrowFixedShapeTensorDataTypeClass
 *klass)
 {
+  GParamSpec *spec;
+
+  auto gobject_class = G_OBJECT_CLASS(klass);
+  gobject_class->get_property = 
garrow_fixed_shape_tensor_data_type_get_property;
+
+  /**
+   * GArrowFixedShapeTensorDataType::n-dimensions:
+   *
+   * The number of dimensions of tensor elements.
+   *
+   * Since: 21.0.0
+   */
+  spec = g_param_spec_uint64("n_dimensions",
+                             "N dimensions",
+                             "Number of dimensions of tensor elements",
+                             0,
+                             G_MAXUINT64,
+                             0,
+                             static_cast<GParamFlags>(G_PARAM_READABLE));
+  g_object_class_install_property(gobject_class, PROP_N_DIMENSIONS, spec);
 }
 
 /**
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 fa7625cbae..abf8bf00db 100644
--- a/c_glib/test/test-fixed-shape-tensor-data-type.rb
+++ b/c_glib/test/test-fixed-shape-tensor-data-type.rb
@@ -32,6 +32,10 @@ class TestFixedShapeTensorDataType < Test::Unit::TestCase
                  [@data_type.name, @data_type.extension_name])
   end
 
+  def test_n_dimensions
+    assert_equal(2, @data_type.n_dimensions)
+  end
+
   def test_shape
     assert_equal([3, 4], @data_type.shape)
   end

Reply via email to