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

NumPy Trac numpy-tickets@scipy....
Fri Oct 1 07:09:23 CDT 2010


#1624: dot gives wrong result for large array with float32 objects
------------------------+---------------------------------------------------
 Reporter:  c_huettel   |       Owner:  somebody
     Type:  defect      |      Status:  new     
 Priority:  high        |   Milestone:  2.0.0   
Component:  numpy.core  |     Version:  1.3.0   
 Keywords:              |  
------------------------+---------------------------------------------------
Changes (by c_huettel):

  * priority:  normal => high
  * version:  1.5.0 => 1.3.0
  * component:  Other => numpy.core


Comment:

 Hallo,
 the formatting was bad, here the better version:

 with Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56) [[BR]]
 [GCC 4.4.3] on linux2 do:

 {{{
 import numpy as np [[BR]]
 a = map(lambda i: np.float32( i ), range( 100000 ) ) [[BR]]
 x = np.array( a ) [[BR]]
 r0 = np.float32( 0 ) [[BR]]
 for b in a:
     r0 += b*b

 ra = reduce( lambda s,i: s+x[i]*x[i], range(len(x)), np.float32(0) )
 [[BR]]
 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#comment:1>
NumPy <http://projects.scipy.org/numpy>
My example project


More information about the NumPy-Tickets mailing list