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

Function SparseCSXMatrixToNdarray

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

Source from the content-addressed store, hash-verified

327}
328
329Status 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
367Status SparseCSRMatrixToNdarray(const std::shared_ptr<SparseCSRMatrix>& sparse_tensor,
368 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