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

Function array_scalar_forward

numpy/core/src/multiarray/number.c:867–900  ·  view source on GitHub ↗

* Convert the array to a scalar if allowed, and apply the builtin function * to it. The where argument is passed onto Py_EnterRecursiveCall when the * array contains python objects. */

Source from the content-addressed store, hash-verified

865 * array contains python objects.
866 */
867NPY_NO_EXPORT PyObject *
868array_scalar_forward(PyArrayObject *v,
869 PyObject *(*builtin_func)(PyObject *),
870 const char *where)
871{
872 if (check_is_convertible_to_scalar(v) < 0) {
873 return NULL;
874 }
875
876 PyObject *scalar;
877 scalar = PyArray_GETITEM(v, PyArray_DATA(v));
878 if (scalar == NULL) {
879 return NULL;
880 }
881
882 /* Need to guard against recursion if our array holds references */
883 if (PyDataType_REFCHK(PyArray_DESCR(v))) {
884 PyObject *res;
885 if (Py_EnterRecursiveCall(where) != 0) {
886 Py_DECREF(scalar);
887 return NULL;
888 }
889 res = builtin_func(scalar);
890 Py_DECREF(scalar);
891 Py_LeaveRecursiveCall();
892 return res;
893 }
894 else {
895 PyObject *res;
896 res = builtin_func(scalar);
897 Py_DECREF(scalar);
898 return res;
899 }
900}
901
902
903NPY_NO_EXPORT PyObject *

Callers 2

array_floatFunction · 0.85
array_intFunction · 0.85

Calls 4

PyArray_GETITEMFunction · 0.85
PyArray_DATAFunction · 0.85
PyArray_DESCRFunction · 0.85

Tested by

no test coverage detected