| 377 | } |
| 378 | |
| 379 | Status SparseCSFTensorToNdarray(const std::shared_ptr<SparseCSFTensor>& sparse_tensor, |
| 380 | PyObject* base, PyObject** out_data, |
| 381 | PyObject** out_indptr, PyObject** out_indices) { |
| 382 | const auto& sparse_index = arrow::internal::checked_cast<const SparseCSFIndex&>( |
| 383 | *sparse_tensor->sparse_index()); |
| 384 | |
| 385 | // Wrap tensor data |
| 386 | OwnedRef result_data; |
| 387 | RETURN_NOT_OK(SparseTensorDataToNdarray( |
| 388 | *sparse_tensor, {static_cast<npy_intp>(sparse_tensor->non_zero_length()), 1}, base, |
| 389 | result_data.ref())); |
| 390 | |
| 391 | // Wrap indices |
| 392 | int ndim = static_cast<int>(sparse_index.indices().size()); |
| 393 | OwnedRef indptr(PyList_New(ndim - 1)); |
| 394 | OwnedRef indices(PyList_New(ndim)); |
| 395 | RETURN_IF_PYERROR(); |
| 396 | |
| 397 | for (int i = 0; i < ndim - 1; ++i) { |
| 398 | PyObject* item; |
| 399 | RETURN_NOT_OK(TensorToNdarray(sparse_index.indptr()[i], base, &item)); |
| 400 | if (PyList_SetItem(indptr.obj(), i, item) < 0) { |
| 401 | RETURN_IF_PYERROR(); |
| 402 | } |
| 403 | } |
| 404 | for (int i = 0; i < ndim; ++i) { |
| 405 | PyObject* item; |
| 406 | RETURN_NOT_OK(TensorToNdarray(sparse_index.indices()[i], base, &item)); |
| 407 | if (PyList_SetItem(indices.obj(), i, item) < 0) { |
| 408 | RETURN_IF_PYERROR(); |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | *out_indptr = indptr.detach(); |
| 413 | *out_indices = indices.detach(); |
| 414 | *out_data = result_data.detach(); |
| 415 | return Status::OK(); |
| 416 | } |
| 417 | |
| 418 | Status NdarraysToSparseCOOTensor(MemoryPool* pool, PyObject* data_ao, PyObject* coords_ao, |
| 419 | const std::vector<int64_t>& shape, |
nothing calls this directly
no test coverage detected