Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions cpp/src/arrow/sparse_tensor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -405,11 +405,25 @@ SparseCSFIndex::SparseCSFIndex(const std::vector<std::shared_ptr<Tensor>>& indpt
std::string SparseCSFIndex::ToString() const { return std::string("SparseCSFIndex"); }

bool SparseCSFIndex::Equals(const SparseCSFIndex& other) const {
if (indices().size() != other.indices().size()) {
return false;
}
if (indptr().size() != other.indptr().size()) {
return false;
}
if (axis_order().size() != other.axis_order().size()) {
return false;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain why is this required?


for (int64_t i = 0; i < static_cast<int64_t>(indices().size()); ++i) {
if (!indices()[i]->Equals(*other.indices()[i])) return false;
if (!indices()[i]->Equals(*other.indices()[i])) {
return false;
}
}
for (int64_t i = 0; i < static_cast<int64_t>(indptr().size()); ++i) {
if (!indptr()[i]->Equals(*other.indptr()[i])) return false;
if (!indptr()[i]->Equals(*other.indptr()[i])) {
return false;
}
Comment thread
rok marked this conversation as resolved.
Outdated
}
return axis_order() == other.axis_order();
}
Comment thread
AliRana30 marked this conversation as resolved.
Expand Down
23 changes: 22 additions & 1 deletion cpp/src/arrow/sparse_tensor_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1641,10 +1641,31 @@ TYPED_TEST_P(TestSparseCSFTensorForIndexValueType, TestNonAscendingShape) {
ASSERT_TRUE(st->Equals(*sparse_tensor));
}

TYPED_TEST_P(TestSparseCSFTensorForIndexValueType, TestEqualityMismatchedDimensions) {
using IndexValueType = TypeParam;
using c_index_value_type = typename IndexValueType::c_type;

// 2D vs 3D - comparing indices with different dimensionality
// 2D CSF: ndim=2, so indptr.size()=1, indices.size()=2
std::vector<int64_t> axis_order_2D = {0, 1};
std::vector<std::vector<c_index_value_type>> indptr_2D = {{0, 1}};
std::vector<std::vector<c_index_value_type>> indices_2D = {{0}, {0}};
auto si_2D = this->MakeSparseCSFIndex(axis_order_2D, indptr_2D, indices_2D);

// 3D CSF: ndim=3, so indptr.size()=2, indices.size()=3
std::vector<int64_t> axis_order_3D = {0, 1, 2};
std::vector<std::vector<c_index_value_type>> indptr_3D = {{0, 1}, {0, 1}};
std::vector<std::vector<c_index_value_type>> indices_3D = {{0}, {0}, {0}};
auto si_3D = this->MakeSparseCSFIndex(axis_order_3D, indptr_3D, indices_3D);

ASSERT_FALSE(si_2D->Equals(*si_3D));
ASSERT_FALSE(si_3D->Equals(*si_2D));
}
Comment thread
AliRana30 marked this conversation as resolved.

REGISTER_TYPED_TEST_SUITE_P(TestSparseCSFTensorForIndexValueType, TestCreateSparseTensor,
TestTensorToSparseTensor, TestSparseTensorToTensor,
TestAlternativeAxisOrder, TestNonAscendingShape,
TestRoundTrip);
TestRoundTrip, TestEqualityMismatchedDimensions);

INSTANTIATE_TYPED_TEST_SUITE_P(TestInt8, TestSparseCSFTensorForIndexValueType, Int8Type);
INSTANTIATE_TYPED_TEST_SUITE_P(TestUInt8, TestSparseCSFTensorForIndexValueType,
Expand Down
Loading