pythonnumpyscipymatrix-inversematrix-decomposition

Inverting a triangular matrix in python/numpy/scipy


I am looking to invert a (lower) triangular matrix that comes from the Cholesky decomposition of A, as A = L @ L.T. There are a few potential solutions, including numpy: inverting an upper triangular matrix. Unfortunately, this question is now more than 11 years old so newer solutions might exist now. Is there any method in numpy or scipy or any other relevant package that could be used to compute the inverse of a triangular matrix, upper or lower?

I can obviously code a solution myself (inverse of diagonal terms and ensuring that non-diagonal products are null) but this is error-prone and might not be as stable and tested as more common packages.


Solution

  • Echoing the previous post, it is often unnecessary to obtain the explicit inverse, and refactoring the code to call a triangular solver routine wherever it is used next is usually preferable. Using a triangular solver with identity as the complementary argument produces the explicit inverse if it is really necessary.

    Tensorflow's triangular solver can be much faster than those mentioned in the previous post if used correctly. See:

    https://www.tensorflow.org/api_docs/python/tf/linalg/triangular_solve https://www.tensorflow.org/guide/function

    Other than that (as someone who does a lot of work with Cholesky decompositions) the answers in the previous post still ring true from my perspective.