-
-
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
Remove a few redundant diagonal ldiv!
methods
#38484
Conversation
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.
Two comments (summarizing what @KlausC said), and then this is ready to go.
Hm, actually, this really requires benchmarking. The strided version is optimized towards good access pattern for |
@dkarrasch I used the changes you and @KlausC suggested. Benchmarking revealed only minor performance differences: Julia 1.5.0 julia> D = Diagonal(rand(500)); M = rand(500, 500); @btime ldiv!(D, M)
580.819 μs (0 allocations: 0 bytes)
julia> D = Diagonal(rand(500)); M = UpperTriangular(rand(500, 500)); @btime ldiv!(D, M)
533.071 μs (0 allocations: 0 bytes) This PR: julia> D = Diagonal(rand(500)); M = rand(500, 500); @btime ldiv!(D, M)
536.923 μs (0 allocations: 0 bytes)
julia> D = Diagonal(rand(500)); M = UpperTriangular(rand(500, 500)); @btime ldiv!(D, M)
521.033 μs (0 allocations: 0 bytes) |
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.
The benchmark suggests that it makes sense to switch to the previous strided matrix loop order also for abstract matrices. This LGTM. The only question I have is whether we should try to preserve structure when the matrix has structure.
#Linear solver | ||
function ldiv!(D::Diagonal, B::StridedVecOrMat) | ||
(\)(D::Diagonal, A::AbstractMatrix) = | ||
ldiv!(D, (typeof(oneunit(eltype(D))/oneunit(eltype(A)))).(A)) |
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.
Should we change this to something like copy_oftype
or copyto!(similar(A, typeof(...), size(A)), A)
or so, in order to preserve the structure whenever possible?
I'm assuming the LGTM meant to dismiss this
Three
ldiv!
methods for diagonal matrices were effectively the exact same but had different type specializations. This PR replaces them with a singleldiv!
that subsumes their functionality.