Skip to content
Advertisement

Fastest way for computing pseudoinverse (pinv) in Python

I have a a loop in which I’m calculating several pseudoinverses of rather large, non-sparse matrices (eg. 20000x800).

As my code spends most time on the pinv, I was trying to find a way to speed up the computation. I’m already using multiprocessing (joblib/loky) to run with several processes, but that of course increases also overhead. Using jit did not help much.

Is there a faster way / better implementation to compute pseudoinverse using any function? Precision isn’t key.

My current benchmark

JavaScript
JavaScript

EDIT: JAX seems to be 30% faster! impressive! Thanks for letting me know @yuri-brigance . For Windows it works well under WSL.

JavaScript

Advertisement

Answer

Try with JAX:

JavaScript

Seems to be slightly faster than regular numpy.linalg.pinv. On my machine your benchmark looks like this:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement