-
-
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 any f for sum/minimum/maximum(f, v::AbstractSparseVector) #29884
Conversation
This assumes |
I think that's a fairly reasonable assumption though. What kinds of types are you thinking about where that would fail? BigInt and BigFloat because they allocate? |
Yeah, we make that assumption throughout the sparse library. It's not the |
@test @inferred(sum(t -> true, spzeros(Float64, 8))) === 8 | ||
@test @inferred(sum(t -> abs(t) + one(t), spzeros(Float64, 8))) === 8.0 | ||
|
||
@test_broken sum(t -> true, spzeros(Float64, 0)) === 0 # reducing over an empty collection |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know it's unrelated, but maybe throw an @test_broken sum(t -> true, zeros(Float64, 0)) === 0
right next to this line so that way when one gets fixed the author will find the other.
So we do...
|
Could this be done more generally by hooking into the |
@alyst This is an old PR. Any chance you'd be able to update it? It would be great to get this in, and then get the |
generalize sum/minimum/maximum(abs/abs2, v::AbstractSparseVector) to arbitrary f
tester_win32 failure is unrelated (permission denied), while the SparseVector tests had passed. |
@ViralBShah is this good to go? |
…aLang#29884) * sum/minimum/maximum(f, v::AbstractSparseVector) generalize sum/minimum/maximum(abs/abs2, v::AbstractSparseVector) to arbitrary f * add broken sum(f, [])==0 tests for reference
…aLang#29884) * sum/minimum/maximum(f, v::AbstractSparseVector) generalize sum/minimum/maximum(abs/abs2, v::AbstractSparseVector) to arbitrary f * add broken sum(f, [])==0 tests for reference
…aLang#29884) * sum/minimum/maximum(f, v::AbstractSparseVector) generalize sum/minimum/maximum(abs/abs2, v::AbstractSparseVector) to arbitrary f * add broken sum(f, [])==0 tests for reference
At the moment only
f=abs/abs2
have specialized implementations ofsum/minimum/maximum(f, v::AbstractSparseVector)
, the otherf
s are handled by the genericAbstractVector
methods.This PR extends sparse-specific methods to any
f
.The commit was extracted from #28535 since it should be a non-breaking backportable change.
cc @mbauman