diff options
author | Sebastian Berg <sebastian@sipsolutions.net> | 2012-09-29 17:48:09 +0200 |
---|---|---|
committer | Sebastian Berg <sebastian@sipsolutions.net> | 2012-09-29 18:11:02 +0200 |
commit | 095534fbceb34b03a5c963acd77834a9b001bf38 (patch) | |
tree | c7650dcff4113808f86808e7fd00987ebd6b5586 | |
parent | fd63e8f7dcbab6b7c66bd4be400153592319e7b3 (diff) | |
download | numpy-095534fbceb34b03a5c963acd77834a9b001bf38.tar.gz |
BUG: Fill correct strides for ndmin in array creation
Closes "Issue #465", strides need to be set according
to the requested contiguous flags.
-rw-r--r-- | numpy/core/src/multiarray/multiarraymodule.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/numpy/core/src/multiarray/multiarraymodule.c b/numpy/core/src/multiarray/multiarraymodule.c index 29beb841c..cd8e3afba 100644 --- a/numpy/core/src/multiarray/multiarraymodule.c +++ b/numpy/core/src/multiarray/multiarraymodule.c @@ -1507,18 +1507,26 @@ PyArray_EquivTypenums(int typenum1, int typenum2) /*** END C-API FUNCTIONS **/ static PyObject * -_prepend_ones(PyArrayObject *arr, int nd, int ndmin) +_prepend_ones(PyArrayObject *arr, int nd, int ndmin, NPY_ORDER order) { npy_intp newdims[NPY_MAXDIMS]; npy_intp newstrides[NPY_MAXDIMS]; + npy_intp newstride; int i, k, num; PyArrayObject *ret; PyArray_Descr *dtype; + if (order == NPY_FORTRANORDER || PyArray_ISFORTRAN(arr) || PyArray_NDIM(arr) == 0) { + newstride = PyArray_DESCR(arr)->elsize; + } + else { + newstride = PyArray_STRIDES(arr)[0] * PyArray_DIMS(arr)[0]; + } + num = ndmin - nd; for (i = 0; i < num; i++) { newdims[i] = 1; - newstrides[i] = PyArray_DESCR(arr)->elsize; + newstrides[i] = newstride; } for (i = num; i < ndmin; i++) { k = i - num; @@ -1659,7 +1667,7 @@ _array_fromobject(PyObject *NPY_UNUSED(ignored), PyObject *args, PyObject *kws) * create a new array from the same data with ones in the shape * steals a reference to ret */ - return _prepend_ones(ret, nd, ndmin); + return _prepend_ones(ret, nd, ndmin, order); clean_type: Py_XDECREF(type); |