diff options
| author | mattip <matti.picus@gmail.com> | 2021-05-19 07:27:29 +0300 |
|---|---|---|
| committer | Sebastian Berg <sebastian@sipsolutions.net> | 2021-05-19 08:31:24 -0700 |
| commit | 9cf54f170accf0b06bc55306c5cc9ae9947b477a (patch) | |
| tree | d2c3cb46777e24026a7b45136b3a2393f5ca11b5 | |
| parent | 75567b5b15940d2c09cc309eafb2950504714551 (diff) | |
| download | numpy-9cf54f170accf0b06bc55306c5cc9ae9947b477a.tar.gz | |
BUG: use PyArray_IntTupleFromIntp which handles 'long long' correctly
| -rw-r--r-- | numpy/core/src/multiarray/nditer_pywrap.c | 25 |
1 files changed, 4 insertions, 21 deletions
diff --git a/numpy/core/src/multiarray/nditer_pywrap.c b/numpy/core/src/multiarray/nditer_pywrap.c index 5ac0f8442..7698ae43d 100644 --- a/numpy/core/src/multiarray/nditer_pywrap.c +++ b/numpy/core/src/multiarray/nditer_pywrap.c @@ -1513,8 +1513,7 @@ npyiter_next(NewNpyArrayIterObject *self) static PyObject *npyiter_shape_get(NewNpyArrayIterObject *self) { - PyObject *ret; - npy_intp idim, ndim, shape[NPY_MAXDIMS]; + npy_intp ndim, shape[NPY_MAXDIMS]; if (self->iter == NULL || self->finished) { PyErr_SetString(PyExc_ValueError, @@ -1524,14 +1523,7 @@ static PyObject *npyiter_shape_get(NewNpyArrayIterObject *self) if (NpyIter_GetShape(self->iter, shape) == NPY_SUCCEED) { ndim = NpyIter_GetNDim(self->iter); - ret = PyTuple_New(ndim); - if (ret != NULL) { - for (idim = 0; idim < ndim; ++idim) { - PyTuple_SET_ITEM(ret, idim, - PyLong_FromLong(shape[idim])); - } - return ret; - } + return PyArray_IntTupleFromIntp(ndim, shape); } return NULL; @@ -1539,8 +1531,7 @@ static PyObject *npyiter_shape_get(NewNpyArrayIterObject *self) static PyObject *npyiter_multi_index_get(NewNpyArrayIterObject *self) { - PyObject *ret; - npy_intp idim, ndim, multi_index[NPY_MAXDIMS]; + npy_intp ndim, multi_index[NPY_MAXDIMS]; if (self->iter == NULL || self->finished) { PyErr_SetString(PyExc_ValueError, @@ -1551,15 +1542,7 @@ static PyObject *npyiter_multi_index_get(NewNpyArrayIterObject *self) if (self->get_multi_index != NULL) { ndim = NpyIter_GetNDim(self->iter); self->get_multi_index(self->iter, multi_index); - ret = PyTuple_New(ndim); - if (ret == NULL) { - return NULL; - } - for (idim = 0; idim < ndim; ++idim) { - PyTuple_SET_ITEM(ret, idim, - PyLong_FromLong(multi_index[idim])); - } - return ret; + return PyArray_IntTupleFromIntp(ndim, multi_index); } else { if (!NpyIter_HasMultiIndex(self->iter)) { |
