[Numpy-discussion] Non-deterministic floating point behavior in numpy 1.5.1 ?

josef.pktd@gmai... josef.pktd@gmai...
Wed Feb 2 08:07:34 CST 2011


On Wed, Jan 12, 2011 at 1:05 PM, Pauli Virtanen <pav@iki.fi> wrote:
> Wed, 12 Jan 2011 17:34:32 +0000, Grégory Guyomarc'h wrote:
> [clip]
>>       y = (numpy.dot(m, x) - 13.90901663) * 1000.0 print y[0]
> [clip]
>> Also, I could not reproduce it with older versions of numpy such as 1.3.
>> Is this behavior expected ? Is there a way to make sure the results of a
>> numpy floating point computations remains the same for multiple runs?
>
> There are essentially no changes in the dot() routine since 1.3.0 in
> Numpy. The non-determinism is probably in the BLAS linear algebra library
> you have linked Numpy with. What platform are you using? (Windows? Linux?
> Where did you obtain Numpy binaries?)
>
> What do you get if you replace `numpy.dot` with
> `numpy.core.multiarray.dot` (which does not use BLAS)?
>
> There's another thread on a similar issue here:
>
> http://permalink.gmane.org/gmane.comp.python.scientific.user/27444

The question seems to show up now pretty often, for Win32

np.core.multiarray.dot always produces the same result
Lapack dot has variation, but not always, and it sometimes produces
consistently a result different from
np.core.multiarray.dot

I copied some results to the attached script file, running inside IDLE
- variation, running as script on commandline - no variation, but
different, running repeatedly with execfile in commandline session -
same as IDLE session.

I'm using the official numpy 1.5.1 release

Josef





>
> --
> Pauli Virtanen
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
-------------- next part --------------
'''Non-deterministic behavior of Lapack
from january 12, 2010, numpy mailing list
Non-deterministic floating point behavior in numpy 1.5.1
'''

import numpy as np

#numpy.core.multiarray.dot

x = np.array([[0.00010876945607980702], [0.22568137594619658],
[5.6435218858623557]])

print '\nusing lapack'
for i in range(10):
    m = np.array([[36.0 * 36.0, 36.0, 1.0] for j in range(6)])
    y = (np.dot(m, x) - 13.90901663) * 1000.0
    print y[0]

print '\nusing np.core.multiarray.dot'
for i in range(10):
    m = np.array([[36.0 * 36.0, 36.0, 1.0] for j in range(6)])
    y = (np.core.multiarray.dot(m, x) - 13.90901663) * 1000.0
    print y[0]    


