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

Function SparseCSFTensorToNdarray

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected