* Check whether any of the input and output args have a non-default * __array_ufunc__ method. Return 1 if so, 0 if not, and -1 on error. * * This function primarily exists to help ndarray.__array_ufunc__ determine * whether it can support a ufunc (which is the case only if none of the * operands have an override). Thus, unlike in umath/override.c, the * actual overrides are not needed and o
| 1097 | * actual overrides are not needed and one can stop looking once one is found. |
| 1098 | */ |
| 1099 | static int |
| 1100 | any_array_ufunc_overrides(PyObject *args, PyObject *kwds) |
| 1101 | { |
| 1102 | int i; |
| 1103 | int nin, nout; |
| 1104 | PyObject *out_kwd_obj; |
| 1105 | PyObject *fast; |
| 1106 | PyObject **in_objs, **out_objs, *where_obj; |
| 1107 | |
| 1108 | /* check inputs */ |
| 1109 | nin = PyTuple_Size(args); |
| 1110 | if (nin < 0) { |
| 1111 | return -1; |
| 1112 | } |
| 1113 | fast = PySequence_Fast(args, "Could not convert object to sequence"); |
| 1114 | if (fast == NULL) { |
| 1115 | return -1; |
| 1116 | } |
| 1117 | in_objs = PySequence_Fast_ITEMS(fast); |
| 1118 | for (i = 0; i < nin; ++i) { |
| 1119 | if (PyUFunc_HasOverride(in_objs[i])) { |
| 1120 | Py_DECREF(fast); |
| 1121 | return 1; |
| 1122 | } |
| 1123 | } |
| 1124 | Py_DECREF(fast); |
| 1125 | if (kwds == NULL) { |
| 1126 | return 0; |
| 1127 | } |
| 1128 | /* check outputs, if any */ |
| 1129 | nout = PyUFuncOverride_GetOutObjects(kwds, &out_kwd_obj, &out_objs); |
| 1130 | if (nout < 0) { |
| 1131 | return -1; |
| 1132 | } |
| 1133 | for (i = 0; i < nout; i++) { |
| 1134 | if (PyUFunc_HasOverride(out_objs[i])) { |
| 1135 | Py_DECREF(out_kwd_obj); |
| 1136 | return 1; |
| 1137 | } |
| 1138 | } |
| 1139 | Py_DECREF(out_kwd_obj); |
| 1140 | /* check where if it exists */ |
| 1141 | where_obj = PyDict_GetItemWithError(kwds, npy_ma_str_where); |
| 1142 | if (where_obj == NULL) { |
| 1143 | if (PyErr_Occurred()) { |
| 1144 | return -1; |
| 1145 | } |
| 1146 | } else { |
| 1147 | if (PyUFunc_HasOverride(where_obj)){ |
| 1148 | return 1; |
| 1149 | } |
| 1150 | } |
| 1151 | return 0; |
| 1152 | } |
| 1153 | |
| 1154 | |
| 1155 | NPY_NO_EXPORT PyObject * |
no test coverage detected