Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ARROW-4226: [C++] Add sparse CSF tensor support #5716

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
12 changes: 12 additions & 0 deletions cpp/src/arrow/compare.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1196,6 +1196,13 @@ inline bool SparseTensorEqualsImplDispatch(const SparseTensorImpl<SparseIndexTyp
right_csc);
}

case SparseTensorFormat::CSF: {
const auto& right_csf =
checked_cast<const SparseTensorImpl<SparseCSFIndex>&>(right);
return SparseTensorEqualsImpl<SparseIndexType, SparseCSFIndex>::Compare(left,
right_csf);
}

default:
return false;
}
Expand Down Expand Up @@ -1232,6 +1239,11 @@ bool SparseTensorEquals(const SparseTensor& left, const SparseTensor& right) {
return SparseTensorEqualsImplDispatch(left_csc, right);
}

case SparseTensorFormat::CSF: {
const auto& left_csf = checked_cast<const SparseTensorImpl<SparseCSFIndex>&>(left);
return SparseTensorEqualsImplDispatch(left_csf, right);
}

default:
return false;
}
Expand Down
5 changes: 5 additions & 0 deletions cpp/src/arrow/python/serialize.cc
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,7 @@ Status CountSparseTensors(
OwnedRef num_sparse_tensors(PyDict_New());
size_t num_coo = 0;
size_t num_csr = 0;
size_t num_csf = 0;

for (const auto& sparse_tensor : sparse_tensors) {
switch (sparse_tensor->format_id()) {
Expand All @@ -663,6 +664,9 @@ Status CountSparseTensors(
case SparseTensorFormat::CSR:
++num_csr;
break;
case SparseTensorFormat::CSF:
++num_csf;
break;
case SparseTensorFormat::CSC:
// TODO(mrkn): support csc
break;
Expand All @@ -671,6 +675,7 @@ Status CountSparseTensors(

PyDict_SetItemString(num_sparse_tensors.obj(), "coo", PyLong_FromSize_t(num_coo));
PyDict_SetItemString(num_sparse_tensors.obj(), "csr", PyLong_FromSize_t(num_csr));
PyDict_SetItemString(num_sparse_tensors.obj(), "csf", PyLong_FromSize_t(num_csf));
RETURN_IF_PYERROR();

*out = num_sparse_tensors.detach();
Expand Down
Loading