-
Notifications
You must be signed in to change notification settings - Fork 89
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 eigen and eigvals rules for StridedMatrix #321
Conversation
This is great. Would you mind adding some |
I can do that. Perhaps it would be good to add this to the testers in ChainRulesTestUtils with a configurable option like |
Yes. This would be an excellent idea. |
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 happy with this, modulo a patch bump.
Codecov Report
@@ Coverage Diff @@
## master #321 +/- ##
==========================================
+ Coverage 97.43% 97.62% +0.18%
==========================================
Files 18 18
Lines 937 1011 +74
==========================================
+ Hits 913 987 +74
Misses 24 24
Continue to review full report at Codecov.
|
Thanks! All tests pass so I'll leave open for a few days to give others a chance to review and then merge on Tuesday. |
I changed the |
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.
This looks great, and should be merged with a patch bump.
* Move symmetric rules to own file * Move symmetric tests to own file * Adapt eigen and eigvals rules from #321 * Don't allocate * Implement mutating forms for frule * Add sortby keyword * Use fewer indices * Correctly reference BlasReal * Move eigen pullback to external function * Add hermitian svd rrule * Hermitrize in pullback * Separate out eigvals sign code * Add svdvals rrule * Rearrange functions * Realify eigenvalue cotangents * Restrict to StridedMatrixes * Reduce allocations and unnecessary ops * Avoid unnecessary allocation in svd * Explicitly create eigvals pullback inputs * Simplify _hermitrize! * Add svdvals section * Don't use convenience type not in v1.0 * Fix multiplication order * Remove ambiguity in signature * Define missing variable * Make pure imaginary * Add tests for eigendecomposition rules * Test from nonsymmetric matrix * Add newlines * Remove unnecessary unthunks * Test type-stability * Test mixtures of Zeros * Use more informative testset names * Fix svd pullback bugs * Add svd pullback tests * Return correct argument * Remove unused (co)tangents * Add svdvals tests * Fix typo * Restrict SVD test to greater than v1.3.0 * Only check type-stability on 1.6 * Avoid specifying sortby keyword This is not defined on earlier Julia versions * Remove obsolete comment * Abandon ship when derivatives explode * Handle Hermitian special-case for general eigen * Fix comment * Resolve type-instability * Handle when just ΔV is Zero * Test eigen for hermitian Matrix * Make hermitian Matrix * Call eigen pullback from eigvals * Only pass sortby to Hermitian eigen * Support Julia 1.0's return for _symherm_back * Call Hermitian eigvals! frule * Call eigen rrule in eigval rrule * Test eigvals for hermitian Matrix-es * Do less expensive eltype check first * Correctly handle sortby default * Increment version number * Add references and notes * More clearly name tests * Add comment explaining test set
This PR adds rules for
eigen
andeigvals
. It is very conservative and only applies forStridedMatrix
es. Because the normalization and phase convention foreigen
for these matrices is known, the rules can explicitly account for this, which allows us to stably test with FiniteDifferences.A few notes:
eigen(::Hermitian)
, which uses a different phase convention. That is, the rule will work in a program that is invariant to the phase convention but not one that isn't. This will be handled in a future PR foreigen(::Hermitian)
(currently defined in Symmetric/Hermitian matrix function rules #193 but will be split into its own PR)