-
-
Notifications
You must be signed in to change notification settings - Fork 35
slight optimization of exp, sqrt, ^ for positive semidefinite output #1359
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Perhaps this may be
rmul!(U, Diagonal(v))?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.
We also need to handle the case where
Uis immutable. Perhaps this should only be used whenUis aStridedArray.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.
rmul!is done, thanks for noticing it. I'm not sure what you mean by immutableU, could you show an example where it would fail?Uh oh!
There was an error while loading. Please reload this page.
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 don't have an example immediately, but given that these accept generic matrices, we probably shouldn't assume mutability of either the values or the vectors. E.g., an operation like
returns a
Vectorcurrently, but it may return a range in the future as a performance enhancement. Similarly,This is the identity matrix, and e.g.
FillArraysmay return a non-materialized matrix type here. I'd suggest having a fallback method that preserves the current behavior, and have this fast path only forStridedArrays. This way, we avoid any potential regression.Such issues, unfortunately, occasionally crop up with infinite matrices, where a special non-materialized type needs to be returned.
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.
Then I don't think doing this is a good idea; the code would become more complicated for no benefit, and we wouldn't even have a test for it.
When
eigenstarts returning immutable eigenvalues or eigenvectors then I think it would make sense. But I suspect that would break a lot of things.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'm not sure if I follow: any package may add a method to return an immutable array, and the currently working code that does not assume mutability will break after this PR. We shouldn't rely on packages returning mutable arrays. E.g., Symmetric tridiagonal Toeplitz matrices have a special structure to their eigenvalues and eigenvectors, and the fact that
ToeplitzMatricescurrently returns mutable arrays is 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.
Since there has never been a release of
LinearAlgebrathat worked with immutable objects, I'm certain this PR won't break anybody's code.But let me put it another way: we can't code for hypothetical failures. We need a concrete case to fail in the tests, otherwise the capability of handling immutable objects will be lost sooner or later. We can't rely on you reviewing every single PR to make sure it doesn't happen.
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'm not sure, but perhaps
StaticArraysare such a (immutable) case? Though they may have their own implementations anyway.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.
If I understand correctly, the special functions here already work with immutable arrays. Currently,
eigenreturns mutable arrays for standard cases, but it's possible for a package to add methods to return immutable arrays.StaticArraysis indeed such an example:This PR currently breaks
exp(S).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.
Whereas on 1.12:
But fair enough, it would start working on 1.13 but my PR would prevent it. Instead of creating a special branch for
StridedArray, which would be a horrible mess, I'd rather allocate new arrays, though. The main point of the optimization is usingsyrk, and that would stay.And I really think you should add tests for this.