Skip to content

Commit 540cdb3

Browse files
committed
Change if statement to a macro
1 parent 0dd77b4 commit 540cdb3

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

numpy/_core/src/multiarray/item_selection.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -231,31 +231,35 @@ PyArray_TakeFrom(PyArrayObject *self0, PyObject *indices0, int axis,
231231
PyArrayObject *out, NPY_CLIPMODE clipmode)
232232
{
233233
PyArray_Descr *dtype;
234-
PyArrayObject *obj = NULL, *self, *indices, *tmp;
234+
PyArrayObject *obj = NULL, *self, *indices;
235235
npy_intp nd, i, n, m, max_item, chunk, itemsize, nelem;
236236
npy_intp shape[NPY_MAXDIMS];
237237

238238
npy_bool needs_refcounting;
239239

240-
indices = tmp = NULL;
240+
indices = NULL;
241241
self = (PyArrayObject *)PyArray_CheckAxis(self0, &axis,
242242
NPY_ARRAY_CARRAY_RO);
243243
if (self == NULL) {
244244
return NULL;
245245
}
246+
247+
#if NPY_SIZEOF_INTP == NPY_SIZEOF_INT
248+
PyArrayObject *tmp;
246249
tmp = (PyArrayObject *)PyArray_ContiguousFromAny(indices0,
247250
NPY_INT64,
248251
0, 0);
249252
if (tmp == NULL) {
250253
goto fail;
251254
}
252255

253-
if (NPY_SIZEOF_INTP != 8) {
254-
indices = (PyArrayObject *)PyArray_Cast(tmp, NPY_INTP);
255-
Py_DECREF(tmp);
256-
} else {
257-
indices = tmp;
258-
}
256+
indices = (PyArrayObject *)PyArray_Cast(tmp, NPY_INTP);
257+
Py_DECREF(tmp);
258+
#else
259+
indices = (PyArrayObject *)PyArray_ContiguousFromAny(indices0,
260+
NPY_INT64,
261+
0, 0);
262+
#endif
259263

260264
if (indices == NULL) {
261265
goto fail;

0 commit comments

Comments
 (0)