What is the best pseudo inverse (Moore-Penrose inverse) subroutine?

Dear all,

Pseudo inverse (Moore-Penrose inverse), usually is called pinv in Matlab or some Python library, etc.
In Fortran, what is the best pseudo inverse (Moore-Penrose inverse) subroutine?

Thanks much in advance!

DGELSD computes the minimum-norm solution to a linear least squares problem for GE matrices.

If you really do need the inverse (see my reply in Why doesn't Fortran have a built-in matrix inverse function? - #4 by ivanpribec), then do your SVD / QR / LQ factorization first and then solve A X = I.

Note for example the Eigen C++ library has a complete orthogonal decomposition routine, which also provides a pseudo inverse method, however the documentation states explicitly:

Do not compute this->pseudoInverse()*rhs to solve a linear systems. It is more efficient and numerically stable to call this->solve(rhs) .

1 Like

Yes. Use one of the LAPACK suite of solvers.

If performance is an issue then make sure that you link to a BLAS implementation that is optimized for your platform and compiler.

1 Like