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

Function NdarraysToSparseCOOTensor

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

Source from the content-addressed store, hash-verified

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