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

Function PyUFunc_GetDefaultIdentity

numpy/core/src/umath/ufunc_object.c:2123–2157  ·  view source on GitHub ↗

* Returns a new reference to the ufunc identity. Note that this identity * is only a default identity value stored on the ufunc, since the invidiual * ufunc loop (ArrayMethod) is queried for the actual identity. * * TODO: store a reference in the ufunc object itself, rather than * constructing one each time */

Source from the content-addressed store, hash-verified

2121 * constructing one each time
2122 */
2123NPY_NO_EXPORT PyObject *
2124PyUFunc_GetDefaultIdentity(PyUFuncObject *ufunc, npy_bool *reorderable)
2125{
2126 switch(ufunc->identity) {
2127 case PyUFunc_One:
2128 *reorderable = 1;
2129 return PyLong_FromLong(1);
2130
2131 case PyUFunc_Zero:
2132 *reorderable = 1;
2133 return PyLong_FromLong(0);
2134
2135 case PyUFunc_MinusOne:
2136 *reorderable = 1;
2137 return PyLong_FromLong(-1);
2138
2139 case PyUFunc_ReorderableNone:
2140 *reorderable = 1;
2141 Py_RETURN_NONE;
2142
2143 case PyUFunc_None:
2144 *reorderable = 0;
2145 Py_RETURN_NONE;
2146
2147 case PyUFunc_IdentityValue:
2148 *reorderable = 1;
2149 Py_INCREF(ufunc->identity_value);
2150 return ufunc->identity_value;
2151
2152 default:
2153 PyErr_Format(PyExc_ValueError,
2154 "ufunc %s has an invalid identity", ufunc_get_name_cstr(ufunc));
2155 return NULL;
2156 }
2157}
2158
2159/*
2160 * Copy over parts of the ufunc structure that may need to be

Callers 3

ufunc_get_identityFunction · 0.85
get_initial_from_ufuncFunction · 0.85

Calls 1

ufunc_get_name_cstrFunction · 0.85

Tested by

no test coverage detected