Skip to content

Commit 9a66bdc

Browse files
hiroyuki-satokou
andauthored
GH-46400: [GLib] Add GArrowFixedShapeDataType#permutation (#46401)
### Rationale for this change The C++ API implemented `FixedShapeTensor::permutation()` instance method. GLib was not yet supported. ### What changes are included in this PR? Add `GArrowFixedShapeDataType#permutation` instance method. ### Are these changes tested? Yes. ### Are there any user-facing changes? Yes. * GitHub Issue: #46400 Lead-authored-by: Hiroyuki Sato <hiroysato@gmail.com> Co-authored-by: Sutou Kouhei <kou@cozmixng.org> Signed-off-by: Sutou Kouhei <kou@clear-code.com>
1 parent 1b792e3 commit 9a66bdc

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

c_glib/arrow-glib/basic-data-type.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2366,6 +2366,24 @@ garrow_fixed_shape_tensor_data_type_get_shape(GArrowFixedShapeTensorDataType *da
23662366
return arrow_shape.data();
23672367
}
23682368

2369+
/**
2370+
* garrow_fixed_shape_tensor_data_type_get_permutation:
2371+
* @data_type: A #GArrowFixedShapeTensorDataType.
2372+
* @length: (out): Return location for the number of elements of permutation.
2373+
*
2374+
* Returns: (array length=length): Permutation of the tensor.
2375+
*/
2376+
const gint64 *
2377+
garrow_fixed_shape_tensor_data_type_get_permutation(
2378+
GArrowFixedShapeTensorDataType *data_type, gsize *length)
2379+
{
2380+
auto arrow_data_type = std::static_pointer_cast<arrow::extension::FixedShapeTensorType>(
2381+
garrow_data_type_get_raw(GARROW_DATA_TYPE(data_type)));
2382+
2383+
const auto &arrow_permutation = arrow_data_type->permutation();
2384+
*length = arrow_permutation.size();
2385+
return arrow_permutation.data();
2386+
}
23692387
G_END_DECLS
23702388

23712389
GArrowDataType *

c_glib/arrow-glib/basic-data-type.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -830,4 +830,9 @@ GARROW_AVAILABLE_IN_21_0
830830
const gint64 *
831831
garrow_fixed_shape_tensor_data_type_get_shape(GArrowFixedShapeTensorDataType *data_type,
832832
gsize *length);
833+
834+
GARROW_AVAILABLE_IN_21_0
835+
const gint64 *
836+
garrow_fixed_shape_tensor_data_type_get_permutation(
837+
GArrowFixedShapeTensorDataType *data_type, gsize *length);
833838
G_END_DECLS

c_glib/test/test-fixed-shape-tensor-data-type.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ def test_shape
3636
assert_equal([3, 4], @data_type.shape)
3737
end
3838

39+
def test_permutation
40+
assert_equal([1, 0], @data_type.permutation)
41+
end
42+
3943
def test_to_s
4044
assert do
4145
@data_type.to_s.start_with?("extension<arrow.fixed_shape_tensor")
@@ -47,8 +51,7 @@ def test_nil_permutation
4751
[3, 4],
4852
nil,
4953
["x", "y"])
50-
# TODO: Use Arrow::FixedShapeTensorDataType#permutation
51-
assert_equal(Arrow::Type::EXTENSION, data_type.id)
54+
assert_equal([], data_type.permutation)
5255
end
5356

5457
def test_nil_dim_names

0 commit comments

Comments
 (0)