-
-
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
Define factorize(Adjoint) to make e.g. inv(Adjoint) work (in most cases) #26302
Conversation
stdlib/LinearAlgebra/src/dense.jl
Outdated
@@ -1222,6 +1222,7 @@ function factorize(A::StridedMatrix{T}) where T | |||
end | |||
qrfact(A, Val(true)) | |||
end | |||
factorize(A::Adjoint) = adjoint(factorize(parent(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.
Why prefer adjoint(factorize(parent(A)))
over factorize(copy(A))
? Prefer avoiding an allocation to generating an object that may dispatch more nicely downstream?
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.
As you say, it saves an allocation and I think this within the core business of Adjoint
since the main thing to do after factorize
is solving and most solves ought to have methods for Adjoint
.
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 Andreas! :)
Thanks! Probably makes sense to do a similar thing for |
And |
b4a3d2d
to
cfee1b8
Compare
I think the user should do |
Could you expand on that, @fredrikekre? Adjoints are themselves |
stdlib/LinearAlgebra/test/dense.jl
Outdated
B = complex.(A, randn(n, n)) | ||
B = B + transpose(B) | ||
|
||
@test_broken inv(B')*B' ≈ I |
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.
Could you add a note about why this is broken and what would be required to fix it?
There is just so many cases where In this particular case the 0.7 equivalent of Perhaps it would have been different if |
Generally, there is a tension here between more and less experienced users. Many non-expert users would like to avoid taking |
work (in most cases)
cfee1b8
to
0f180c7
Compare
I am confused. The current implementation does not materialize On the |
That is correct. Your second point is also correct. Although a bit annoying, it only seems to be a theoretical and not a practical concern. If it becomes a real problem, I think we should just make |
Any reason not to do this? |
Making it a subtype of In general, making |
Ref: JuliaLang/LinearAlgebra.jl#2 and #10064 For QR, I think indexing would as costly as O(n^2).
Which potential issues are there here? Isn't it just that you can hit an operation that takes forever or maybe consumes all your memory. We already have these issues with other |
Are there, except for the Theoretically, it should be possible to make the adjoint of a qr factorization be such that it is the lq factorization with matrices The adjoint of an SVD factorization is again an SVD factorization. Not sure about the others though (pivoted LU, ...). |
Initially, I thought this couldn't work but now I'm in doubt. At least for the factorizations that are parametric on the array type this might actually work. I'll have to try it out. Our QR is probably a good test case. |
I've just tried to play around with this and, unfortunately, I don't think this can really work for the QR. It would require more type parameters for the factorization since the field for storing the blocked loadings isn't parametric. Even if we did that, it would be quite awkward compared to just wrapping the factorization in |
Fixes #26299. It will still fail for complex symmetric matrices and it will require a few more definitions to handle that (relatively rare) case so I've added a
@test_broken
for now.