diff options
author | Sebastian Berg <sebastian@sipsolutions.net> | 2021-05-19 09:29:37 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-19 09:29:37 -0700 |
commit | 3a61a14b46535d1ce552d06f1be8172c0fc233c4 (patch) | |
tree | 35e5093c917fed8cf38239490fff40bfeb6ca92b /numpy/core | |
parent | dbed464aa31069a90637a540cc464e6a59feec30 (diff) | |
parent | 9cf54f170accf0b06bc55306c5cc9ae9947b477a (diff) | |
download | numpy-3a61a14b46535d1ce552d06f1be8172c0fc233c4.tar.gz |
Merge pull request #19037 from mattip/more-long
BUG: use PyLong_FromSsize_t where needed
Diffstat (limited to 'numpy/core')
-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)) { |