-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
maximum([fill(NaN, 255); missing]) !== maximum([fill(NaN, 256); missing]) (Should we fix reduce(max, ...) etc.?) #36287
Comments
Good catch. I don't think this qualifies as a minor change though, it's just a bug that should be fixed. I can't comment on your more general proposal. It sounds appealing but I'm not able to judge. :-) |
@nalimilan What do you think about julia> findmax([NaN, missing])
(NaN, 1) being incompatible with |
Well I'd say it qualifies as a bug fix, just like changing |
OK. Lines 2172 to 2177 in 13b07fc
|
Woops. I wasn't aware of that. So yeah that would be a minor change. |
I should have mentioned it :) |
This specific issue is fixed in 1.9:
|
I wonder what fixed it though, as I couldn't find a relevant PR and the code doesn't seem to have been touched since the issue was filed. Examples at #45932 also seem to work now. EDIT: OK, it was fixed by #43604, which removed the short-circuiting in the presence of |
Currently, we have
As you can see,
maximum
is incompatible with the definition ofmax
depending on the size of the array. Furthermore, the result changes when processed with the identity iterator transformation.I think
maximum(xs)
should be defined asreduce(max, xs)
semantically. Currently, it is defined as such at the "syntax" level:julia/base/reducedim.jl
Lines 716 to 725 in 13b07fc
However,
mapreduce
implementation formax
/min
is not compatible with the mathematical definition ofmapreduce
.There were related discussions on findmax/min and argmax/min (#27613, #35316) and I've been suggesting to define the total orderings compatible with
max
/min
and use it to define all the similar functions, at least at the API definition level. I think this is the right direction as otherwise parallelizing these reducers is hard; i.e., we need to express them as folds with an associative operator which requires transitivity in the corresponding comparison. Furthermore, rigorously defining these reducers would let us confidently leverage the commutativity ofmax
/min
and define efficientmaximum(::Diagonal)
etc. #30236.So, I suggest to:
mapreduce(min, ...)
andmapreduce(max, ...)
.min
(maybe in Add 2-arg versions of findmax/min, argmax/min #35316) and use it inargmin
andfindmin
. (Note:isless
is alreadymax
-compatible)cc @nalimilan @StefanKarpinski @mbauman @JeffBezanson
The text was updated successfully, but these errors were encountered: