Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged
merged 4 commits into from
Jul 12, 2017

Conversation

eric-wieser
Copy link
Member

@eric-wieser eric-wieser commented Apr 28, 2017

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

@eric-wieser eric-wieser changed the title [WIP] MAINT: Move functions handling ufunc extobj [help needed] MAINT: Move functions handling ufunc extobj Apr 28, 2017
@eric-wieser eric-wieser changed the title [help needed] MAINT: Move functions handling ufunc extobj BUG: Catch warnings in ufunc.reduce Apr 29, 2017
@eric-wieser
Copy link
Member Author

eric-wieser commented Apr 29, 2017

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 (1, np.nan) or .reduce([1, np.nan]), since they are designed to explicitly handle nans:

  • np.minimum
  • np.maximum
  • np.fmin
  • np.fmax

However, I don't know how to disable the warnings there.

Also, one test fails due to an overflow that was silenced! Which raises a good point - overflow in np.sum is something we really should have been catching

@eric-wieser eric-wieser force-pushed the reduce-warn branch 3 times, most recently from c00d928 to 06bbb23 Compare April 29, 2017 01:51
@eric-wieser
Copy link
Member Author

Ok, all fixed I think. Probably easiest to review this commit-by-commit, since the first refactor is noisy

@juliantaylor
Copy link
Contributor

maximum/minimum should warn, nan's may lead to unexpected results. We also have the nanmax/nanmin functions for these.

@eric-wieser
Copy link
Member Author

What's the history behind having both fmax and nanmax?

@eric-wieser eric-wieser changed the title BUG: Catch warnings in ufunc.reduce BUG: don't silence warnings in ufunc.reduce Apr 29, 2017
@eric-wieser
Copy link
Member Author

@juliantaylor: Ok, warnings are now only squashed in fmin and fmax

@homu

This comment has been minimized.

@eric-wieser eric-wieser force-pushed the reduce-warn branch 2 times, most recently from 1656520 to 33c269c Compare May 1, 2017 10:49
@homu

This comment has been minimized.

@charris
Copy link
Member

charris commented May 12, 2017

Needs rebase.

@charris
Copy link
Member

charris commented May 23, 2017

What's the history behind having both fmax and nanmax?

fmax is a binary ufunc implementing the standard C fmax function. The nanmax function uses it via the reduce method when it can, but see the note in the implementation. It might can be changed now that __array_ufunc__ is in.

Upon successful completion, these functions shall return the maximum numeric value of their arguments.

If just one argument is a NaN, the other argument shall be returned.

@eric-wieser
Copy link
Member Author

@charris: Rebased

Copy link
Contributor

@mhvk mhvk left a 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;
}
Copy link
Contributor

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing end of line.

@@ -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
Copy link
Contributor

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);
Copy link
Contributor

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.

@eric-wieser
Copy link
Member Author

Don't understand how this patch could have introduced the warning about out_obj, since the diff doesn't even contain that word, but all your nitpicks are fair

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
@eric-wieser
Copy link
Member Author

Nitpicks addressed, but still not sure about that missing function prototype. Works fine on MSVC though...

@mhvk mhvk added this to the 1.14.0 release milestone Jun 2, 2017
@mhvk
Copy link
Contributor

mhvk commented Jun 2, 2017

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?

@charris
Copy link
Member

charris commented Jun 2, 2017

@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 __array_ufunc__, but this doesn't look to qualify for that.

I'm going to release the 1.13.0 final at the beginning of next week.

@eric-wieser
Copy link
Member Author

eric-wieser commented Jun 3, 2017

That's a lot of code.

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spaces around operators.

Copy link
Member Author

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"test"?

Copy link
Member Author

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;
Copy link
Member

@charris charris Jun 24, 2017

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NVM

@eric-wieser
Copy link
Member Author

Quoting the first commit:

Apart from the includes, everything here is just a direct move - there are no code changes

I'd rather not open the can of poorly-documented worms that is how extobj actually works

@eric-wieser
Copy link
Member Author

@charris: Any other remarks here?

@charris charris merged commit 7e1a322 into numpy:master Jul 12, 2017
@charris
Copy link
Member

charris commented Jul 12, 2017

Nope, might as well put it in. Thanks Eric.

@rgommers
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants