Python: make scipy use numpy.float128 instead numpy.float64?

Is it possible, and if yes how to do it: How can I make scipy use by default numpy.float128. For example

>>> from scipy.stats import norm
>>> type(norm.pdf(10, 10, 1))
<class 'numpy.float64'>

and I want it to be

>>> from scipy.stats import norm
>>> type(norm.pdf(10, 10, 1))
<class 'numpy.float128'>

If not, I will need to implement norm.pdf function by myself, which is easy, but do not solve my problem.

Upvotes: 4

Views: 943

Answers (1)

Warren Weckesser
Warren Weckesser

Reputation: 114781

In general, you can't. Some of the scipy routines are wrappers of code written in C or Fortran that are only available in double precision. Even if you figure out which ones are pure python+numpy, and manage to ensure that the operations performed in the computation preserve the data type, you'll find that many of the functions use hardcoded 64 bit constants such as numpy.pi.

Upvotes: 3

Related Questions