diff options
author | Mark Wiebe <mwwiebe@gmail.com> | 2010-10-27 17:46:31 -0700 |
---|---|---|
committer | Pauli Virtanen <pav@iki.fi> | 2010-11-20 00:33:05 +0100 |
commit | 223f553725e41599a11313169642f064ad248059 (patch) | |
tree | 0d069c9b3dd3a35051982db1a3bba50d8c06721d | |
parent | e6f253346d7d87ba362f8283205f09eb336c482d (diff) | |
download | numpy-223f553725e41599a11313169642f064ad248059.tar.gz |
BUG: core: Change subarray field indexing to always append the shape, add tests
-rw-r--r-- | numpy/core/src/multiarray/ctors.c | 19 | ||||
-rw-r--r-- | numpy/core/tests/test_multiarray.py | 13 |
2 files changed, 16 insertions, 16 deletions
diff --git a/numpy/core/src/multiarray/ctors.c b/numpy/core/src/multiarray/ctors.c index 6e339f5df..ecffb0dc1 100644 --- a/numpy/core/src/multiarray/ctors.c +++ b/numpy/core/src/multiarray/ctors.c @@ -199,17 +199,15 @@ fromfile_skip_separator(FILE **fp, const char *sep, void *NPY_UNUSED(stream_data /* * Change a sub-array field to the base descriptor - * * and update the dimensions and strides * appropriately. Dimensions and strides are added - * to the end unless we have a FORTRAN array - * and then they are added to the beginning + * to the end. * * Strides are only added if given (because data is given). */ static int _update_descr_and_dimensions(PyArray_Descr **des, intp *newdims, - intp *newstrides, int oldnd, int isfortran) + intp *newstrides, int oldnd) { PyArray_Descr *old; int newnd; @@ -236,10 +234,6 @@ _update_descr_and_dimensions(PyArray_Descr **des, intp *newdims, if (newnd > MAX_DIMS) { goto finish; } - if (isfortran) { - memmove(newdims+numnew, newdims, oldnd*sizeof(intp)); - mydim = newdims; - } if (tuple) { for (i = 0; i < numnew; i++) { mydim[i] = (intp) PyInt_AsLong( @@ -255,10 +249,6 @@ _update_descr_and_dimensions(PyArray_Descr **des, intp *newdims, intp *mystrides; mystrides = newstrides + oldnd; - if (isfortran) { - memmove(newstrides+numnew, newstrides, oldnd*sizeof(intp)); - mystrides = newstrides; - } /* Make new strides -- alwasy C-contiguous */ tempsize = (*des)->elsize; for (i = numnew - 1; i >= 0; i--) { @@ -1390,16 +1380,13 @@ PyArray_NewFromDescr(PyTypeObject *subtype, PyArray_Descr *descr, int nd, PyObject *ret; intp newdims[2*MAX_DIMS]; intp *newstrides = NULL; - int isfortran = 0; - isfortran = (data && (flags & FORTRAN) && !(flags & CONTIGUOUS)) || - (!data && flags); memcpy(newdims, dims, nd*sizeof(intp)); if (strides) { newstrides = newdims + MAX_DIMS; memcpy(newstrides, strides, nd*sizeof(intp)); } nd =_update_descr_and_dimensions(&descr, newdims, - newstrides, nd, isfortran); + newstrides, nd); ret = PyArray_NewFromDescr(subtype, descr, nd, newdims, newstrides, data, flags, obj); diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py index cdc01f072..6bb8aced9 100644 --- a/numpy/core/tests/test_multiarray.py +++ b/numpy/core/tests/test_multiarray.py @@ -255,6 +255,19 @@ class TestCreation(TestCase): msg = 'String conversion for %s' % type assert_equal(array(nstr, dtype=type), result, err_msg=msg) +class TestStructured(TestCase): + def test_subarray_field_access(self): + a = np.zeros((3, 5), dtype=[('a', ('i4', (2, 2)))]) + a['a'] = np.arange(60).reshape(3, 5, 2, 2) + + # Since the subarray is always in C-order, these aren't equal + assert_(np.any(a['a'].T != a.T['a'])) + + # In Fortran order, the subarray gets appended + # like in all other cases, not prepended as a special case + b = a.copy(order='F') + assert_equal(a['a'].shape, b['a'].shape) + assert_equal(a.T['a'].shape, a.T.copy()['a'].shape) class TestBool(TestCase): def test_test_interning(self): |