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