-
-
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
Unalias off-diagonals in Tridiagonal constructor #51763
Conversation
I like this much better, but it looks like you'll also need to revert #35197 (as those tests added there should fail). |
I believe we have tests in the EDIT: 🤦 That's exactly what @mbauman was talking about. |
@@ -82,7 +82,7 @@ end | |||
@test TT == Matrix(TT) | |||
@test TT.dl === y | |||
@test TT.d === x | |||
@test TT.du === y | |||
@test TT.du == y |
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 document which off-diagonal is aliased to the argument of the constructor and which one may be just a copy?
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.
I feel we should document that the off diagonals shouldn't be aliased, and leave the de-aliasing as an implementation detail.
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.
Hello, as a Julia beginner and new user, I feel I might prefer to have a warning here along with the unaliasing if I alias dl
and du
(and not an error as earlier). The reason is that, in Julia, I always expect matrix assignments and calls to reuse the same memory. Silent unaliasing of dl
and du
would be (from my point of view) unexpected behaviour.
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.
I've added a comment to the docstring explaining that du
is copied if aliasing is detected.
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.
Thank you very much, @jishnub. I'm not sure if it makes sense, in my comment above, I was actually referring to a runtime warning that would seem most correct to me as a beginner.
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.
I think runtime warnings may ruin performance. Moreover, we have the hint in the documentation, so it's not exactly "silent".
Is this ready to go? I'd say so. |
Yeah, seems ok to me |
This seems better since you prevent a bug, wrong results. I'm just curious this makes a copy sometimes, e.g. in that case I presume, and why didn't it throw in the old code? Line 1521 in ea261ce
Sometimes you do not want allocations, and that is now a possibility, but also still the possibility of throwing (for unusual types). |
It didn't throw in the old code because there was no aliasing check included. It's true, it may now imply an allocation that may not be intended by the user, but it appears only once at construction, and afterwards makes no difference except that it avoids errors. |
…ti-aliasing implementation in JuliaLang#51763 + include comments in symmetriceigen.jl
As noted by Samuel Isaacson on slack, currently,
This PR resolves such issues by ensuring that the off-diagonals are not aliased. After this,
This also gets the in-place
lu!
to work on such an array, which otherwise wouldn't as the off-diagonals are aliased.It was suggested in JuliaLang/LinearAlgebra.jl#706 that a warning for mutable functions may suffice (instead of an explicit check for
dl !== du
), but preventing the aliasing seems to be a better solution that would avoid various bugs.