Skip to content

Commit 37f0bb4

Browse files
committed
Add tests for column-major strides
1 parent 14fa527 commit 37f0bb4

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

cpp/src/arrow/tensor-test.cc

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ TEST(TestNumericTensor, ElementAccess) {
127127
ASSERT_EQ(11.1f, t_f32.Value({2, 2}));
128128
}
129129

130-
TEST(TestNumericTensor, ElementAccessWithStrides) {
130+
TEST(TestNumericTensor, ElementAccessWithRowMajorStrides) {
131131
std::vector<int64_t> shape = {3, 4};
132132

133133
const int64_t i64_size = sizeof(int64_t);
@@ -138,6 +138,8 @@ TEST(TestNumericTensor, ElementAccessWithStrides) {
138138
NumericTensor<Int64Type> t_i64(buffer_i64, shape, strides_i64);
139139

140140
ASSERT_EQ(1, t_i64.Value({0, 0}));
141+
ASSERT_EQ(2, t_i64.Value({0, 1}));
142+
ASSERT_EQ(4, t_i64.Value({0, 3}));
141143
ASSERT_EQ(5, t_i64.Value({1, 0}));
142144
ASSERT_EQ(6, t_i64.Value({1, 1}));
143145
ASSERT_EQ(11, t_i64.Value({2, 2}));
@@ -151,6 +153,39 @@ TEST(TestNumericTensor, ElementAccessWithStrides) {
151153
NumericTensor<FloatType> t_f32(buffer_f32, shape, strides_f32);
152154

153155
ASSERT_EQ(1.1f, t_f32.Value({0, 0}));
156+
ASSERT_EQ(2.1f, t_f32.Value({0, 1}));
157+
ASSERT_EQ(4.1f, t_f32.Value({0, 3}));
158+
ASSERT_EQ(5.1f, t_f32.Value({1, 0}));
159+
ASSERT_EQ(6.1f, t_f32.Value({1, 1}));
160+
ASSERT_EQ(11.1f, t_f32.Value({2, 2}));
161+
}
162+
163+
TEST(TestNumericTensor, ElementAccessWithColumnMajorStrides) {
164+
std::vector<int64_t> shape = {3, 4};
165+
166+
const int64_t i64_size = sizeof(int64_t);
167+
std::vector<int64_t> values_i64 = {1, 5, 9, 0, 2, 6, 10, 0, 3, 7, 11, 0, 4, 8, 12, 0};
168+
std::vector<int64_t> strides_i64 = {i64_size, i64_size * 4};
169+
std::shared_ptr<Buffer> buffer_i64(Buffer::Wrap(values_i64));
170+
NumericTensor<Int64Type> t_i64(buffer_i64, shape, strides_i64);
171+
172+
ASSERT_EQ(1, t_i64.Value({0, 0}));
173+
ASSERT_EQ(2, t_i64.Value({0, 1}));
174+
ASSERT_EQ(4, t_i64.Value({0, 3}));
175+
ASSERT_EQ(5, t_i64.Value({1, 0}));
176+
ASSERT_EQ(6, t_i64.Value({1, 1}));
177+
ASSERT_EQ(11, t_i64.Value({2, 2}));
178+
179+
const int64_t f32_size = sizeof(float);
180+
std::vector<float> values_f32 = {1.1f, 5.1f, 9.1f, 0.0f, 2.1f, 6.1f, 10.1f, 0.0f,
181+
3.1f, 7.1f, 11.1f, 0.0f, 4.1f, 8.1f, 12.1f, 0.0f};
182+
std::vector<int64_t> strides_f32 = {f32_size, f32_size * 4};
183+
std::shared_ptr<Buffer> buffer_f32(Buffer::Wrap(values_f32));
184+
NumericTensor<FloatType> t_f32(buffer_f32, shape, strides_f32);
185+
186+
ASSERT_EQ(1.1f, t_f32.Value({0, 0}));
187+
ASSERT_EQ(2.1f, t_f32.Value({0, 1}));
188+
ASSERT_EQ(4.1f, t_f32.Value({0, 3}));
154189
ASSERT_EQ(5.1f, t_f32.Value({1, 0}));
155190
ASSERT_EQ(6.1f, t_f32.Value({1, 1}));
156191
ASSERT_EQ(11.1f, t_f32.Value({2, 2}));

0 commit comments

Comments
 (0)