MCPcopy Create free account
hub / github.com/apache/arrow / TEST

Function TEST

cpp/src/arrow/sparse_tensor_test.cc:57–91  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

55// SparseCOOIndex
56
57TEST(TestSparseCOOIndex, MakeRowMajorCanonical) {
58 std::vector<int32_t> values = {0, 0, 0, 0, 0, 2, 0, 1, 1, 0, 1, 3, 0, 2, 0, 0, 2, 2,
59 1, 0, 1, 1, 0, 3, 1, 1, 0, 1, 1, 2, 1, 2, 1, 1, 2, 3};
60 auto data = Buffer::Wrap(values);
61 std::vector<int64_t> shape = {12, 3};
62 std::vector<int64_t> strides = {3 * sizeof(int32_t), sizeof(int32_t)}; // Row-major
63
64 // OK
65 std::shared_ptr<SparseCOOIndex> si;
66 ASSERT_OK_AND_ASSIGN(si, SparseCOOIndex::Make(int32(), shape, strides, data));
67 ASSERT_EQ(shape, si->indices()->shape());
68 ASSERT_EQ(strides, si->indices()->strides());
69 ASSERT_EQ(data->data(), si->indices()->raw_data());
70 ASSERT_TRUE(si->is_canonical());
71
72 // Non-integer type
73 auto res = SparseCOOIndex::Make(float32(), shape, strides, data);
74 ASSERT_RAISES(TypeError, res);
75
76 // Non-matrix indices
77 res = SparseCOOIndex::Make(int32(), {4, 3, 4}, strides, data);
78 ASSERT_RAISES(Invalid, res);
79
80 // Non-contiguous indices
81 res = SparseCOOIndex::Make(int32(), {6, 3}, {6 * sizeof(int32_t), 2 * sizeof(int32_t)},
82 data);
83 ASSERT_RAISES(Invalid, res);
84
85 // Make from sparse tensor properties
86 // (shape is arbitrary 3-dim, non-zero length = 12)
87 ASSERT_OK_AND_ASSIGN(si, SparseCOOIndex::Make(int32(), {99, 99, 99}, 12, data));
88 ASSERT_EQ(shape, si->indices()->shape());
89 ASSERT_EQ(strides, si->indices()->strides());
90 ASSERT_EQ(data->data(), si->indices()->raw_data());
91}
92
93TEST(TestSparseCOOIndex, MakeRowMajorNonCanonical) {
94 std::vector<int32_t> values = {0, 0, 0, 0, 0, 2, 0, 1, 1, 0, 1, 3, 0, 2, 0, 1, 0, 1,

Callers

nothing calls this directly

Calls 9

WrapFunction · 0.85
indicesMethod · 0.80
stridesMethod · 0.80
raw_dataMethod · 0.80
ASSERT_OK_AND_ASSIGNFunction · 0.70
MakeFunction · 0.70
shapeMethod · 0.45
dataMethod · 0.45
ToStringMethod · 0.45

Tested by

no test coverage detected