-
-
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
Unexpected type promotion in reduce and mapreduce #21523
Comments
Duplicate of #20560 |
Hmm, I guess it is not quite a duplicate of that issue, but it is related. The resolution (#20607) should try to fix both problems. |
Issue #20560 is mainly about To me, But It would actually be a nice feature if |
Well stated. I too have never been a fan of |
+100 @perrutquist |
Another benefit of making the distinction |
The
reduce
function should, according to its docstring, "reduce the given collection with the given binary operator." I believe this is also what most programmers would expect areduce
function to do.However, this is not always what it does. Some input types, e.g.
Int32
are converted before the operator is applied. This can lead to unexpected results.The exact same problem occurs with
mapreduce(identity, my_op, ones(Int32,42))
.I realize that using an accumulator that is wider than the input could be beneficial in some special circumstances, such as if the
sum
function didn't exist and one wanted to create it usingreduce(+, ...)
without risking integer overflow. But in those cases one could supply av0
argument of the desired return type (or there could be an optionalaccumulator_type
argument).The text was updated successfully, but these errors were encountered: