-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Fix method ambiguities in SparseArrays #30120
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
Conversation
| @inline capturescalars(f, mixedargs::Tuple{SparseVecOrMat, Ref{Type{T}}, Vararg{Any}}) where {T} = | ||
| capturescalars((a1, args...)->f(a1, T, args...), (mixedargs[1], Base.tail(Base.tail(mixedargs))...)) | ||
| @inline capturescalars(f, mixedargs::Tuple{Union{Ref,AbstractArray{0}}, Ref{Type{T}}, Vararg{Any}}) where {T} = | ||
| @inline capturescalars(f, mixedargs::Tuple{Union{Ref,AbstractArray{<:Any,0}}, Ref{Type{T}}, Vararg{Any}}) where {T} = |
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.
This was irrelevant to this PR but I suppose AbstractArray{0} was a typo?
| @test ((_, x) -> x).(Int, spzeros(3)) == spzeros(3) | ||
| @test ((_, _, x) -> x).(Int, Int, spzeros(3)) == spzeros(3) | ||
| @test ((_, _, _, x) -> x).(Int, Int, Int, spzeros(3)) == spzeros(3) | ||
| @test_broken ((_, _, _, _, x) -> x).(Int, Int, Int, Int, spzeros(3)) == spzeros(3) |
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.
It looks like capturescalars has type inference issue when it has to recurse a lot (> 3). I wounder if capturescalars could be implemented more naturally (for humans and maybe for Julia as well?) if you used @generated function. Any reason why capturescalars is implemented based on recursion?
| _copyto!(parevalf, dest, passedsrcargstup...) | ||
| end | ||
|
|
||
| struct CapturedScalars{F, Args, Order} |
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.
git grep CapturedScalars shows me that there is no code using it. Maybe some remnant from experimenting with capturescalars? This was irrelevant to this PR but I thought it's OK to remove it here (as I'm touching capturescalars).
timholy
left a comment
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.
Thanks for doing this.
| parevalf, passedargstup = capturescalars(f, args) | ||
| return _copy(parevalf, passedargstup...) | ||
| end | ||
| _copy(f) = throw(MethodError(_copy, (f))) # avoid method ambiguity |
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.
(f) === f, should be (f,)
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.
Thanks for catching this. I fixed it and added a test.
* Remove unused struct CapturedScalars * Fix method ambiguities in SparseArrays * Fix HigherOrderFns._copy(f) (cherry picked from commit f10530e)
* Remove unused struct CapturedScalars * Fix method ambiguities in SparseArrays * Fix HigherOrderFns._copy(f) (cherry picked from commit f10530e)
* Remove unused struct CapturedScalars * Fix method ambiguities in SparseArrays * Fix HigherOrderFns._copy(f) (cherry picked from commit f10530e)
I added a few methods to resolve method ambiguity in SparseArrays.jl. I also included the test using
detect_ambiguitiesas I did for LinearAlgebra.jl in #28749 and #28816.