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

Function NdarraysToSparseCSXMatrix

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

Source from the content-addressed store, hash-verified

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