Skip to content

Allow empty reductions for maximum(Unsigned) and compose #44702

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

eschnett
Copy link
Contributor

No description provided.

@rfourquet
Copy link
Member

A few words explaining the rationale would be useful. I understand the reasoning for compose, but having maximum(UInt[]) === UInt(0) would need some discussion. E.g. why would it work only for unsigned, e.g. why not also maximum(Int[]) == typemin(Int) and same for floats?

@eschnett
Copy link
Contributor Author

I thought about Int etc., and I thought this would require more discussion. For example, typemin(BigInt) doesn't exist. typemin(Int) is probably rarely the value that people want – one often stores non-negative values as Int, and then the neutral element is 0. If there is no clear-cut rule, then the safe way out is to do nothing and ask people to use the init argument instead.

Using -Inf for Float64 etc. makes more sense.

If it was easily possible to deduce automatically whether typemin exists for a particular type, then we could always use that as default. I think this is possible with a @generated function, but I'm not sure that is worth the trouble without discussion.

Unsigned seems a safe choice since the neutral element for maximum there is unambiguous.

@eschnett
Copy link
Contributor Author

The current error is in the documentation for another package (SparseArrays). How should I address this problem? Is there a way to link two pull requests?

@nlw0
Copy link
Contributor

nlw0 commented Apr 5, 2022

Seems related to #44819

@vtjnash vtjnash added the merge me PR is reviewed. Merge when all tests are passing label Oct 30, 2023
@giordano
Copy link
Contributor

giordano commented Oct 31, 2023

This is changing an error tested in SparseArrays (https://buildkite.com/julialang/julia-master/builds/29424#018b81a2-76cf-4a83-9c0f-bba97e31c621/768-1631) which is now in a different repository:

Error in testset SparseArrays/sparsematrix_ops:
Test Failed at /cache/build/default-amdci5-1/julialang/julia-master/julia-7469597a4f/share/julia/stdlib/v1.11/SparseArrays/test/sparsematrix_ops.jl:246
  Expression: maximum(sparse(Int[]))
    Expected: "reducing over an empty"
     Message: "ArgumentError: reducing with maximum over an empty collection of element type Int64 is not allowed.\nYou may be able to prevent this error by supplying an `init` value to the reducer."

Edit: JuliaSparse/SparseArrays.jl#466 was just opened.

@vtjnash vtjnash removed the merge me PR is reviewed. Merge when all tests are passing label Oct 31, 2023
@adienes
Copy link
Member

adienes commented Sep 11, 2024

updated by #55628

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

Successfully merging this pull request may close these issues.

6 participants