diff options
author | Sebastian Berg <sebastian@sipsolutions.net> | 2013-01-05 11:50:50 +0100 |
---|---|---|
committer | Sebastian Berg <sebastian@sipsolutions.net> | 2013-01-05 12:04:49 +0100 |
commit | d2ca91791024f74dd4754fa9b811228abd1ce613 (patch) | |
tree | 3da2f69fcd386303603d58cdbf274066f7dd2963 /numpy/core | |
parent | c74586282e4598e70b9b2473ee987785e2a61477 (diff) | |
download | numpy-d2ca91791024f74dd4754fa9b811228abd1ce613.tar.gz |
BUG: Fix byteswapping for complex scalars
During a cleanup, the fast paths were invalidated because SIZEOF_LONGDOUBLE
was not defined anymore and needs to be replaced with NPY_SIZEOF_LONGDOUBLE.
The other SIZEOF macros still existed however so only complex long double
broke because it switched to the already broken fast path.
This commit fixes the fast path, and replaces all SIZEOF_ macros within
arraytypes.c.src with their corresponding NPY_SIZEOF_ macros.
Diffstat (limited to 'numpy/core')
-rw-r--r-- | numpy/core/src/multiarray/arraytypes.c.src | 29 | ||||
-rw-r--r-- | numpy/core/tests/test_regression.py | 24 |
2 files changed, 28 insertions, 25 deletions
diff --git a/numpy/core/src/multiarray/arraytypes.c.src b/numpy/core/src/multiarray/arraytypes.c.src index ad45cdb9e..92782e498 100644 --- a/numpy/core/src/multiarray/arraytypes.c.src +++ b/numpy/core/src/multiarray/arraytypes.c.src @@ -946,9 +946,9 @@ HALF_to_@TYPE@(npy_half *ip, @type@ *op, npy_intp n, } /**end repeat**/ -#if SIZEOF_SHORT == 2 +#if NPY_SIZEOF_SHORT == 2 #define HALF_to_HALF SHORT_to_SHORT -#elif SIZEOF_INT == 2 +#elif NPY_SIZEOF_INT == 2 #define HALF_to_HALF INT_to_INT #endif @@ -1612,27 +1612,27 @@ static void char *a, *b, c; a = (char *)dst; -#if SIZEOF_@fsize@ == 2 +#if NPY_SIZEOF_@fsize@ == 2 b = a + 1; c = *a; *a++ = *b; *b = c; -#elif SIZEOF_@fsize@ == 4 +#elif NPY_SIZEOF_@fsize@ == 4 b = a + 3; c = *a; *a++ = *b; *b-- = c; c = *a; *a++ = *b; *b = c; -#elif SIZEOF_@fsize@ == 8 +#elif NPY_SIZEOF_@fsize@ == 8 b = a + 7; c = *a; *a++ = *b; *b-- = c; c = *a; *a++ = *b; *b-- = c; c = *a; *a++ = *b; *b-- = c; c = *a; *a++ = *b; *b = c; -#elif SIZEOF_@fsize@ == 10 +#elif NPY_SIZEOF_@fsize@ == 10 b = a + 9; c = *a; *a++ = *b; *b-- = c; c = *a; *a++ = *b; *b-- = c; c = *a; *a++ = *b; *b-- = c; c = *a; *a++ = *b; *b-- = c; c = *a; *a++ = *b; *b = c; -#elif SIZEOF_@fsize@ == 12 +#elif NPY_SIZEOF_@fsize@ == 12 b = a + 11; c = *a; *a++ = *b; *b-- = c; c = *a; *a++ = *b; *b-- = c; @@ -1640,7 +1640,7 @@ static void c = *a; *a++ = *b; *b-- = c; c = *a; *a++ = *b; *b-- = c; c = *a; *a++ = *b; *b = c; -#elif SIZEOF_@fsize@ == 16 +#elif NPY_SIZEOF_@fsize@ == 16 b = a + 15; c = *a; *a++ = *b; *b-- = c; c = *a; *a++ = *b; *b-- = c; @@ -1744,7 +1744,7 @@ static void if (swap) { char *a, *b, c; a = (char *)dst; -#if SIZEOF_@fsize@ == 4 +#if NPY_SIZEOF_@fsize@ == 4 b = a + 3; c = *a; *a++ = *b; *b-- = c; c = *a; *a++ = *b; *b = c; @@ -1752,7 +1752,7 @@ static void b = a + 3; c = *a; *a++ = *b; *b-- = c; c = *a; *a++ = *b; *b = c; -#elif SIZEOF_@fsize@ == 8 +#elif NPY_SIZEOF_@fsize@ == 8 b = a + 7; c = *a; *a++ = *b; *b-- = c; c = *a; *a++ = *b; *b-- = c; @@ -1764,7 +1764,7 @@ static void c = *a; *a++ = *b; *b-- = c; c = *a; *a++ = *b; *b-- = c; c = *a; *a++ = *b; *b = c; -#elif SIZEOF_@fsize@ == 10 +#elif NPY_SIZEOF_@fsize@ == 10 b = a + 9; c = *a; *a++ = *b; *b-- = c; c = *a; *a++ = *b; *b-- = c; @@ -1778,7 +1778,7 @@ static void c = *a; *a++ = *b; *b-- = c; c = *a; *a++ = *b; *b-- = c; c = *a; *a++ = *b; *b = c; -#elif SIZEOF_@fsize@ == 12 +#elif NPY_SIZEOF_@fsize@ == 12 b = a + 11; c = *a; *a++ = *b; *b-- = c; c = *a; *a++ = *b; *b-- = c; @@ -1794,7 +1794,7 @@ static void c = *a; *a++ = *b; *b-- = c; c = *a; *a++ = *b; *b-- = c; c = *a; *a++ = *b; *b = c; -#elif SIZEOF_@fsize@ == 16 +#elif NPY_SIZEOF_@fsize@ == 16 b = a + 15; c = *a; *a++ = *b; *b-- = c; c = *a; *a++ = *b; *b-- = c; @@ -1825,9 +1825,8 @@ static void *a++ = *b; *b-- = c; } - a += nn / 2; + a += nn; b = a + (NPY_SIZEOF_@fsize@ - 1); - nn = NPY_SIZEOF_@fsize@ / 2; for (i = 0; i < nn; i++) { c = *a; *a++ = *b; diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py index adc991bd9..d5e59cdc0 100644 --- a/numpy/core/tests/test_regression.py +++ b/numpy/core/tests/test_regression.py @@ -1296,16 +1296,20 @@ class TestRegression(TestCase): np.dot(a['f0'], b['f0']) def test_byteswap_complex_scalar(self): - """Ticket #1259""" - z = np.array([-1j], '<c8') - x = z[0] # always native-endian - y = x.byteswap() - if x.dtype.byteorder == z.dtype.byteorder: - # little-endian machine - assert_equal(x, np.fromstring(y.tostring(), dtype='>c8')) - else: - # big-endian machine - assert_equal(x, np.fromstring(y.tostring(), dtype='<c8')) + """Ticket #1259 and gh-441""" + for dtype in [np.dtype('<'+t) for t in np.typecodes['Complex']]: + z = np.array([2.2-1.1j], dtype) + x = z[0] # always native-endian + y = x.byteswap() + if x.dtype.byteorder == z.dtype.byteorder: + # little-endian machine + assert_equal(x, np.fromstring(y.tostring(), dtype=dtype.newbyteorder())) + else: + # big-endian machine + assert_equal(x, np.fromstring(y.tostring(), dtype=dtype)) + # double check real and imaginary parts: + assert_equal(x.real, y.real.byteswap()) + assert_equal(x.imag, y.imag.byteswap()) def test_structured_arrays_with_objects1(self): """Ticket #1299""" |