-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Fix maximum(abs/abs2, T[]) #28535
Fix maximum(abs/abs2, T[]) #28535
Conversation
e8f8404
to
e1506d1
Compare
I agree that this is inconsistent. We can't break code anymore so we can't break |
I'd rather leave
P.S. Sorry for abusing CI, I had no julia dev environment set up and I was too optimistic of my coding skills. |
6290354
to
fd51bef
Compare
It looks like it's possible to implement |
|
I can remove the support for |
fix maximum(abs/abs2, ::AbstractSparseVector)
I've excluded the support for cc @mbauman (for |
Could you split apart the changes here? It looks like there is a performance fix (2nd commit) mixed in with a breaking change. It'll be easier to review & merge if we detangle the two. |
@mbauman The 2nd commit depends on the first one. So I removed it from this PR, but, to reduce the noise, I'd rather submit the new PR if/when this one gets merged. |
That change was largely back-portable, though, no? You'd have to just preserve the weird This change needs to pass PkgEval for it to be included in 1.1. Given that support was explicitly added for this case, I find it hard to blithely call it a bug. |
I can do that, though it looks more like a new feature. Then it would have to be merged first to avoid conflicts resolution.
Interesting question. :) This behaviour dates back to #7038 when |
Sorry, late to this issue. What's wrong with The underlying rationale is that
where ( FWIW, I think we could also define
|
Agree, I don't see why we wouldn't give these kinds of definitions when there is a value that's correct. It's conventional across mathematics that an empty sum is zero, an empty product is one, an empty maximum or reals is negative infinity and an empty minimum of reals is positive infinity. It seems just as reasonable to say that an empty maximum of absolute values is zero. |
Should it generalize to |
For one, it's not consistent with |
I agree, that's why I suggested adding that as well.
the criteria, roughly put, is "return a value when well-defined, throw an error when not" (e.g. for |
We could also just consistently make |
Of course it does seem somewhat more informative to give a more precise answer... |
Returning |
That would make the behaviour of |
Yeah, I'm slightly hesitant about this as well, since it breaks my above criterion if
whereas |
Right, I didn't really mean to suggest that for types that don't have ±Inf values (that is what I wrote though). I really meant more to suggest that it would be correct if not precise for
Of course, we don't have to implement it that way since an inexact error would be a weird way for an empty minimum or maximum operation to present itself, but you get the idea. |
Only if We could also have, e.g. |
The logic for
For
I realise that is still not exactly mathematically precise, but that's the best I can think of for now. Note that this still doesn't uniquely characterise all such values, e.g. any |
If |
Can we specialize on I would argue for keeping the special cases where possible: it is useful that |
I mean that we know that |
Sure, but for those cases we can give "better" values, so we should do that. The more interesting question is whether we could do it for an arbitrary anonymous function? I guess we could do something similar to |
I don't think we can in general since we can't know that the function always produces a given type. |
So for Also, for
While I agree that
on v1.0.1 I get
|
Let me approach this from the other direction? Are there situations where it's really useful that As it stands, I'm concerned that the current approach will potentially require special-casing every |
But my criterion wouldn't apply to that example. It would however apply to:
which IMHO makes perfect sense.
Yes, it was meant to be a hypothetical if we were to change it to use |
It allows you to write
I like that! |
Sure. But isn't |
That's a good point --- I think the first thing we should do is add methods to |
See #29919. |
Seems like this has been superseded by #29919 |
At the moment
It doesn't seem right to me. I suppose
maximum()
over an empty collection should throw in all cases.The second commit improves
It seems valid to return 0 in the second case. Of course,
isequal()
is just one specific case of bool-valuedf
, OTOH it's quite a common one.