I'm trying to lower the error of my floating point calculation, to this end I wanted to use python mpmath to utilize the arbitrary precision of the library. But I notice that it is much slower than the math.
Consider the program
import math
import numpy as np
mathsin = np.vectorize(math.sin)
mathsin(np.arange(1,10**7)
this take around a second or two, if I do this with mpmath
import mpmath as mp
import numpy as np
mpsin = np.vectorize(mp.sin)
mpsin(np.arange(1,10**7)
this takes around forty second even if I lower the default settings of precision with mp.prec
and mp.dps
.
Is there a way to speed up such process for mpmath? And are there any general tips to making mpmath faster when using it also with numpy?