'''
in IDLE session, running several times the same script

using lapack
[  5.00486230e-06]
[  5.00486230e-06]
[  5.00486230e-06]
[  5.00486230e-06]
[  5.00486230e-06]
[  5.00486230e-06]
[  5.00486230e-06]
[  5.00486230e-06]
[  5.00486230e-06]
[  5.00486230e-06]

using np.core.multiarray.dot
[  5.00486230e-06]
[  5.00486230e-06]
[  5.00486230e-06]
[  5.00486230e-06]
[  5.00486230e-06]
[  5.00486230e-06]
[  5.00486230e-06]
[  5.00486230e-06]
[  5.00486230e-06]
[  5.00486230e-06]
>>> 

using lapack
[  5.00486230e-06]
[  5.00486408e-06]
[  5.00486230e-06]
[  5.00486408e-06]
[  5.00486230e-06]
[  5.00486408e-06]
[  5.00486230e-06]
[  5.00486408e-06]
[  5.00486230e-06]
[  5.00486408e-06]

using np.core.multiarray.dot
[  5.00486230e-06]
[  5.00486230e-06]
[  5.00486230e-06]
[  5.00486230e-06]
[  5.00486230e-06]
[  5.00486230e-06]
[  5.00486230e-06]
[  5.00486230e-06]
[  5.00486230e-06]
[  5.00486230e-06]


on the command line, new run of script each time

C:\Josef\work-oth>try_numpy_determ.py

using lapack
[  5.00486408e-06]
[  5.00486408e-06]
[  5.00486408e-06]
[  5.00486408e-06]
[  5.00486408e-06]
[  5.00486408e-06]
[  5.00486408e-06]
[  5.00486408e-06]
[  5.00486408e-06]
[  5.00486408e-06]

using np.core.multiarray.dot
[  5.00486230e-06]
[  5.00486230e-06]
[  5.00486230e-06]
[  5.00486230e-06]
[  5.00486230e-06]
[  5.00486230e-06]
[  5.00486230e-06]
[  5.00486230e-06]
[  5.00486230e-06]
[  5.00486230e-06]


session on commandline, without IDLE

C:\Josef\work-oth>python -i try_numpy_determ.py

using lapack
[  5.00486230e-06]
[  5.00486408e-06]
[  5.00486230e-06]
[  5.00486408e-06]
[  5.00486230e-06]
[  5.00486408e-06]
[  5.00486230e-06]
[  5.00486408e-06]
[  5.00486230e-06]
[  5.00486408e-06]

using np.core.multiarray.dot
[  5.00486230e-06]
[  5.00486230e-06]
[  5.00486230e-06]
[  5.00486230e-06]
[  5.00486230e-06]
[  5.00486230e-06]
[  5.00486230e-06]
[  5.00486230e-06]
[  5.00486230e-06]
[  5.00486230e-06]
>>> execfile('try_numpy_determ.py')

using lapack
[  5.00486230e-06]
[  5.00486408e-06]
[  5.00486230e-06]
[  5.00486408e-06]
[  5.00486230e-06]
[  5.00486408e-06]
[  5.00486230e-06]
[  5.00486408e-06]
[  5.00486230e-06]
[  5.00486408e-06]

using np.core.multiarray.dot
[  5.00486230e-06]
[  5.00486230e-06]
[  5.00486230e-06]
[  5.00486230e-06]
[  5.00486230e-06]
[  5.00486230e-06]
[  5.00486230e-06]
[  5.00486230e-06]
[  5.00486230e-06]
[  5.00486230e-06]
>>> execfile('try_numpy_determ.py')

using lapack
[  5.00486230e-06]
[  5.00486408e-06]
[  5.00486230e-06]
[  5.00486408e-06]
[  5.00486230e-06]
[  5.00486408e-06]
[  5.00486230e-06]
[  5.00486408e-06]
[  5.00486230e-06]
[  5.00486408e-06]

using np.core.multiarray.dot
[  5.00486230e-06]
[  5.00486230e-06]
[  5.00486230e-06]
[  5.00486230e-06]
[  5.00486230e-06]
[  5.00486230e-06]
[  5.00486230e-06]
[  5.00486230e-06]
[  5.00486230e-06]
[  5.00486230e-06]
>>>



>>> np.show_config()
atlas_threads_info:
  NOT AVAILABLE
blas_opt_info:
    libraries = ['f77blas', 'cblas', 'atlas']
    library_dirs = ['C:\\local\\lib\\yop\\sse2']
    define_macros = [('ATLAS_INFO', '"\\"?.?.?\\""')]
    language = c
atlas_blas_threads_info:
  NOT AVAILABLE
lapack_opt_info:
    libraries = ['lapack', 'f77blas', 'cblas', 'atlas']
    library_dirs = ['C:\\local\\lib\\yop\\sse2']
    define_macros = [('ATLAS_INFO', '"\\"?.?.?\\""')]
    language = f77
atlas_info:
    libraries = ['lapack', 'f77blas', 'cblas', 'atlas']
    library_dirs = ['C:\\local\\lib\\yop\\sse2']
    language = f77
lapack_mkl_info:
  NOT AVAILABLE
blas_mkl_info:
  NOT AVAILABLE
atlas_blas_info:
    libraries = ['f77blas', 'cblas', 'atlas']
    library_dirs = ['C:\\local\\lib\\yop\\sse2']
    language = c
mkl_info:
  NOT AVAILABLE

>>> np.__version__
'1.5.1'
'''


More information about the NumPy-Discussion mailing list