-
Notifications
You must be signed in to change notification settings - Fork 195
Matrix exponential #1038
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
base: master
Are you sure you want to change the base?
Matrix exponential #1038
Conversation
Updating branch with latest dev from stdlib/main
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 @loiseaujc . Overall LGTM. Here are some suggestions
contains | ||
|
||
#:for rk,rt,ri in RC_KINDS_TYPES | ||
module function stdlib_linalg_${ri}$_expm_fun(A, order) result(E) |
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.
pure style, I'm an advocate of having the kind suffix at the end of the procedure name signature. Kind of like the "hh:mm:ss" principle (the thing that changes the most last).
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 a strong preference there. I went with whatever @perazz used for the Cholesky:
pure module function stdlib_linalg_${ri}$_cholesky_fun(a,lower,other_zeroed) result(c)
Either ways are fine with me.
Co-authored-by: Jeremie Vandenplas <[email protected]>
Following a comment by Meromorphic on the discourse here, this PR implements the matrix exponential function
expm
. It does so in a newstdlib_linalg_matrix_functions
submodule which might eventually accomodate later on implementations of other matrix functions (e.g.logm
,sqrtm
,cosm
, etc).Proposed interfaces
E = expm(A [, order, err])
call matrix_exp(A [, order, err])
(in-place)call matrix_exp(A, E [, order, err])
(out-of-place)where
A
is the inputn x n
matrix,order
(optional) is the order of the Pade approximation, anderr
of typelinalg_state_type
for error handling.Key facts
The implementation makes use of a standard "scaling and squaring" approach to compute the Pade approximation with a fixed order. It is adapted from the implementation by John Burkardt.
Progress
Possible improvements
The implementation is fully working and validated. Computational performances and/or robustness could potentially be improved eventually by considering:
order
for the Pade approximation based on the data. This is used for instance inscipy.linalg.expm
.In practice, it has however never failed me so far.
cc @perazz, @jvdp1, @jalvesz
PS : This is actually a re-opening of #968 which was automatically closed when I deleted my own fork of
stdlib
(don't ask me why, I can't remember).