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(...)) */
| 2527 | * so it can be used like PyArray_EnsureArray(some_function(...)) |
| 2528 | */ |
| 2529 | NPY_NO_EXPORT PyObject * |
| 2530 | PyArray_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*/ |
| 2552 | NPY_NO_EXPORT PyObject * |
no test coverage detected