Skip to content

Commit

Permalink
BUG: use PyArray_IntTupleFromIntp which handles 'long long' correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
mattip authored and seberg committed May 19, 2021
1 parent 75567b5 commit 9cf54f1
Showing 1 changed file with 4 additions and 21 deletions.
25 changes: 4 additions & 21 deletions numpy/core/src/multiarray/nditer_pywrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -1524,23 +1523,15 @@ 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;
}

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,
Expand All @@ -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)) {
Expand Down

0 comments on commit 9cf54f1

Please sign in to comment.