summaryrefslogtreecommitdiff
path: root/numpy/linalg
diff options
context:
space:
mode:
authorMatthew Brett <matthew.brett@gmail.com>2012-03-17 01:32:40 -0700
committerCharles Harris <charlesr.harris@gmail.com>2012-03-17 17:01:54 -0600
commit016ad9fb4d818feae2974ffae7c4ff0bbc99e3b0 (patch)
tree8fe01f3fb14c6ef27766d551561419fa56dadb1a /numpy/linalg
parent83480b6eb106d8c7e1d9293d7adc988c7c670778 (diff)
downloadnumpy-016ad9fb4d818feae2974ffae7c4ff0bbc99e3b0.tar.gz
BUG: native but not '=' byte order error in lapack
The check_object call in lapack_litemodule was checking if the passed array was of byteorder '=' or '|', but this check failed for arrays of specified native byte order ('<' on little-endian).
Diffstat (limited to 'numpy/linalg')
-rw-r--r--numpy/linalg/lapack_litemodule.c3
-rw-r--r--numpy/linalg/tests/test_linalg.py22
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()