-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
BUG: don't silence warnings in ufunc.reduce #9020
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
8273a08
to
9794fd1
Compare
Tests fail right now because we're now being warned about more things. Most of these are correct (ie, testing nan behavior), and need test updates. I don't think these should warn at all when invoked with
Also, one test fails due to an overflow that was silenced! Which raises a good point - overflow in |
c00d928
to
06bbb23
Compare
Ok, all fixed I think. Probably easiest to review this commit-by-commit, since the first refactor is noisy |
maximum/minimum should warn, nan's may lead to unexpected results. We also have the nanmax/nanmin functions for these. |
What's the history behind having both |
06bbb23
to
9ef93b5
Compare
@juliantaylor: Ok, warnings are now only squashed in fmin and fmax |
This comment has been minimized.
This comment has been minimized.
1656520
to
33c269c
Compare
This comment has been minimized.
This comment has been minimized.
Needs rebase. |
|
@charris: Rebased |
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.
Mostly nitpicks, but also warnings in the compilation:
numpy/core/src/umath/ufunc_object.c:3619:15: warning: unused variable 'out_obj' [-Wunused-variable]
numpy/core/src/umath/reduction.c:562:5: warning: implicit declaration of function 'PyUFunc_clearfperr' [-Wimplicit-function-declaration]
I think the first is likely a result of the rebase; the definition can be removed from l.3619, as it is moved to 3655.
The second I'm not sure about; a missing include perhaps?
} | ||
|
||
return 0; | ||
} |
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.
Missing end of line.
ufunc_update_use_defaults(void); | ||
#endif | ||
|
||
#endif |
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.
Missing end of line.
numpy/core/src/umath/reduction.c
Outdated
@@ -436,6 +437,7 @@ PyArray_InitializeReduceResult( | |||
* loop : The loop which does the reduction. | |||
* data : Data which is passed to assign_identity and the inner loop. | |||
* buffersize : Buffer size for the iterator. For the default, pass in 0. | |||
* errormask : forwarded from _get_bufsize_errmask |
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.
Since it comes after funcname
in the signature, move it below it here as well.
@@ -149,6 +149,7 @@ PyUFunc_ReduceWrapper(PyArrayObject *operand, PyArrayObject *out, | |||
int subok, | |||
PyArray_AssignReduceIdentityFunc *assign_identity, | |||
PyArray_ReduceLoopFunc *loop, | |||
void *data, npy_intp buffersize, const char *funcname); | |||
void *data, npy_intp buffersize, const char *funcname, | |||
int errormask); |
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.
Add errormask
to the description above as well.
Don't understand how this patch could have introduced the warning about |
This makes it visible inside other files, like reduction.c Apart from the includes, everything here is just a direct move - there are no code changes
Previously, these would do so when encountering nans
The two most visible consequences are warnings for: * np.min and np.max when inputs contain nan * np.sum when the summation (of floats) overflows Implementation taken from the code for ufunc.__call__ Fixes numpy#8954
Nitpicks addressed, but still not sure about that missing function prototype. Works fine on MSVC though... |
This now looks all OK. The one remaining question is whether this is worth backporting. Including the MAINT commits, it is a bit of a large code shuffle, but it does fix a bug. @charris? |
@mhvk That's a lot of code. If the bug is long standing I would leave it for 1.14. I'm OK with backporting fixes to I'm going to release the 1.13.0 final at the beginning of next week. |
Not really - almost all of it (ie, the first MAINT commit) is just moving code from one file to another. I agree though, this isn't terribly deserving of a backport |
|
||
#include "ufunc_object.h" /* for npy_um_str_pyvals_name */ | ||
|
||
#if USE_USE_DEFAULTS==1 |
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.
Spaces around operators.
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.
Again, this is verbatim from the other file.
int res; | ||
|
||
PyUFunc_NUM_NODEFAULTS += 1; | ||
res = PyUFunc_GetPyValues("test", &bufsize, &errmask, &errobj); |
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.
"test"?
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.
Beats me - again, just a maintenance change, moving this from the other file
return 0; | ||
} | ||
|
||
NPY_ALLOW_C_API; |
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.
Does this buy anything? A small speedup in error handling, which should be rare, doesn't seem worth it.
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.
NVM
Quoting the first commit:
I'd rather not open the can of poorly-documented worms that is how |
@charris: Any other remarks here? |
Nope, might as well put it in. Thanks Eric. |
Please do not backport this - no need, and it will show warnings in the scipy test suite (and other packages probably) for released versions of scipy for which the test suite should be clean. |
Needed a file of helper functions so that this was actually visible in
reduction.c
. This move is in the first commit.Fix itself is trivial once things are visible.
Fixes #8954