summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Wieser <wieser.eric@gmail.com>2020-04-15 12:30:08 +0100
committerEric Wieser <wieser.eric@gmail.com>2020-04-15 14:55:10 +0100
commit6e3df98c15e7fe930e6bdbd3ef9d06881fe0a484 (patch)
treeca6138a595f823246a09c612d6637dd351fddbbd
parent8d7ac42dfcf408caadab08aeb63f4bec7327a773 (diff)
downloadnumpy-6e3df98c15e7fe930e6bdbd3ef9d06881fe0a484.tar.gz
MAINT: Move declarations next to usage
-rw-r--r--numpy/core/src/umath/reduction.c32
1 files changed, 15 insertions, 17 deletions
diff --git a/numpy/core/src/umath/reduction.c b/numpy/core/src/umath/reduction.c
index 5b049be4e..b2b4db012 100644
--- a/numpy/core/src/umath/reduction.c
+++ b/numpy/core/src/umath/reduction.c
@@ -89,14 +89,13 @@ conform_reduce_result(PyArrayObject *in, const npy_bool *axis_flags,
PyArrayObject *out, int keepdims, const char *funcname,
int need_copy)
{
- int ndim = PyArray_NDIM(in);
- npy_intp *shape_in = PyArray_DIMS(in);
- npy_intp strides[NPY_MAXDIMS], shape[NPY_MAXDIMS];
- npy_intp *strides_out = PyArray_STRIDES(out);
- npy_intp *shape_out = PyArray_DIMS(out);
- int idim, idim_out, ndim_out = PyArray_NDIM(out);
- PyArray_Descr *dtype;
- PyArrayObject_fields *ret;
+ /* unpack shape information */
+ int const ndim = PyArray_NDIM(in);
+ npy_intp const *shape_in = PyArray_DIMS(in);
+
+ int const ndim_out = PyArray_NDIM(out);
+ npy_intp const *strides_out = PyArray_STRIDES(out);
+ npy_intp const *shape_out = PyArray_DIMS(out);
/*
* If the 'keepdims' parameter is true, do a simpler validation and
@@ -111,7 +110,7 @@ conform_reduce_result(PyArrayObject *in, const npy_bool *axis_flags,
return NULL;
}
- for (idim = 0; idim < ndim; ++idim) {
+ for (int idim = 0; idim < ndim; ++idim) {
if (axis_flags[idim]) {
if (shape_out[idim] != 1) {
PyErr_Format(PyExc_ValueError,
@@ -138,8 +137,9 @@ conform_reduce_result(PyArrayObject *in, const npy_bool *axis_flags,
}
/* Construct the strides and shape */
- idim_out = 0;
- for (idim = 0; idim < ndim; ++idim) {
+ npy_intp strides[NPY_MAXDIMS], shape[NPY_MAXDIMS];
+ int idim_out = 0;
+ for (int idim = 0; idim < ndim; ++idim) {
if (axis_flags[idim]) {
strides[idim] = 0;
shape[idim] = 1;
@@ -172,10 +172,10 @@ conform_reduce_result(PyArrayObject *in, const npy_bool *axis_flags,
}
/* Allocate the view */
- dtype = PyArray_DESCR(out);
+ PyArray_Descr *dtype = PyArray_DESCR(out);
Py_INCREF(dtype);
- ret = (PyArrayObject_fields *)PyArray_NewFromDescrAndBase(
+ PyArrayObject_fields *ret = (PyArrayObject_fields *)PyArray_NewFromDescrAndBase(
&PyArray_Type, dtype,
ndim, shape, strides, PyArray_DATA(out),
PyArray_FLAGS(out), NULL, (PyObject *)out);
@@ -184,10 +184,8 @@ conform_reduce_result(PyArrayObject *in, const npy_bool *axis_flags,
}
if (need_copy) {
- PyArrayObject *ret_copy;
-
- ret_copy = (PyArrayObject *)PyArray_NewLikeArray(
- (PyArrayObject *)ret, NPY_ANYORDER, NULL, 0);
+ PyArrayObject *ret_copy = (PyArrayObject *)PyArray_NewLikeArray(
+ (PyArrayObject *)ret, NPY_ANYORDER, NULL, 0);
if (ret_copy == NULL) {
Py_DECREF(ret);
return NULL;