[NumPy-Tickets] [NumPy] #1624: dot gives wrong result for large array with float32 objects

NumPy Trac numpy-tickets@scipy....
Fri Oct 1 07:04:34 CDT 2010


#1624: dot gives wrong result for large array with float32 objects
-----------------------+----------------------------------------------------
 Reporter:  c_huettel  |       Owner:  somebody
     Type:  defect     |      Status:  new     
 Priority:  normal     |   Milestone:  2.0.0   
Component:  Other      |     Version:  1.5.0   
 Keywords:             |  
-----------------------+----------------------------------------------------
 with
 Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56)
 [GCC 4.4.3] on linux2
 do:

 import numpy as np
 a  = map(lambda i: np.float32( i ), range( 100000 ) )
 x  = np.array( a )
 r0 = np.float32( 0 )
 for b in a:
     r0 += b*b
 ra = reduce( lambda s,i: s+x[i]*x[i], range(len(x)), np.float32(0) )
 rx = np.dot(x,x)

 print '%1.0f'%(r0), '%1.0f'%(ra), '%1.0f'%(rx), ra-rx

 this gives:
 333328452419584 333328452419584 333328318201856 1.34218e+08

 rx, the dot-product from numpy, gives a different result
 as the ( much slower ) r0 and ra computations.

 Same results are gotten when
 1) the range is only up to 10000
 2) float instead of float32 is used

 What is the reason?

-- 
Ticket URL: <http://projects.scipy.org/numpy/ticket/1624>
NumPy <http://projects.scipy.org/numpy>
My example project


More information about the NumPy-Tickets mailing list