| 275 | } |
| 276 | |
| 277 | Status PyArray_NewFromPool(int nd, npy_intp* dims, PyArray_Descr* descr, MemoryPool* pool, |
| 278 | PyObject** out) { |
| 279 | // ARROW-6570: Allocate memory from MemoryPool for a couple reasons |
| 280 | // |
| 281 | // * Track allocations |
| 282 | // * Get better performance through custom allocators |
| 283 | int64_t total_size = PyDataType_ELSIZE(descr); |
| 284 | for (int i = 0; i < nd; ++i) { |
| 285 | total_size *= dims[i]; |
| 286 | } |
| 287 | |
| 288 | ARROW_ASSIGN_OR_RAISE(auto buffer, AllocateBuffer(total_size, pool)); |
| 289 | *out = PyArray_NewFromDescr(&PyArray_Type, descr, nd, dims, |
| 290 | /*strides=*/nullptr, |
| 291 | /*data=*/buffer->mutable_data(), |
| 292 | /*flags=*/NPY_ARRAY_CARRAY | NPY_ARRAY_WRITEABLE, |
| 293 | /*obj=*/nullptr); |
| 294 | if (*out == nullptr) { |
| 295 | RETURN_IF_PYERROR(); |
| 296 | // Trust that error set if NULL returned |
| 297 | } |
| 298 | return SetBufferBase(reinterpret_cast<PyArrayObject*>(*out), std::move(buffer)); |
| 299 | } |
| 300 | |
| 301 | template <typename T = void> |
| 302 | inline const T* GetPrimitiveValues(const Array& arr) { |
no test coverage detected