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

Function NdarraysToSparseCOOTensor

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

Source from the content-addressed store, hash-verified

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