| 327 | } |
| 328 | |
| 329 | Status SparseCSXMatrixToNdarray(const std::shared_ptr<SparseTensor>& sparse_tensor, |
| 330 | PyObject* base, PyObject** out_data, |
| 331 | PyObject** out_indptr, PyObject** out_indices) { |
| 332 | // Wrap indices |
| 333 | OwnedRef result_indptr; |
| 334 | OwnedRef result_indices; |
| 335 | |
| 336 | switch (sparse_tensor->format_id()) { |
| 337 | case SparseTensorFormat::CSR: { |
| 338 | const auto& sparse_index = arrow::internal::checked_cast<const SparseCSRIndex&>( |
| 339 | *sparse_tensor->sparse_index()); |
| 340 | RETURN_NOT_OK(TensorToNdarray(sparse_index.indptr(), base, result_indptr.ref())); |
| 341 | RETURN_NOT_OK(TensorToNdarray(sparse_index.indices(), base, result_indices.ref())); |
| 342 | break; |
| 343 | } |
| 344 | case SparseTensorFormat::CSC: { |
| 345 | const auto& sparse_index = arrow::internal::checked_cast<const SparseCSCIndex&>( |
| 346 | *sparse_tensor->sparse_index()); |
| 347 | RETURN_NOT_OK(TensorToNdarray(sparse_index.indptr(), base, result_indptr.ref())); |
| 348 | RETURN_NOT_OK(TensorToNdarray(sparse_index.indices(), base, result_indices.ref())); |
| 349 | break; |
| 350 | } |
| 351 | default: |
| 352 | return Status::NotImplemented("Invalid SparseTensor type."); |
| 353 | } |
| 354 | |
| 355 | // Wrap tensor data |
| 356 | OwnedRef result_data; |
| 357 | RETURN_NOT_OK(SparseTensorDataToNdarray( |
| 358 | *sparse_tensor, {static_cast<npy_intp>(sparse_tensor->non_zero_length()), 1}, base, |
| 359 | result_data.ref())); |
| 360 | |
| 361 | *out_data = result_data.detach(); |
| 362 | *out_indptr = result_indptr.detach(); |
| 363 | *out_indices = result_indices.detach(); |
| 364 | return Status::OK(); |
| 365 | } |
| 366 | |
| 367 | Status SparseCSRMatrixToNdarray(const std::shared_ptr<SparseCSRMatrix>& sparse_tensor, |
| 368 | PyObject* base, PyObject** out_data, |
no test coverage detected