[Numpy-discussion] Floating Point Difference between numpy and numarray

Sebastian Stephan Berg sebastian@sipsolutions....
Mon Sep 8 16:55:55 CDT 2008


Yeah, I memory wise it doesn't matter to sum to a double, but just
trying around it seems that the mixing of float and double is very slow
(at least on my comp) while if the starting array is already double
there is almost no difference for summing. Generally double precision
calculations should be slower though. Don't extensions like SSE2 operate
either on 2 doubles or 4 floats at once and thus should be about twice
as fast for floats? For add/multiply this behaviour is for me visible
anyways.

Some timeings for sum and also add with different datatypes, f64 being a
float64 and f32 a float32 array (times not very exact):

In [20]: %timeit f32.sum(dtype='float32')
10 loops, best of 3: 70.5 ms per loop

In [21]: %timeit f32.sum(dtype='float64')
10 loops, best of 3: 334 ms per loop

In [22]: %timeit f64.sum(dtype='float32')
10 loops, best of 3: 329 ms per loop

In [23]: %timeit f64.sum(dtype='float64')
10 loops, best of 3: 75.3 ms per loop

And add (similar for multiplying):

In [50]: %timeit add(f64, 1.32, f64)
10 loops, best of 3: 158 ms per loop

In [51]: %timeit add(f32, 1.32, f32)
10 loops, best of 3: 78.1 ms per loop

It seems here numpy picked float32 for 1.32 in the second case. If I
give array([1.32], dtype='float64') performance drops to 200+ ms!

Maybe this speed difference when summing to a different type is a reason
for not changing the default type though.


Sebastian



More information about the Numpy-discussion mailing list