* Fills an item based on a coercion cache object. It consumes the cache * object while doing so. * * @param self Array to fill. * @param cache coercion_cache_object, will be consumed. The cache must not * contain a single array (must start with a sequence). The array case * should be handled by `PyArray_FromArray()` before. * @return 0 on success -1 on failure. */
| 550 | * @return 0 on success -1 on failure. |
| 551 | */ |
| 552 | NPY_NO_EXPORT int |
| 553 | PyArray_AssignFromCache(PyArrayObject *self, coercion_cache_obj *cache) { |
| 554 | int ndim = PyArray_NDIM(self); |
| 555 | /* |
| 556 | * Do not support ndim == 0 now with an array in the cache. |
| 557 | * The ndim == 0 is special because np.array(np.array(0), dtype=object) |
| 558 | * should unpack the inner array. |
| 559 | * Since the single-array case is special, it is handled previously |
| 560 | * in either case. |
| 561 | */ |
| 562 | assert(cache->sequence); |
| 563 | assert(ndim != 0); /* guaranteed if cache contains a sequence */ |
| 564 | |
| 565 | if (PyArray_AssignFromCache_Recursive(self, ndim, &cache) < 0) { |
| 566 | /* free the remaining cache. */ |
| 567 | npy_free_coercion_cache(cache); |
| 568 | return -1; |
| 569 | } |
| 570 | |
| 571 | /* |
| 572 | * Sanity check, this is the initial call, and when it returns, the |
| 573 | * cache has to be fully consumed, otherwise something is wrong. |
| 574 | * NOTE: May be nicer to put into a recursion helper. |
| 575 | */ |
| 576 | if (cache != NULL) { |
| 577 | PyErr_SetString(PyExc_RuntimeError, |
| 578 | "Inconsistent object during array creation? " |
| 579 | "Content of sequences changed (cache not consumed)."); |
| 580 | npy_free_coercion_cache(cache); |
| 581 | return -1; |
| 582 | } |
| 583 | return 0; |
| 584 | } |
| 585 | |
| 586 | |
| 587 | static void |
no test coverage detected