-
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 rules for solutions to Sylvester and Lyapunov equations #384
Conversation
FiniteDifferences only consistently works during overflow, but locally it works sometimes, which is enough to know that the scaling is correctly handled.
Codecov Report
@@ Coverage Diff @@
## master #384 +/- ##
==========================================
+ Coverage 97.72% 97.80% +0.07%
==========================================
Files 19 20 +1
Lines 1496 1547 +51
==========================================
+ Hits 1462 1513 +51
Misses 34 34
Continue to review full report at Codecov.
|
trans = T <: Complex ? 'C' : 'T' | ||
∂D, scale2 = LAPACK.trsyl!(trans, trans, RA, RB, ∂Y) | ||
∂Z = rmul!(QA * (∂D * QB'), -inv(scale2)) | ||
return NO_FIELDS, @thunk(∂Z * Ω'), @thunk(Ω' * ∂Z), @thunk(∂Z * inv(scale)) |
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 wonder if we should have a shorthand for inplaceable thunking multiplication.
Maybe @thunk
should be smart in that way?
Not for this PR but just something to consider
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.
That would be convenient. I haven't really put any effort into writing InplaceableThunks
, since nothing supports them yet. Simple cases like this would be easy to transform but maybe could break? e.g. for the last thunk here, the macro would not know that scale
is a number not a matrix. And is the case that we thunk just the multiplication common enough to make the code complexity worth it?
Co-authored-by: Lyndon White <[email protected]>
This PR adds rules for the following functions:
frule
forLAPACK.trsyl!
(solution to the Sylvester equation for (quasi)-triangular inputs)frule
/rrule
forsylvester
(solution to the Sylvester equation)frule
/rrule
forlyap
(solution to the Lyapunov equation)All of the rules can be written in terms of the primal function itself. However,
sylvester
andlyap
both use a Schur decomposition to solve an easier equation usingLAPACK.trsyl!
, so these rules then reuse that Schur decomposition. As a result, the included rule forlyap
is much more efficient than the one in Zygote forStridedMatrix
inputs.