diff options
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/core/src/multiarray/new_iterator.c.src | 9 | ||||
-rw-r--r-- | numpy/core/src/multiarray/new_iterator.h | 12 | ||||
-rw-r--r-- | numpy/core/src/multiarray/new_iterator_pywrap.c | 2 | ||||
-rw-r--r-- | numpy/core/tests/test_new_iterator.py | 9 |
4 files changed, 21 insertions, 11 deletions
diff --git a/numpy/core/src/multiarray/new_iterator.c.src b/numpy/core/src/multiarray/new_iterator.c.src index 985e7d084..9a59379b0 100644 --- a/numpy/core/src/multiarray/new_iterator.c.src +++ b/numpy/core/src/multiarray/new_iterator.c.src @@ -2016,7 +2016,14 @@ npyiter_can_cast(PyArray_Descr *from, PyArray_Descr *to, NPY_CASTING casting) } return ret; } - return 1; + + if (casting == NPY_NO_CASTING) { + return PyArray_ISNBO(from->byteorder) == + PyArray_ISNBO(to->byteorder); + } + else { + return 1; + } } /* If safe or same-kind casts are allowed */ else if (casting == NPY_SAFE_CASTING || casting == NPY_SAME_KIND_CASTING) { diff --git a/numpy/core/src/multiarray/new_iterator.h b/numpy/core/src/multiarray/new_iterator.h index 26370d8f2..90949471a 100644 --- a/numpy/core/src/multiarray/new_iterator.h +++ b/numpy/core/src/multiarray/new_iterator.h @@ -14,16 +14,16 @@ typedef void (*NpyIter_GetCoords_Fn )(NpyIter *iter, /* For specifying allowed casting in operations which support it */ typedef enum { - /* Only allow exactly equivalent types */ + /* Only allow identical types */ NPY_NO_CASTING=0, - /* Allow casts between equivalent types of different byte orders */ - NPY_EQUIV_CASTING=0, + /* Allow identical and byte swapped types */ + NPY_EQUIV_CASTING=1, /* Only allow safe casts */ - NPY_SAFE_CASTING=1, + NPY_SAFE_CASTING=2, /* Allow safe casts or casts within the same kind */ - NPY_SAME_KIND_CASTING=2, + NPY_SAME_KIND_CASTING=3, /* Allow any casts */ - NPY_UNSAFE_CASTING=3 + NPY_UNSAFE_CASTING=4 } NPY_CASTING; diff --git a/numpy/core/src/multiarray/new_iterator_pywrap.c b/numpy/core/src/multiarray/new_iterator_pywrap.c index 757ddc709..9d43774cc 100644 --- a/numpy/core/src/multiarray/new_iterator_pywrap.c +++ b/numpy/core/src/multiarray/new_iterator_pywrap.c @@ -91,7 +91,7 @@ npyiter_init(NewNpyArrayIterObject *self, PyObject *args, PyObject *kwds) PyArrayObject *op[NPY_MAXARGS]; npy_uint32 flags = 0; NPY_ORDER order = NPY_KEEPORDER; - NPY_CASTING casting = NPY_NO_CASTING; + NPY_CASTING casting = NPY_EQUIV_CASTING; npy_uint32 op_flags[NPY_MAXARGS]; PyArray_Descr *op_request_dtypes[NPY_MAXARGS]; npy_intp oa_ndim = 0; diff --git a/numpy/core/tests/test_new_iterator.py b/numpy/core/tests/test_new_iterator.py index 74affaebf..ad9b9226f 100644 --- a/numpy/core/tests/test_new_iterator.py +++ b/numpy/core/tests/test_new_iterator.py @@ -619,7 +619,8 @@ def test_iter_nbo_align(): au = a.byteswap().newbyteorder() assert_(a.dtype.byteorder != au.dtype.byteorder) i = newiter(au, [], [['readwrite','updateifcopy']], - op_dtypes=[np.dtype('f4')]) + casting='equiv', + op_dtypes=[np.dtype('f4')]) assert_equal(i.dtypes[0].byteorder, a.dtype.byteorder) assert_equal(i.operands[0].dtype.byteorder, a.dtype.byteorder) assert_equal(i.operands[0], a) @@ -631,7 +632,7 @@ def test_iter_nbo_align(): a = np.arange(6, dtype='f4') au = a.byteswap().newbyteorder() assert_(a.dtype.byteorder != au.dtype.byteorder) - i = newiter(au, [], [['readwrite','updateifcopy','nbo_aligned']]) + i = newiter(au, [], [['readwrite','updateifcopy','nbo_aligned']], casting='equiv') assert_equal(i.dtypes[0].byteorder, a.dtype.byteorder) assert_equal(i.operands[0].dtype.byteorder, a.dtype.byteorder) assert_equal(i.operands[0], a) @@ -731,7 +732,7 @@ def test_iter_array_cast_errors(): op_dtypes=[np.dtype('f4')]) # '<f4' -> '>f4' should not work with casting='no' assert_raises(TypeError, newiter, arange(2,dtype='<f4'), [], - [['readonly']], casting='no', + [['readonly','copy']], casting='no', op_dtypes=[np.dtype('>f4')]) # 'f4' -> 'f8' is a safe cast, but 'f8' -> 'f4' isn't assert_raises(TypeError, newiter, arange(2,dtype='f4'), [], @@ -1134,6 +1135,7 @@ def test_iter_buffering(): i = np.newiter(a, ['buffered','no_inner_iteration'], [['readonly','nbo_aligned']], order='C', + casting='equiv', buffersize=buffersize) while not i.finished: assert_(i[0].size <= buffersize) @@ -1148,6 +1150,7 @@ def test_iter_write_buffering(): a = np.arange(24).reshape(2,3,4).T.newbyteorder().byteswap() i = np.newiter(a, ['buffered'], [['readwrite','nbo_aligned']], + casting='equiv', order='C', buffersize=16) x = 0 |