Enabling SparseTensor.Equals checks.

This commit is contained in:
Rok authored and Antoine Pitrou committed 2019-07-01 11:39:30 +02:00
1 parent 654002afe0
commit c31b8eb329
3 files changed
+40 -3

No files matched your search

+1 -2
View File
@@ -1026,9 +1026,8 @@ struct SparseTensorEqualsImpl<SparseIndexType, SparseIndexType> {
const uint8_t* left_data = left.data()->data();
const uint8_t* right_data = right.data()->data();
return memcmp(left_data, right_data,
static_cast<size_t>(byte_width * left.non_zero_length()));
static_cast<size_t>(byte_width * left.non_zero_length())) == 0;
}
};
+39
View File
@@ -182,6 +182,25 @@ TEST(TestSparseCOOTensor, CreationFromNonContiguousTensor) {
AssertCOOIndex(sidx, 11, {1, 2, 3});
}
TEST(TestSparseCOOTensor, TensorEquality) {
std::vector<int64_t> shape = {2, 3, 4};
std::vector<int64_t> values1 = {1, 0, 2, 0, 0, 3, 0, 4, 5, 0, 6, 0,
0, 11, 0, 12, 13, 0, 14, 0, 0, 15, 0, 16};
std::vector<int64_t> values2 = {0, 0, 2, 0, 0, 3, 0, 4, 5, 0, 6, 0,
0, 11, 0, 12, 13, 0, 14, 0, 0, 15, 0, 16};
std::shared_ptr<Buffer> buffer1 = Buffer::Wrap(values1);
std::shared_ptr<Buffer> buffer2 = Buffer::Wrap(values2);
NumericTensor<Int64Type> tensor1(buffer1, shape);
NumericTensor<Int64Type> tensor2(buffer1, shape);
NumericTensor<Int64Type> tensor3(buffer2, shape);
SparseTensorImpl<SparseCOOIndex> st1(tensor1);
SparseTensorImpl<SparseCOOIndex> st2(tensor2);
SparseTensorImpl<SparseCOOIndex> st3(tensor3);
ASSERT_TRUE(st1.Equals(st2));
ASSERT_TRUE(!st1.Equals(st3));
}
TEST(TestSparseCSRMatrix, CreationFromNumericTensor2D) {
std::vector<int64_t> shape = {6, 4};
std::vector<int64_t> values = {1, 0, 2, 0, 0, 3, 0, 4, 5, 0, 6, 0,
@@ -269,4 +288,24 @@ TEST(TestSparseCSRMatrix, CreationFromNonContiguousTensor) {
ASSERT_EQ(std::vector<int64_t>({0, 2, 1, 3, 0, 2, 1, 3, 0, 2, 1, 3}), indices_values);
}
TEST(TestSparseCSRMatrix, TensorEquality) {
std::vector<int64_t> shape = {6, 4};
std::vector<int64_t> values1 = {1, 0, 2, 0, 0, 3, 0, 4, 5, 0, 6, 0,
0, 11, 0, 12, 13, 0, 14, 0, 0, 15, 0, 16};
std::vector<int64_t> values2 = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
};
std::shared_ptr<Buffer> buffer1 = Buffer::Wrap(values1);
std::shared_ptr<Buffer> buffer2 = Buffer::Wrap(values2);
NumericTensor<Int64Type> tensor1(buffer1, shape);
NumericTensor<Int64Type> tensor2(buffer1, shape);
NumericTensor<Int64Type> tensor3(buffer2, shape);
SparseTensorImpl<SparseCSRIndex> st1(tensor1);
SparseTensorImpl<SparseCSRIndex> st2(tensor2);
SparseTensorImpl<SparseCSRIndex> st3(tensor3);
ASSERT_TRUE(st1.Equals(st2));
ASSERT_TRUE(!st1.Equals(st3));
}
} // namespace arrow
@@ -82,7 +82,6 @@ def test_sparse_tensor_csr_base_object():
assert np.array_equal(indices, result_indices)
@pytest.mark.skip
@pytest.mark.parametrize('sparse_tensor_type', [
pa.SparseTensorCSR,
pa.SparseTensorCOO,