numpy.linalg.det of square array of mpmath.mpfs

113 Views Asked by At

I am having the following issue:

>>> import numpy as np
>>> import mpmath as mp
>>> v1 = [mp.mpf(1), mp.mpf(2)]
>>> v2 = [mp.mpf(3), mp.mpf(4)]
>>> np.dot(v1,v2)
mpf('11.0')
>>> M2 = [[mp.mpf(1), mp.mpf(2)], [mp.mpf(3), mp.mpf(4)]]
>>> np.linalg.det(M2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "~/anaconda/lib/python2.7/site-packages/numpy/linalg/linalg.py", line 1776, in det
    r = _umath_linalg.det(a, signature=signature)
TypeError: No loop matching the specified signature and casting
was found for ufunc det

My calls to numpy's linalg.det method work fine with non-mpmath entries, yet I get the above error when giving it mp.mpfs. The old question Interoperability between Numpy and MpMath in Python indicates that np.dot will work just fine if the entries are mp.mpfs (confirmed above), so my question is why this doesn't carry over to np.linalg.det, and what I can do to get around this. The context is that I have already written a large amount of code using only numpy (no mpmath) and only just realized I will need much higher numerical precision, so ideally there is a solution that doesn't involve converting all of the numpy code.

Thanks in advance for any answers.

0

There are 0 best solutions below