MCPcopy Create free account
hub / github.com/numpy/numpy / PyArray_AssignFromCache

Function PyArray_AssignFromCache

numpy/core/src/multiarray/ctors.c:552–584  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

550 * @return 0 on success -1 on failure.
551 */
552NPY_NO_EXPORT int
553PyArray_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
587static void

Callers 2

PyArray_FromAny_intFunction · 0.85
PyArray_CopyObjectFunction · 0.85

Calls 3

PyArray_NDIMFunction · 0.85
npy_free_coercion_cacheFunction · 0.85

Tested by

no test coverage detected