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

Function NdarraysToSparseCSXMatrix

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

Source from the content-addressed store, hash-verified

443
444template <class IndexType>
445Status NdarraysToSparseCSXMatrix(MemoryPool* pool, PyObject* data_ao, PyObject* indptr_ao,
446 PyObject* indices_ao, const std::vector<int64_t>& shape,
447 const std::vector<std::string>& dim_names,
448 std::shared_ptr<SparseTensorImpl<IndexType>>* out) {
449 if (!PyArray_Check(data_ao) || !PyArray_Check(indptr_ao) ||
450 !PyArray_Check(indices_ao)) {
451 return Status::TypeError("Did not pass ndarray object");
452 }
453
454 PyArrayObject* ndarray_data = reinterpret_cast<PyArrayObject*>(data_ao);
455 std::shared_ptr<Buffer> data = std::make_shared<NumPyBuffer>(data_ao);
456 ARROW_ASSIGN_OR_RAISE(
457 auto type_data,
458 GetTensorType(reinterpret_cast<PyObject*>(PyArray_DESCR(ndarray_data))));
459
460 std::shared_ptr<Tensor> indptr, indices;
461 RETURN_NOT_OK(NdarrayToTensor(pool, indptr_ao, {}, &indptr));
462 RETURN_NOT_OK(NdarrayToTensor(pool, indices_ao, {}, &indices));
463 ARROW_CHECK_EQ(indptr->type_id(), Type::INT64); // Should be ensured by caller
464 ARROW_CHECK_EQ(indices->type_id(), Type::INT64); // Should be ensured by caller
465
466 auto sparse_index = std::make_shared<IndexType>(
467 std::static_pointer_cast<NumericTensor<Int64Type>>(indptr),
468 std::static_pointer_cast<NumericTensor<Int64Type>>(indices));
469 *out = std::make_shared<SparseTensorImpl<IndexType>>(sparse_index, type_data, data,
470 shape, dim_names);
471 return Status::OK();
472}
473
474Status NdarraysToSparseCSFTensor(MemoryPool* pool, PyObject* data_ao, PyObject* indptr_ao,
475 PyObject* indices_ao, const std::vector<int64_t>& shape,

Callers

nothing calls this directly

Calls 4

NdarrayToTensorFunction · 0.85
TypeErrorFunction · 0.50
OKFunction · 0.50
type_idMethod · 0.45

Tested by

no test coverage detected