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

Function PyUFuncOverride_GetOutObjects

numpy/core/src/common/ufunc_override.c:87–133  ·  view source on GitHub ↗

* Get possible out argument from kwds, and returns the number of outputs * contained within it: if a tuple, the number of elements in it, 1 otherwise. * The out argument itself is returned in out_kwd_obj, and the outputs * in the out_obj array (as borrowed references). * * Returns 0 if no outputs found, -1 if kwds is not a dict (with an error set). */

Source from the content-addressed store, hash-verified

85 * Returns 0 if no outputs found, -1 if kwds is not a dict (with an error set).
86 */
87NPY_NO_EXPORT int
88PyUFuncOverride_GetOutObjects(PyObject *kwds, PyObject **out_kwd_obj, PyObject ***out_objs)
89{
90 if (kwds == NULL) {
91 Py_INCREF(Py_None);
92 *out_kwd_obj = Py_None;
93 return 0;
94 }
95 if (!PyDict_CheckExact(kwds)) {
96 PyErr_SetString(PyExc_TypeError,
97 "Internal Numpy error: call to PyUFuncOverride_GetOutObjects "
98 "with non-dict kwds");
99 *out_kwd_obj = NULL;
100 return -1;
101 }
102 /* borrowed reference */
103 *out_kwd_obj = _PyDict_GetItemStringWithError(kwds, "out");
104 if (*out_kwd_obj == NULL) {
105 if (PyErr_Occurred()) {
106 return -1;
107 }
108 Py_INCREF(Py_None);
109 *out_kwd_obj = Py_None;
110 return 0;
111 }
112 if (PyTuple_CheckExact(*out_kwd_obj)) {
113 /*
114 * The C-API recommends calling PySequence_Fast before any of the other
115 * PySequence_Fast* functions. This is required for PyPy
116 */
117 PyObject *seq;
118 seq = PySequence_Fast(*out_kwd_obj,
119 "Could not convert object to sequence");
120 if (seq == NULL) {
121 *out_kwd_obj = NULL;
122 return -1;
123 }
124 *out_objs = PySequence_Fast_ITEMS(seq);
125 *out_kwd_obj = seq;
126 return PySequence_Fast_GET_SIZE(seq);
127 }
128 else {
129 Py_INCREF(*out_kwd_obj);
130 *out_objs = out_kwd_obj;
131 return 1;
132 }
133}

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected