| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
|
|
||
| rcount = _count_reduce_items(arr, axis, keepdims=keepdims, where=where) | ||
| if rcount == 0 if where is True else umr_any(rcount == 0): | ||
| if (where is True and rcount == 0) or (where is not True and _any(rcount == 0)): |
There was a problem hiding this comment.
So, after puzzling longer... The error I made is the missing axis=None here. It seems that unlike our top-level aliases, ufunc.reduce uses axis=0 by default. And I frankly would not have known that without stumbling over it even otherwise...
It was silly to delete it, but just as bad that none of these have tests that fail here. Could you use the axis=None solution (could pass by position if you like), and add a simple test?
Sorry, something went wrong.
There was a problem hiding this comment.
@seberg Sure! I've just pushed changes reverting to umr_any and adding test case
Sorry, something went wrong.
|
|
||
| rcount = _count_reduce_items(arr, axis, keepdims=keepdims, where=where) | ||
| if rcount == 0 if where is True else umr_any(rcount == 0): | ||
| if (where is True and rcount == 0) or \ |
There was a problem hiding this comment.
I don't get this logic - surely _count_reduce_items can return an nd array even if where is True, and this will still break?
Sorry, something went wrong.
There was a problem hiding this comment.
I think it's impossible for _count_reduce_items to return ndarray with where=True. In such case it returns a scalar items = nt.intp(1) with accumulated items items *= .... Have you got an example where it returns an array when where=True?
Sorry, something went wrong.
There was a problem hiding this comment.
Ah you're right, it doesn't do what I think it does.
Sorry, something went wrong.
There was a problem hiding this comment.
Thanks for adding a test. Is it just me? I understand that the ternary operator was a bit confusing trying to understand whats wrong, but I can read it much easier than the duplicated where is True check, personally?
Sorry, something went wrong.
There was a problem hiding this comment.
Yeah, it was confusing for me 😅. Should I revert it to original if ... if .. else:?
Sorry, something went wrong.
There was a problem hiding this comment.
Maybe make a temporary variable with a nice name if you like to avoid the two if on a single line?
Sorry, something went wrong.
There was a problem hiding this comment.
On the second thought I revered it to original notation as it's all clear to me now, sorry for this confusion. All pushed.
Sorry, something went wrong.
|
I think it's ready but I see that one of the CI stages failed that previously was passing (previously whole CI was green). Also I see that it doesn't regard code itself. Should I do something about it? |
Sorry, something went wrong.
|
Thanks! I did a force push just to retrigger CI after PR rename - it's all green now. |
Sorry, something went wrong.
|
Sorry, looks good to me, and happy to merge. If you are still up for it, a test for both std and var would be nice, if not, also fine. |
Sorry, something went wrong.
Sure! Give me 20 minutes. Can I just copy-paste that part with correct _res to std and var? |
Sorry, something went wrong.
|
Great! |
Sorry, something went wrong.
…mpygh-18560) * Fixed keyword bug * Added test case * Reverted to original notation * Added tests for var and std Closes numpygh-18552
| Back | FazBrowse Home | New Git URL |
Addresses #18552
Hi @seberg!
I've managed to fix where keyword issue by refactoring those if statements.
So the rcount is a scalar when where is not provided as we reduce equal number of elements for given axis (or axes). So the first and statement prevents from illegal comparison of array to 0 value that caused original error. If the where clause is provided and rcount is an array (as we might want to reduce different number of elements along axis due to masking) then we check second and statement if any of those reduce groups are zero. I also maintained this micro-optimization to avoid calling _any(rcount == 0) when where is True and not zero.
Is this correct?
Also I had to change umr_any to _any as I think there is another bug there (or umr_any shouldn't be used there). np.any without axis parameter evaluates to scalar value (that can be used in if statement). But umr_any does not behave that way - it only reduces one dimension. Here's code for reproducing:
Here's a colab reproduction: https://colab.research.google.com/drive/1UJi6E50zzaLu2nZQWMEFHPLZnq2v6pzT?usp=sharing
Thank you for any help!