Skip to content
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

mapreduce(abs, max, Int[]) returns 0 #28028

Closed
nalimilan opened this issue Jul 10, 2018 · 4 comments
Closed

mapreduce(abs, max, Int[]) returns 0 #28028

nalimilan opened this issue Jul 10, 2018 · 4 comments

Comments

@nalimilan
Copy link
Member

julia> mapreduce(abs, max, Int[])
0

julia> mapreduce(abs2, max, Int[])
0

julia> mapreduce(identity, max, Int[])
ERROR: ArgumentError: reducing over an empty collection is not allowed

I see the mathematical justification for these two special cases, but they seem too clever for me. They also raise several questions:

  • why not add specializations for other functions which only return positive values (e.g exp)?
  • why not return Inf/-Inf or typemax(T)/typemin(T) for all functions?

See also this discussion in Numpy: numpy/numpy#5032

@nalimilan
Copy link
Member Author

See also #27845. Cc: @andreasnoack

@andreasnoack
Copy link
Member

To handle the empty case in general, we'd probably have to be able to reason about the range of the function which isn't and probably won't ever be possible. However, the current special casing behavior isn't wrong. Maybe just not that elegant. Returning Inf/-Inf or typemax(T)/typemin(T) instead of throwing would be wrong though. It also wouldn't avoid the exception in general since e.g. typemax(BigInt) isn't defined.

@simonbyrne
Copy link
Contributor

This is also discussed in #28535.

@vtjnash
Copy link
Member

vtjnash commented Nov 23, 2021

Triage approved and will merge this in #29919

@vtjnash vtjnash closed this as completed Nov 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants