-
Notifications
You must be signed in to change notification settings - Fork 2
Implement left_orth/right_orth #122
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
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #122 +/- ##
==========================================
+ Coverage 77.61% 78.26% +0.65%
==========================================
Files 32 33 +1
Lines 1604 1652 +48
==========================================
+ Hits 1245 1293 +48
Misses 359 359
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
@lkdvos going into this, I was interested to see how much of the logic in MatrixAlgebraKit.jl could be reused here. The primary issue I found was that
That isn't so straightforward for block sparse matrices and graded arrays since the block sizes and sectors may not be consistent across SVD, polar, and QR/LQ. That meant I had to repeat very similar logic in this PR to circumvent that. This PR makes me think that the MatrixAlgebraKit.jl logic is a bit too opinionated and could match the logic in this PR, I'm curious to hear what you think about that. Maybe MatrixAlgebraKit.jl could have a special codepath for StridedMatrix that allows pre-allocating the output. |
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.
Overall definitely looks reasonable to me.
As a global comment for the polar decomposition, the question is if we want to implement this as a blockwise polar, or by reimplementing the logic for computing the polar by doing a total svd and then reconstructing the polar decomposition.
Trying to think this through, I'm not sure which solution is better.
On the one hand, blockwise polar decomposition would require again to repeat the logic of constructing the correct axes, but it does seem more in the spirit of the blockwise algorithms.
On the other hand, your current implementation is quite simple and convenient, and probably the efficiency is more or less equal.
Just wanted to hear if you had more thoughts on this?
src/factorizations/orthnull.jl
Outdated
select_algorithm, | ||
svd_compact! | ||
|
||
function MatrixAlgebraKit.left_orth!( |
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.
Is this not caught by the MatrixAlgebraKit implementation? If not, it probably should?
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's a bit subtle, the MatrixAlgebraKit.jl version is designed around the output being pre-allocated, so it has an extra argument for the output. That is tricky to support for block sparse matrices since the different backends (SVD, QR/LQ, polar) might have different block structures/sectors so it isn't straightforward to pre-allocate the output in that way.
We can move this code over to MatrixAlgebraKit.jl, that was the main thing I wanted your feedback on.
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.
Ah I see now! This was indeed something that I at some point saw in MatrixAlgebraKit but then kind of forgot about in the end.
My initial reaction would be that I do think this should indeed be moved over there, such that the general codepath follows that of the @algdef
-defined functions, with a little extra implementations that make it hard to simply use @algdef
.
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.
Ok, in that case I'll make a PR to MatrixAlgebraKit.jl, it would be nice to not have this logic here.
It's a good question. I basically implemented it the current way because it is simpler and leverages the blockwise SVD. I think the leading scaling (in the limit of large blocks) should be the same so I'd lean towards keeping this version for the sake of code simplicity. Maybe we can switch over to the blockwise polar version when we change the logic of all of the blockwise factorizations to be based on first converting to a block diagonal matrix, in which case blockwise factorizations will be simpler to implement. |
@lkdvos in the latest, I removed the implementation of polar since I moved it out to #125. Also, inspired by our discussion above and on Slack, I simplified the logic here by overloading |
I definitely agree, the only thing I am wondering about is what happens if you actually do want to provide the output because you already have it. Do we just postpone handling that for now, and discard the provided outputs? |
Yeah, for now it will just discard the provided outputs, which seems ok. |
Actually, maybe I'll just make that case error for now so we know if we accidentally use that. |
This is good to go from my end, any more comments? |
I'm not entirely convinced by making that error - if you write generic code that is supposed to handle both dense and blocksparse arrays you would also not be able to provide the output. Realistically it doesn't matter that much yet though, so I'm okay with merging as is |
I was thinking that too, but also the output isn't easy to construct for block sparse arrays anyway, so how easily can you write generic code across both cases? We can always remove the error if that case comes up, I just figure the error message will make it clear to us when that happens (and generic code can specify the output as |
To do:
left_polar
/right_polar
.Future work:
lq_compact
/lq_full
.Discussion points:
left_orth
andright_orth
to MatrixAlgebraKit.jl?