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

Function NdarraysToSparseCSXMatrix

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

Source from the content-addressed store, hash-verified

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