Skip to content

Commit 21ff0b0

Browse files
committed
STY: more explicit variable init
1 parent c92daef commit 21ff0b0

File tree

4 files changed

+25
-37
lines changed

4 files changed

+25
-37
lines changed

bottleneck/include/iterators.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ static inline void init_iter_one(iter *it, PyArrayObject *a, int axis) {
7474
* calling Py_DECREF(it.a_ravel) after you are done with the iterator.
7575
* See nanargmin for an example.
7676
*/
77-
static inline void
78-
init_iter_all(iter *it, PyArrayObject *a, int ravel, int anyorder) {
79-
int i, j = 0;
77+
static inline void init_iter_all(iter *it, PyArrayObject *a, int ravel, int anyorder) {
78+
int i = 0;
79+
int j = 0;
8080
const int ndim = PyArray_NDIM(a);
8181
const npy_intp *shape = PyArray_SHAPE(a);
8282
const npy_intp *strides = PyArray_STRIDES(a);
@@ -208,9 +208,9 @@ struct _iter2 {
208208
};
209209
typedef struct _iter2 iter2;
210210

211-
static inline void
212-
init_iter2(iter2 *it, PyArrayObject *a, PyObject *y, int axis) {
213-
int i, j = 0;
211+
static inline void init_iter2(iter2 *it, PyArrayObject *a, PyObject *y, int axis) {
212+
int i = 0;
213+
int j = 0;
214214
const int ndim = PyArray_NDIM(a);
215215
const npy_intp *shape = PyArray_SHAPE(a);
216216
const npy_intp *astrides = PyArray_STRIDES(a);
@@ -283,9 +283,9 @@ struct _iter3 {
283283
};
284284
typedef struct _iter3 iter3;
285285

286-
static inline void
287-
init_iter3(iter3 *it, PyArrayObject *a, PyObject *y, PyObject *z, int axis) {
288-
int i, j = 0;
286+
static inline void init_iter3(iter3 *it, PyArrayObject *a, PyObject *y, PyObject *z, int axis) {
287+
int i = 0;
288+
int j = 0;
289289
const int ndim = PyArray_NDIM(a);
290290
const npy_intp *shape = PyArray_SHAPE(a);
291291
const npy_intp *astrides = PyArray_STRIDES(a);

bottleneck/src/move_template.c

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,6 @@ MOVE_MAIN(move_median, 0)
613613
g = 0; \
614614
e = 1; \
615615
n = 1; \
616-
r = 0; \
617616
for (j = limit; j < INDEX; j++) { \
618617
aj = AX(dtype0, j); \
619618
if (!bn_isnan(aj)) { \
@@ -675,7 +674,6 @@ MOVE(move_rank, DTYPE0) {
675674
const npy_DTYPE0 ai = AI(DTYPE0);
676675
g = 0;
677676
e = 1;
678-
r = 0;
679677
for (j = 0; j < INDEX; j++) {
680678
const npy_DTYPE0 aj = AX(DTYPE0, j);
681679
if (ai > aj) {
@@ -699,7 +697,6 @@ MOVE(move_rank, DTYPE0) {
699697
const npy_DTYPE0 ai = AI(DTYPE0);
700698
g = 0;
701699
e = 1;
702-
r = 0;
703700
for (j = INDEX - window + 1; j < INDEX; j++) {
704701
const npy_DTYPE0 aj = AX(DTYPE0, j);
705702
if (ai > aj) {
@@ -863,13 +860,6 @@ mover(char * name,
863860
move_t move_int64,
864861
move_t move_int32,
865862
int has_ddof) {
866-
int mc;
867-
int window;
868-
int axis;
869-
int ddof;
870-
int dtype;
871-
int ndim;
872-
873863
Py_ssize_t length;
874864

875865
PyArrayObject *a;
@@ -903,13 +893,14 @@ mover(char * name,
903893
}
904894

905895
/* window */
906-
window = PyArray_PyIntAsInt(window_obj);
896+
int window = PyArray_PyIntAsInt(window_obj);
907897
if (error_converting(window)) {
908898
TYPE_ERR("`window` must be an integer");
909899
goto error;
910900
}
911901

912902
/* min_count */
903+
int mc;
913904
if (min_count_obj == Py_None) {
914905
mc = window;
915906
} else {
@@ -930,7 +921,7 @@ mover(char * name,
930921
}
931922
}
932923

933-
ndim = PyArray_NDIM(a);
924+
int ndim = PyArray_NDIM(a);
934925

935926
/* defend against 0d beings */
936927
if (ndim == 0) {
@@ -939,6 +930,7 @@ mover(char * name,
939930
}
940931

941932
/* defend against the axis of negativity */
933+
int axis;
942934
if (axis_obj == NULL) {
943935
axis = ndim - 1;
944936
} else {
@@ -962,6 +954,7 @@ mover(char * name,
962954
}
963955

964956
/* ddof */
957+
int ddof;
965958
if (ddof_obj == NULL) {
966959
ddof = 0;
967960
} else {
@@ -981,7 +974,7 @@ mover(char * name,
981974
goto error;
982975
}
983976

984-
dtype = PyArray_TYPE(a);
977+
int dtype = PyArray_TYPE(a);
985978

986979
if (dtype == NPY_float64) {
987980
y = move_float64(a, window, mc, axis, ddof);

bottleneck/src/nonreduce_axis_template.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ nonreducer_axis(char * name,
5050

5151
/* dtype = [['float64'], ['float32'], ['int64'], ['int32']] */
5252
NRA(partition, DTYPE0) {
53-
npy_intp j, k;
53+
npy_intp j = 0, k = 0;
5454
iter it;
5555

5656
a = (PyArrayObject *)PyArray_NewCopy(a, NPY_ANYORDER);
@@ -164,6 +164,7 @@ NRA_MAIN(partition, PARSE_PARTITION)
164164
/* dtype = [['float64', 'intp'], ['float32', 'intp'],
165165
['int64', 'intp'], ['int32', 'intp']] */
166166
NRA(argpartition, DTYPE0) {
167+
npy_intp i;
167168
PyObject *y = PyArray_EMPTY(PyArray_NDIM(a), PyArray_SHAPE(a), NPY_DTYPE1, 0);
168169
iter2 it;
169170
init_iter2(&it, a, y, axis);
@@ -180,8 +181,6 @@ NRA(argpartition, DTYPE0) {
180181
npy_intp j, l, r, k;
181182
k = n;
182183
WHILE {
183-
l = 0;
184-
r = LENGTH - 1;
185184
ARGPARTSORT(DTYPE0, DTYPE1)
186185
NEXT2
187186
}
@@ -414,7 +413,7 @@ parse_partition(PyObject * args,
414413
const Py_ssize_t nkwds = kwds == NULL ? 0 : PyDict_Size(kwds);
415414
if (nkwds) {
416415
int nkwds_found = 0;
417-
PyObject *tmp;
416+
PyObject *tmp = NULL;
418417
switch (nargs) {
419418
case 2:
420419
*n = PyTuple_GET_ITEM(args, 1);
@@ -485,7 +484,7 @@ parse_rankdata(PyObject * args,
485484
const Py_ssize_t nkwds = kwds == NULL ? 0 : PyDict_Size(kwds);
486485
if (nkwds) {
487486
int nkwds_found = 0;
488-
PyObject *tmp;
487+
PyObject *tmp = NULL;
489488
switch (nargs) {
490489
case 1:
491490
*a = PyTuple_GET_ITEM(args, 0);
@@ -547,7 +546,7 @@ parse_push(PyObject * args,
547546
const Py_ssize_t nkwds = kwds == NULL ? 0 : PyDict_Size(kwds);
548547
if (nkwds) {
549548
int nkwds_found = 0;
550-
PyObject *tmp;
549+
PyObject *tmp = NULL;
551550
switch (nargs) {
552551
case 2:
553552
*n = PyTuple_GET_ITEM(args, 1);
@@ -618,12 +617,11 @@ nonreducer_axis(char * name,
618617
nra_t nra_int64,
619618
nra_t nra_int32,
620619
parse_type parse) {
621-
int n;
620+
int n = -1;
622621
int axis;
623-
int dtype;
624622

625623
PyArrayObject *a;
626-
PyObject * y;
624+
PyObject * y = NULL;
627625

628626
PyObject *a_obj = NULL;
629627
PyObject *n_obj = NULL;
@@ -724,7 +722,7 @@ nonreducer_axis(char * name,
724722
}
725723
}
726724

727-
dtype = PyArray_TYPE(a);
725+
int dtype = PyArray_TYPE(a);
728726
if (dtype == NPY_float64) {
729727
y = nra_float64(a, axis, n);
730728
} else if (dtype == NPY_float32) {

bottleneck/src/nonreduce_template.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,8 @@ nonreducer(char * name,
206206
nr_t nr_int64,
207207
nr_t nr_int32,
208208
int inplace) {
209-
int dtype;
210-
double old, new;
211-
212-
PyArrayObject *a;
213-
PyObject * y;
209+
PyArrayObject *a = NULL;
210+
PyObject * y = NULL;
214211

215212
PyObject *a_obj = NULL;
216213
PyObject *old_obj = NULL;

0 commit comments

Comments
 (0)