[Tutor] hi

Oscar Benjamin oscar.j.benjamin at gmail.com
Mon Aug 12 23:07:31 CEST 2013


On 12 August 2013 21:41, Vick <vick1975 at orange.mu> wrote:
>> From: Oscar Benjamin [mailto:oscar.j.benjamin at gmail.com]
>>
>> It's because I'm using double precision and you're using mpmath.
>
> [Vick] Where is the call for double precision in your code?
> Is it built in with scipy or maybe odeint?

When you write
    from math import exp
    a = 1.0
    b = exp(a)
you're working with Python float objects which are implemented in 64
bit double precision. These are very efficient since the computations
are accelerated in the FPU.

When you write
    from mpmath import mpf, exp
    a = mpf('1')
    b = exp(a)
your working with Multi-Precision Floats from the mpmath library. This
is implemented in pure Python and runs a lot slower (it'll be faster
if you have gmpy installed but still much slower than the FPU).

Try writing a simple script that computes something using floats or
using mpmath and you will notice the speed difference very quickly.
The same thing happens when using the decimal module (although it is
*much* faster in Python 3.3).


Oscar


More information about the Tutor mailing list