What implementation is used for `matrix_exp`?

The documentation here explains what the matrix exponential is, but not how it’s implemented. I know this is a massive area of research, so I’d like to know which particular implementation is used.

Thank you

I think you can find the implementation here.

For reference, we use the algorithm suggested in the paper Mathematics | Free Full-Text | Computing the Matrix Exponential with an Optimized Taylor Polynomial Approximation

1 Like

Thank you! Do I understand correctly that the bottleneck in this approximation is essentially a constant number of matrix multiplications?

Depends. Does your computation happen on CPU or CUDA? In the former, the algorithm can be understood as a number of mms. In the latter, you have to think about things like synchronisations and so on. The current implementation could do a better job when it comes to these really.

Is it possible to add the pade-based matrix_exp method to pytorch? I found that the tylor-based method has poor computational accuracy when the matrix order exceeds 100.

Contributions are welcome, so you could create a feature request on GitHub describing your implementation and advantage, in case you are interested in implementing it.

Is there a reference somewhere for why the current implementation for matrix exponential was chosen? Have been going through issues like [feature request] Add matrix functions · Issue #9983 · pytorch/pytorch · GitHub to try to find where a discussion of the various choices of implementation may have existed (or still exist).

It may be worthwhile to explicitly add test-cases of the limitations of the current/given implementation, for example related to the above comments ‘taylor-based method has poor computational accuracy when the matrix order exceeds 100.’