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

Function PyArray_EnsureArray

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

NUMPY_API * This is a quick wrapper around * PyArray_FromAny(op, NULL, 0, 0, NPY_ARRAY_ENSUREARRAY, NULL) * that special cases Arrays and PyArray_Scalars up front * It *steals a reference* to the object * It also guarantees that the result is PyArray_Type * Because it decrefs op if any conversion needs to take place * so it can be used like PyArray_EnsureArray(some_function(...)) */

Source from the content-addressed store, hash-verified

2527 * so it can be used like PyArray_EnsureArray(some_function(...))
2528 */
2529NPY_NO_EXPORT PyObject *
2530PyArray_EnsureArray(PyObject *op)
2531{
2532 PyObject *new;
2533
2534 if ((op == NULL) || (PyArray_CheckExact(op))) {
2535 new = op;
2536 Py_XINCREF(new);
2537 }
2538 else if (PyArray_Check(op)) {
2539 new = PyArray_View((PyArrayObject *)op, NULL, &PyArray_Type);
2540 }
2541 else if (PyArray_IsScalar(op, Generic)) {
2542 new = PyArray_FromScalar(op, NULL);
2543 }
2544 else {
2545 new = PyArray_FROM_OF(op, NPY_ARRAY_ENSUREARRAY);
2546 }
2547 Py_XDECREF(op);
2548 return new;
2549}
2550
2551/*NUMPY_API*/
2552NPY_NO_EXPORT PyObject *

Callers 3

PyArray_EnsureAnyArrayFunction · 0.85
can_elide_tempFunction · 0.85
__New_PyArray_StdFunction · 0.85

Calls 2

PyArray_ViewFunction · 0.85
PyArray_FromScalarFunction · 0.85

Tested by

no test coverage detected