| 416 | } |
| 417 | |
| 418 | Status 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 | |
| 443 | template <class IndexType> |
| 444 | Status NdarraysToSparseCSXMatrix(MemoryPool* pool, PyObject* data_ao, PyObject* indptr_ao, |
nothing calls this directly
no test coverage detected