MCPcopy Create free account
hub / github.com/apache/arrow / SparseCSXMatrixToNdarray

Function SparseCSXMatrixToNdarray

python/pyarrow/src/arrow/python/numpy_convert.cc:326–362  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 2

SparseCSRMatrixToNdarrayFunction · 0.85
SparseCSCMatrixToNdarrayFunction · 0.85

Calls 7

TensorToNdarrayFunction · 0.85
sparse_indexMethod · 0.80
indicesMethod · 0.80
NotImplementedFunction · 0.50
OKFunction · 0.50
non_zero_lengthMethod · 0.45

Tested by

no test coverage detected