-
-
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
stop being clever with reduction result types #20560
Comments
So should I like the former, because it generalizes to |
I think the zero element should dictate the result type if given, not influence it. I guess I feel like the former behavior is better but I don't think there should be any difference for reasonable types, so it probably doesn't matter much. |
The issue with returning just the result of |
We don't really coddle people when it comes to overflow anywhere else in the language, although this is a bit different since having at native size accumulator is pretty efficient. It would be better not to make the return type user-visible. I still worry that we won't be guaranteed to catch all overflows – we'll just catch some of them. |
I do generally agree that less magic is better, but in the case of really small types I worry that making the default |
Xref #20561 |
I'm fine with it being something "useful" but the current guessing game of result type is not ok. If it was |
+1 for defaulting to |
I like this as a default, but it would be great if there was a way for users to override this behavior. |
Otherwise things like adding an array of elements close to zero to each element of the array (or anything similar) would allocate a ton. |
The override would be by providing a "neutral" element (zero) of the desired type. So if you wanted the useless |
I don't understand this. What do you mean? |
I'm also fine with defaulting to |
Ok, seems like we have a decision here and this just needs a PR. |
I've run into very same problem with JuliaMath/FixedPointNumbers.jl#41 where we discussed widening of Normed{T,f} to Fixed{Int64, f} for all math operations to protect ourselves from over/underflow errors. From my point of view, there is no use case for overflow math in reduction operations and I fully support widening of UInt8 directly to UInt64 or even better to Int64. |
There are other ways to do this in Julia, but what about reducing to find the max along a particular axis? |
Not all reductions have to behave identically. For |
I think this is reasonable as long as there's a way to dictate the return type. We have too many cases in my package where memory is at a premium, and we're introducing abstractions specifically to allow larger data structures with fewer allocations. |
@TotalVerb, would you be willing to tackle this issue and #21523? |
Certainly. So the consensus is for the mathy operations that make sense to widen (sum, prod) to widen to Int/UInt always, and for reduce to never widen, right. |
Awesome, thanks. Yes I think that's the consensus. |
Let's play "guess the result type":
This isn't entirely inconsistent, but it's not super simple either. It's not entirely obvious why 32 bits is some kind of special threshold on a 64-bit machine. I propose that we simply return the type that
+
would have produced instead and if people want a different result type for their reduction, we should allow them to choose it by specifying a zero element of that type. This applies toprod
and other built-in reductions as well.The text was updated successfully, but these errors were encountered: