| 442 | |
| 443 | template <class IndexType> |
| 444 | Status 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 | |
| 473 | Status NdarraysToSparseCSFTensor(MemoryPool* pool, PyObject* data_ao, PyObject* indptr_ao, |
| 474 | PyObject* indices_ao, const std::vector<int64_t>& shape, |
nothing calls this directly
no test coverage detected