-
-
Notifications
You must be signed in to change notification settings - Fork 11.4k
MAINT: Remove duplicated logic between array_wrap and array_prepare #10459
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only a question about whether you'd not rather check for a tuple here as well. Fine to do that in a follow-up PR, though.
@@ -243,27 +269,13 @@ _find_array_prepare(PyObject *args, PyObject *kwds, | |||
obj = PyDict_GetItem(kwds, npy_um_str_out); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are on purpose not yet checking whether the out
argument is a tuple, correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm on purpose just leaving it as it was - I want to push the out
argument parsing way upstream
Actually, I should try to keep the comments from the function I removed - so don't merge this yet |
326ac85
to
ee0a016
Compare
Updated with comments and slightly more efficient code. |
numpy/core/src/umath/ufunc_object.c
Outdated
static PyObject * | ||
_get_output_array_method(PyObject *obj, PyObject *method, | ||
PyObject *input_method) { | ||
if (obj == Py_None) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are now three times in which you have the incref and return of input_method
. How about inverting the logic, and move the next two lines to the very end, as the fall-back opion, i.e.,
PyObject *ometh;
if obj != Py_None` {
if (PyArrayCheckExact(obj)) {
return Py_RETURN_NONE;
}
ometh = ...
if (ometh) {
if(PyCallable_Check(ometh)) {
return ometh;
}
else {
Py_DECREF(ometh);
}
}
else {
PyErr_Clear();
}
}
Py_XINCREF(input_method);
return input_method;
This behaves exactly as before
ee0a016
to
e6956dd
Compare
Should be ready |
All OK now, merging! |
…lt to inherit the output's mask This brings `np.add(a, b, out)` in line with `np.add(a, b, out=out)`. These previously differed because numpygh-10459 causes them to call __array_wrap__ in different ways (with and without the output argument in the context tuple, respectively). Since the data in the `out` argument is never used by ufuncs, it seems consistent that the mask should not be either.
Currently, this causes the result to inherit the output's mask. This brings `np.add(a, b, out)` in line with `np.add(a, b, out=out)`. These previously differed because numpygh-10459 causes them to call __array_wrap__ in different ways (with and without the output argument in the context tuple, respectively). Since the data in the `out` argument is never used by ufuncs, it seems consistent that the mask should not be either.
…lt to inherit the output's mask This brings `np.add(a, b, out)` in line with `np.add(a, b, out=out)`. These previously differed because numpygh-10459 causes them to call __array_wrap__ in different ways (with and without the output argument in the context tuple, respectively). Since the data in the `out` argument is never used by ufuncs, it seems consistent that the mask should not be either.
This behaves exactly as before
Part of the cleanup needed to fix #10450