-
-
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
Allow to specify the result type of a sum #5311
Comments
I can make a PR to implement this if people agree that this is useful. |
Interesting. And how about (in addition to adding your proposed function) defaulting to |
I agree with using a more sensible choice in determining the default type. |
This seems like a very natural extension of the current functionality. I have some problem to understand a few gotchas.
|
The correct implementation of function mysum(R, x)
s = zero(R)
for v in x
s = convert(R, s + v)
end
return s
end When |
I agree that the current implementation of |
Yes it is kind of a different issue, but |
Currently, Also, |
My point was that these functions are closely related, and if one want to change the interface, all the interfaces should be considered together. I have some understanding of the implementation details, and did NOT intend to suggest that the other reduction functions should be implemented using our |
I agree that the implementation of |
On the subject of making
but it now fails because
I'm not sure if the former should actually work or not, but if the documentation says that the two should be equivalent, it should. BTW the error for the
|
Given the existence of #18423, should this be closed? |
@oscardssmith typically issues are closed only after relevant pull requests are merged. |
Or when the two issues are duplicate of each other (or when one covers the other one). These two issues seems to be closely related but are not quite the same. (A fix should probably take both into account though.) |
The original issue seems to be solved, julia> a = rand(Float32, 10^6);
julia> sum(Float64.(a)) - sum(a)
-0.020957350730895996
julia> sum(Float64.(a)) - sum(Float64,a)
0.0 Close or change title? PS: I haven't verified there is a test for this; we might want to do so before closing. |
Works now. |
Currently, the
sum
function use the element type (except for the boolean case) of the input array as result type. This is sometimes not a desirable choice:My proposal is to add a method like
sum(R, x)
whereR
is the user-specifed type. This won't break any existing codes, but provide the user additional choices.The text was updated successfully, but these errors were encountered: