diff options
Diffstat (limited to 'numpy/linalg')
-rw-r--r-- | numpy/linalg/lapack_litemodule.c | 3 | ||||
-rw-r--r-- | numpy/linalg/tests/test_linalg.py | 22 |
2 files changed, 23 insertions, 2 deletions
diff --git a/numpy/linalg/lapack_litemodule.c b/numpy/linalg/lapack_litemodule.c index f302deb9d..25a0181ea 100644 --- a/numpy/linalg/lapack_litemodule.c +++ b/numpy/linalg/lapack_litemodule.c @@ -115,8 +115,7 @@ check_object(PyObject *ob, int t, char *obname, "Parameter %s is not of type %s in lapack_lite.%s", obname, tname, funname); return 0; - } else if (((PyArrayObject *)ob)->descr->byteorder != '=' && - ((PyArrayObject *)ob)->descr->byteorder != '|') { + } else if (PyArray_ISBYTESWAPPED(ob)) { PyErr_Format(LapackError, "Parameter %s has non-native byte order in lapack_lite.%s", obname, funname); diff --git a/numpy/linalg/tests/test_linalg.py b/numpy/linalg/tests/test_linalg.py index 3e832b62f..2a2ec3da5 100644 --- a/numpy/linalg/tests/test_linalg.py +++ b/numpy/linalg/tests/test_linalg.py @@ -1,5 +1,6 @@ """ Test functions for linalg module """ +import sys import numpy as np from numpy.testing import * @@ -456,5 +457,26 @@ class TestQR(TestCase): self.assertRaises(linalg.LinAlgError, linalg.qr, a) +def test_byteorder_check(): + # Byte order check should pass for native order + if sys.byteorder == 'little': + native = '<' + else: + native = '>' + + for dtt in (np.float32, np.float64): + arr = np.eye(4, dtype=dtt) + n_arr = arr.newbyteorder(native) + sw_arr = arr.newbyteorder('S').byteswap() + assert_equal(arr.dtype.byteorder, '=') + for routine in (linalg.inv, linalg.det, linalg.pinv): + # Normal call + res = routine(arr) + # Native but not '=' + assert_array_equal(res, routine(n_arr)) + # Swapped + assert_array_equal(res, routine(sw_arr)) + + if __name__ == "__main__": run_module_suite() |