-
-
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
Add dispatch routines for ldiv!
with transposed LU and transposed or Hermitian/Symmetric B
#55760
Add dispatch routines for ldiv!
with transposed LU and transposed or Hermitian/Symmetric B
#55760
Conversation
dc5188a
to
10445d1
Compare
Test Resultsjulia> using LinearAlgebra, BenchmarkTools
julia> id(A,T) = T(Matrix{eltype(A)}(I, size(A)...))
id (generic function with 1 method)
julia> A = randn(1000,1000);
julia> @btime inv($A);
29.407 ms (10 allocations: 8.13 MiB)
julia> @btime ldiv!(lu(A), $(id(A,Matrix)));
35.406 ms (7 allocations: 7.64 MiB)
julia> @btime rdiv!($(id(A,Matrix)), lu(A));
32.574 ms (11 allocations: 15.27 MiB)
julia> @btime rdiv!($(id(A,Symmetric)), lu(A));
32.137 ms (12 allocations: 15.27 MiB)
julia> inv(A) ≈ ldiv!(lu(A), id(A,Matrix)) ≈ rdiv!(id(A,Matrix), lu(A)) ≈ rdiv!(id(A,Symmetric), lu(A))
true
julia> A = complex.(randn(1000,1000),randn(1000,1000));
julia> @btime inv($A);
66.822 ms (10 allocations: 16.24 MiB)
julia> @btime ldiv!(lu(A), $(id(A,Matrix)));
96.932 ms (7 allocations: 15.27 MiB)
julia> @btime rdiv!($(id(A,Matrix)), lu(A));
113.056 ms (11 allocations: 30.53 MiB)
julia> @btime rdiv!($(id(A,Hermitian)), lu(A));
93.395 ms (12 allocations: 30.53 MiB)
julia> inv(A) ≈ ldiv!(lu(A), id(A,Matrix)) ≈ rdiv!(id(A,Matrix), lu(A)) ≈ rdiv!(id(A,Hermitian), lu(A))
true |
10445d1
to
47c7506
Compare
Wait, but these are not in-place, are they? The assumption is that |
Good evening, @dkarrasch. You're right. Unfortunately, these are not in-place. The original implementation used generic matrix functions, which were about If you have any suggestions for in-place expansion of |
Could maybe e.g. replace the function _transpose!(M::AbstractMatrix)
Mt = reshape(M, reverse(size(M)))
for i in axes(M, 1), j in firstindex(M, 2)+i:lastindex(M, 2)
(Mt[j,i], M[i,j]) = (transpose(M[i,j]), transpose(Mt[j,i]))
end
return Mt
end And similar for Have't thought this through completely, but maybe its an idea to work with. EDIT: The indexing is horribly wrong; this doesn't do a proper transpose. |
The "promise" of A = factorize(rand(3,3)) # for instance
B = rand(3, 5)
ldiv!(A, B)
# continue to work with B If this wasn't in-place, you would need |
I think my proposal should in principle achieve this, as the |
Thank you, @dkarrasch. I fully agree that in the final version, I feel that it may be best to use LAPACK for |
It depends. When there are different BLAS-types invovled, there are no such BLAS-methods. So we will need to fall back to generic methods. The point is that we have two orthogonal goals: performance vs memory allocation. When users don't mind the memory allocation, then they can use |
So my
If there is a way to express the |
Thank you, @dkarrasch. I agree with your response. If you feel it is not worth taking forward, perhaps we can make it clear in the I understand the surprise of OP and the poster on Discourse when |
It turns out this was a silly dispatch issue, so this PR should be superseded by #55764. |
Introduction
This PR is a possible fix for the issue #55422, where it is observed that, with LU factorisation,
rdiv!
is much slower thanldiv!
, see the issue for details and analysis.This PR adds four new dispatch routines (methods) for
ldiv!
with LU: forAdjoint
,Transpose
,Hermitian
, andSymmetric
.Test Suite
Test Results
See #55760 (comment)