[Numpy-discussion] Wrong treatment of byte order?

Nadav Horesh nadavh@visionsense....
Tue Aug 23 09:33:16 CDT 2011


My system is a 64 bit gentoo linux on core i7 machine. Numpy version 1.6.1 and pyton(s) 2.7.2 and 3.2.1

Problem summary:
 I tried t invert a matrix of explicit little endian byte-order and got an error. The inversion run properly with a native byte order, and I get a wrong answer with not error message when the matrix is set to big-endian.

mat is a 3x3 float64 array

>>  import numpy as N

>>> mat.dtype.byteorder
'<'
>>> N.linalg.inv(mat)                  # Refuse to ibvert
Traceback (most recent call last):
  File "<pyshell#107>", line 1, in <module>
    N.linalg.inv(mat)
  File "/usr/lib64/python2.7/site-packages/numpy/linalg/linalg.py", line 445, in inv
    return wrap(solve(a, identity(a.shape[0], dtype=a.dtype)))
  File "/usr/lib64/python2.7/site-packages/numpy/linalg/linalg.py", line 326, in solve
    results = lapack_routine(n_eq, n_rhs, a, n_eq, pivots, b, n_eq, 0)
LapackError: Parameter a has non-native byte order in lapack_lite.dgesv

>>> N.linalg.inv(mat.newbyteorder('='))    # OK
array([[ 0.09234453,  0.46163744,  0.2713108 ],
       [ 0.48886135,  0.51230859,  0.2277598 ],
       [ 0.48303131,  0.82571266,  0.17551993]])

>>> N.linalg.inv(mat.newbyteorder('>'))   # WRONG !!!
array([[  2.39051169e-159,  -7.70643158e-157,   5.34087235e-160],
       [  2.11823992e+305,   2.37224043e+307,  -4.31607382e+304],
       [ -1.26608299e+304,  -1.43225563e+306,   7.22233688e+303]])

  Nadav
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20110823/a248de1f/attachment.html 


More information about the NumPy-Discussion mailing list