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

Function NdarraysToSparseCOOTensor

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

Source from the content-addressed store, hash-verified

416}
417
418Status NdarraysToSparseCOOTensor(MemoryPool* pool, PyObject* data_ao, PyObject* coords_ao,
419 const std::vector<int64_t>& shape,
420 const std::vector<std::string>& dim_names,
421 std::shared_ptr<SparseCOOTensor>* out) {
422 if (!PyArray_Check(data_ao) || !PyArray_Check(coords_ao)) {
423 return Status::TypeError("Did not pass ndarray object");
424 }
425
426 PyArrayObject* ndarray_data = reinterpret_cast<PyArrayObject*>(data_ao);
427 std::shared_ptr<Buffer> data = std::make_shared<NumPyBuffer>(data_ao);
428 ARROW_ASSIGN_OR_RAISE(
429 auto type_data,
430 GetTensorType(reinterpret_cast<PyObject*>(PyArray_DESCR(ndarray_data))));
431
432 std::shared_ptr<Tensor> coords;
433 RETURN_NOT_OK(NdarrayToTensor(pool, coords_ao, {}, &coords));
434 ARROW_CHECK_EQ(coords->type_id(), Type::INT64); // Should be ensured by caller
435
436 ARROW_ASSIGN_OR_RAISE(std::shared_ptr<SparseCOOIndex> sparse_index,
437 SparseCOOIndex::Make(coords));
438 *out = std::make_shared<SparseTensorImpl<SparseCOOIndex>>(sparse_index, type_data, data,
439 shape, dim_names);
440 return Status::OK();
441}
442
443template <class IndexType>
444Status NdarraysToSparseCSXMatrix(MemoryPool* pool, PyObject* data_ao, PyObject* indptr_ao,

Callers

nothing calls this directly

Calls 6

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

Tested by

no test coverage detected