Skip to content

Conversation

loiseaujc
Copy link
Contributor

Following a comment by Meromorphic on the discourse here, this PR implements the matrix exponential function expm. It does so in a new stdlib_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 input n x n matrix, order (optional) is the order of the Pade approximation, and err of type linalg_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

  • Base implementation.
  • Tests
  • in-code Documentation
  • Specifications
  • Example

Possible improvements

The implementation is fully working and validated. Computational performances and/or robustness could potentially be improved eventually by considering:

  • Automatic estimation of the best order for the Pade approximation based on the data. This is used for instance in scipy.linalg.expm.
  • Balancing is not used currently, but it might improve the robustness.

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).

Copy link
Member

@jvdp1 jvdp1 left a 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)
Copy link
Contributor

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).

Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants