I'm writing some code in python that requires frequently inverting large square matrices (100-200 rows/colums).
I'm hitting the limits of machine precision so have started trying to use mpmath
to do arbitrary precision matrix inversion but it is very slow, even using gmpy
.
Inverting random matrices of size 20, 30, 60 at precision 30 (decimal) takes ~ 0.19, 0.60, and 4.61 seconds whereas the same operations in mathematica
take 0.0084, 0.015, and 0.055 seconds.
This is using python3
and mpmath 0.17
(not sure of gmpy version) on an arch linux machine. I'm not sure why mpmath is so much slower but is there any open source library that will approach the speeds mathematica manages for this (even 1/2 as fast would be good)?
I don't need arbitrary precision -- 128 bit would probably be good enough. I also just don't understand how mpmath can be so much slower. It must be using a very different matrix inversion algorithm. To be specific I'm using M**-1
.
Is there a way to get it to use a faster algorithm or to speed it up.