Skip to content

Commit e39c4ef

Browse files
Merge pull request #544 from musicinmybrain/declarators
MRG: Cython: declare pointers one per line None of these declarations was incorrect, but Cython now warns about them. The developers are worried that people will write “cdef int* a, b” and think that “b” is an “int*” rather than an “int”. Reducing the number of warnings from Cython makes it easier to notice warnings that might represent real problems. See also https://groups.google.com/g/cython-users/c/MA8I1wmoT0Q for discussion.
2 parents e20152d + af9fc39 commit e39c4ef

File tree

9 files changed

+153
-49
lines changed

9 files changed

+153
-49
lines changed

nipy/algorithms/statistics/_quantile.pyx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ def _quantile(X, double ratio, int interp=False, int axis=0):
4848
Y : array
4949
Array of quantiles
5050
"""
51-
cdef double *x, *y
51+
cdef double *x
52+
cdef double *y
5253
cdef long int size, stride
5354
cdef np.flatiter itX, itY
5455

nipy/labs/bindings/array.pyx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ def array_get_block( A, size_t x0, size_t x1, size_t fX=1,
4242
size_t z0=0, size_t z1=0, size_t fZ=1,
4343
size_t t0=0, size_t t1=0, size_t fT=1 )
4444
"""
45-
cdef fff_array *a, *b
45+
cdef fff_array *a
46+
cdef fff_array *b
4647
cdef fff_array asub
4748
a = fff_array_fromPyArray(A)
4849
asub = fff_array_get_block(a, x0, x1, fX, y0, y1, fY, z0, z1, fZ, t0, t1, fT)
@@ -57,7 +58,9 @@ def array_add(A, B):
5758
"""
5859
C = A + B
5960
"""
60-
cdef fff_array *a, *b, *c
61+
cdef fff_array *a
62+
cdef fff_array *b
63+
cdef fff_array *c
6164

6265
a = fff_array_fromPyArray(A)
6366
b = fff_array_fromPyArray(B)
@@ -74,7 +77,9 @@ def array_mul(A, B):
7477
"""
7578
C = A * B
7679
"""
77-
cdef fff_array *a, *b, *c
80+
cdef fff_array *a
81+
cdef fff_array *b
82+
cdef fff_array *c
7883

7984
a = fff_array_fromPyArray(A)
8085
b = fff_array_fromPyArray(B)
@@ -91,7 +96,9 @@ def array_sub(A, B):
9196
"""
9297
C = A - B
9398
"""
94-
cdef fff_array *a, *b, *c
99+
cdef fff_array *a
100+
cdef fff_array *b
101+
cdef fff_array *c
95102

96103
a = fff_array_fromPyArray(A)
97104
b = fff_array_fromPyArray(B)
@@ -108,7 +115,9 @@ def array_div(A, B):
108115
"""
109116
C = A / B
110117
"""
111-
cdef fff_array *a, *b, *c
118+
cdef fff_array *a
119+
cdef fff_array *b
120+
cdef fff_array *c
112121

113122
a = fff_array_fromPyArray(A)
114123
b = fff_array_fromPyArray(B)

nipy/labs/bindings/linalg.pyx

Lines changed: 53 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ def vector_set(X, size_t i, double a):
105105
Set i-th element.
106106
vector_set(x, i, a)
107107
"""
108-
cdef fff_vector *x, *y
108+
cdef fff_vector *x
109+
cdef fff_vector *y
109110
x = fff_vector_fromPyArray(X)
110111
y = fff_vector_new(x.size)
111112
fff_vector_memcpy(y, x)
@@ -119,7 +120,8 @@ def vector_set_all(X, double a):
119120
Set to a constant value.
120121
vector_set_all(x, a)
121122
"""
122-
cdef fff_vector *x, *y
123+
cdef fff_vector *x
124+
cdef fff_vector *y
123125
x = fff_vector_fromPyArray(X)
124126
y = fff_vector_new(x.size)
125127
fff_vector_memcpy(y, x)
@@ -133,7 +135,8 @@ def vector_scale(X, double a):
133135
Multiply by a constant value.
134136
y = vector_scale(x, a)
135137
"""
136-
cdef fff_vector *x, *y
138+
cdef fff_vector *x
139+
cdef fff_vector *y
137140
x = fff_vector_fromPyArray(X)
138141
y = fff_vector_new(x.size)
139142
fff_vector_memcpy(y, x)
@@ -147,7 +150,8 @@ def vector_add_constant(X, double a):
147150
Add a constant value.
148151
y = vector_add_constant(x, a)
149152
"""
150-
cdef fff_vector *x, *y
153+
cdef fff_vector *x
154+
cdef fff_vector *y
151155
x = fff_vector_fromPyArray(X)
152156
y = fff_vector_new(x.size)
153157
fff_vector_memcpy(y, x)
@@ -161,7 +165,9 @@ def vector_add(X, Y):
161165
Add two vectors.
162166
z = vector_add(x, y)
163167
"""
164-
cdef fff_vector *x, *y, *z
168+
cdef fff_vector *x
169+
cdef fff_vector *y
170+
cdef fff_vector *z
165171
x = fff_vector_fromPyArray(X)
166172
y = fff_vector_fromPyArray(Y)
167173
z = fff_vector_new(x.size)
@@ -177,7 +183,9 @@ def vector_sub(X, Y):
177183
Subtract two vectors: x - y
178184
z = vector_sub(x, y)
179185
"""
180-
cdef fff_vector *x, *y, *z
186+
cdef fff_vector *x
187+
cdef fff_vector *y
188+
cdef fff_vector *z
181189
x = fff_vector_fromPyArray(X)
182190
y = fff_vector_fromPyArray(Y)
183191
z = fff_vector_new(x.size)
@@ -193,7 +201,9 @@ def vector_mul(X, Y):
193201
Element-wise multiplication.
194202
z = vector_mul(x, y)
195203
"""
196-
cdef fff_vector *x, *y, *z
204+
cdef fff_vector *x
205+
cdef fff_vector *y
206+
cdef fff_vector *z
197207
x = fff_vector_fromPyArray(X)
198208
y = fff_vector_fromPyArray(Y)
199209
z = fff_vector_new(x.size)
@@ -209,7 +219,9 @@ def vector_div(X, Y):
209219
Element-wise division.
210220
z = vector_div(x, y)
211221
"""
212-
cdef fff_vector *x, *y, *z
222+
cdef fff_vector *x
223+
cdef fff_vector *y
224+
cdef fff_vector *z
213225
x = fff_vector_fromPyArray(X)
214226
y = fff_vector_fromPyArray(Y)
215227
z = fff_vector_new(x.size)
@@ -300,7 +312,8 @@ def matrix_transpose(A):
300312
Transpose a matrix.
301313
B = matrix_transpose(A)
302314
"""
303-
cdef fff_matrix *a, *b
315+
cdef fff_matrix *a
316+
cdef fff_matrix *b
304317
a = fff_matrix_fromPyArray(A)
305318
b = fff_matrix_new(a.size2, a.size1)
306319
fff_matrix_transpose(b, a)
@@ -312,7 +325,9 @@ def matrix_add(A, B):
312325
"""
313326
C = matrix_add(A, B)
314327
"""
315-
cdef fff_matrix *a, *b, *c
328+
cdef fff_matrix *a
329+
cdef fff_matrix *b
330+
cdef fff_matrix *c
316331
a = fff_matrix_fromPyArray(A)
317332
b = fff_matrix_fromPyArray(B)
318333
c = fff_matrix_new(a.size1, a.size2)
@@ -368,13 +383,16 @@ def blas_dasum(X):
368383
return fff_blas_dasum(x)
369384

370385
def blas_ddot(X, Y):
371-
cdef fff_vector *x, *y
386+
cdef fff_vector *x
387+
cdef fff_vector *y
372388
x = fff_vector_fromPyArray(X)
373389
y = fff_vector_fromPyArray(Y)
374390
return fff_blas_ddot(x, y)
375391

376392
def blas_daxpy(double alpha, X, Y):
377-
cdef fff_vector *x, *y, *z
393+
cdef fff_vector *x
394+
cdef fff_vector *y
395+
cdef fff_vector *z
378396
x = fff_vector_fromPyArray(X)
379397
y = fff_vector_fromPyArray(Y)
380398
z = fff_vector_new(y.size)
@@ -384,7 +402,8 @@ def blas_daxpy(double alpha, X, Y):
384402
return Z
385403

386404
def blas_dscal(double alpha, X):
387-
cdef fff_vector *x, *y
405+
cdef fff_vector *x
406+
cdef fff_vector *y
388407
x = fff_vector_fromPyArray(X)
389408
y = fff_vector_new(x.size)
390409
fff_vector_memcpy(y, x)
@@ -403,7 +422,10 @@ def blas_dgemm(int TransA, int TransB, double alpha, A, B, double beta, C):
403422
beta C where op(A) = A, A^T, A^H for TransA = CblasNoTrans,
404423
CblasTrans, CblasConjTrans and similarly for the parameter TransB.
405424
"""
406-
cdef fff_matrix *a, *b, *c, *d
425+
cdef fff_matrix *a
426+
cdef fff_matrix *b
427+
cdef fff_matrix *c
428+
cdef fff_matrix *d
407429
a = fff_matrix_fromPyArray(A)
408430
b = fff_matrix_fromPyArray(B)
409431
c = fff_matrix_fromPyArray(C)
@@ -428,7 +450,10 @@ def blas_dsymm(int Side, int Uplo, double alpha, A, B, beta, C):
428450
when Uplo is CblasLower then the lower triangle and diagonal of A
429451
are used.
430452
"""
431-
cdef fff_matrix *a, *b, *c, *d
453+
cdef fff_matrix *a
454+
cdef fff_matrix *b
455+
cdef fff_matrix *c
456+
cdef fff_matrix *d
432457
a = fff_matrix_fromPyArray(A)
433458
b = fff_matrix_fromPyArray(B)
434459
c = fff_matrix_fromPyArray(C)
@@ -455,7 +480,9 @@ def blas_dtrmm(int Side, int Uplo, int TransA, int Diag, double alpha, A, B):
455480
diagonal elements of the matrix A are taken as unity and are not
456481
referenced.
457482
"""
458-
cdef fff_matrix *a, *b, *c
483+
cdef fff_matrix *a
484+
cdef fff_matrix *b
485+
cdef fff_matrix *c
459486
a = fff_matrix_fromPyArray(A)
460487
b = fff_matrix_fromPyArray(B)
461488
c = fff_matrix_new(a.size1, a.size2)
@@ -482,7 +509,9 @@ def blas_dtrsm(int Side, int Uplo, int TransA, int Diag, double alpha, A, B):
482509
CblasUnit then the diagonal elements of the matrix A are taken as
483510
unity and are not referenced.
484511
"""
485-
cdef fff_matrix *a, *b, *c
512+
cdef fff_matrix *a
513+
cdef fff_matrix *b
514+
cdef fff_matrix *c
486515
a = fff_matrix_fromPyArray(A)
487516
b = fff_matrix_fromPyArray(B)
488517
c = fff_matrix_new(a.size1, a.size2)
@@ -507,7 +536,9 @@ def blas_dsyrk(int Uplo, int Trans, double alpha, A, double beta, C):
507536
when Uplo is CblasLower then the lower triangle and diagonal of C
508537
are used.
509538
"""
510-
cdef fff_matrix *a, *c, *d
539+
cdef fff_matrix *a
540+
cdef fff_matrix *c
541+
cdef fff_matrix *d
511542
a = fff_matrix_fromPyArray(A)
512543
c = fff_matrix_fromPyArray(C)
513544
d = fff_matrix_new(a.size1, a.size2)
@@ -529,7 +560,10 @@ def blas_dsyr2k(int Uplo, int Trans, double alpha, A, B, double beta, C):
529560
and when Uplo is CblasLower then the lower triangle and diagonal of C
530561
are used.
531562
"""
532-
cdef fff_matrix *a, *b, *c, *d
563+
cdef fff_matrix *a
564+
cdef fff_matrix *b
565+
cdef fff_matrix *c
566+
cdef fff_matrix *d
533567
a = fff_matrix_fromPyArray(A)
534568
b = fff_matrix_fromPyArray(B)
535569
c = fff_matrix_fromPyArray(C)

nipy/labs/bindings/wrapper.pyx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ def pass_vector(ndarray X):
6262
"""
6363
Y = pass_vector(X)
6464
"""
65-
cdef fff_vector *x, *y
65+
cdef fff_vector *x
66+
cdef fff_vector *y
6667
x = fff_vector_fromPyArray(X)
6768
y = fff_vector_new(x.size)
6869
fff_vector_memcpy(y, x)
@@ -105,7 +106,8 @@ def pass_matrix(ndarray X):
105106
"""
106107
Y = pass_matrix(X)
107108
"""
108-
cdef fff_matrix *x, *y
109+
cdef fff_matrix *x
110+
cdef fff_matrix *y
109111
x = fff_matrix_fromPyArray(X)
110112
y = fff_matrix_new(x.size1, x.size2)
111113
fff_matrix_memcpy(y, x)
@@ -117,7 +119,8 @@ def pass_array(ndarray X):
117119
"""
118120
Y = pass_array(X)
119121
"""
120-
cdef fff_array *x, *y
122+
cdef fff_array *x
123+
cdef fff_array *y
121124
x = fff_array_fromPyArray(X)
122125
y = fff_array_new(x.datatype, x.dimX, x.dimY, x.dimZ, x.dimT)
123126
fff_array_copy(y, x)
@@ -129,7 +132,9 @@ def pass_vector_via_iterator(ndarray X, int axis=0, int niters=0):
129132
"""
130133
Y = pass_vector_via_iterator(X, axis=0, niters=0)
131134
"""
132-
cdef fff_vector *x, *y, *z
135+
cdef fff_vector *x
136+
cdef fff_vector *y
137+
cdef fff_vector *z
133138
cdef fffpy_multi_iterator* multi
134139

135140
Xdum = X.copy() ## at least two arrays needed for multi iterator
@@ -152,7 +157,8 @@ def copy_via_iterators(ndarray Y, int axis=0):
152157
Copy array Y into Z via fff's PyArray_MultiIterAllButAxis C function.
153158
Behavior should be equivalent to Z = Y.copy().
154159
"""
155-
cdef fff_vector *y, *z
160+
cdef fff_vector *y
161+
cdef fff_vector *z
156162
cdef fffpy_multi_iterator* multi
157163

158164
# Allocate output array
@@ -184,7 +190,8 @@ def sum_via_iterators(ndarray Y, int axis=0):
184190
Return the sum of input elements along the dimension specified by axis.
185191
Behavior should be equivalent to Z = Y.sum(axis).
186192
"""
187-
cdef fff_vector *y, *z
193+
cdef fff_vector *y
194+
cdef fff_vector *z
188195
cdef fffpy_multi_iterator* multi
189196

190197
# Allocate output array

nipy/labs/glm/kalman.pyx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ def ols(ndarray Y, ndarray X, int axis=0):
8484
8585
REFERENCE: Roche et al, ISBI 2004.
8686
"""
87-
cdef fff_vector *y, *b, *s2
87+
cdef fff_vector *y
88+
cdef fff_vector *b
89+
cdef fff_vector *s2
8890
cdef fff_matrix *x
8991
cdef fff_glm_KF *kfilt
9092
cdef size_t p
@@ -161,7 +163,11 @@ def ar1(ndarray Y, ndarray X, int niter=2, int axis=0):
161163
REFERENCE:
162164
Roche et al, MICCAI 2004.
163165
"""
164-
cdef fff_vector *y, *b, *vb, *s2, *a
166+
cdef fff_vector *y
167+
cdef fff_vector *b
168+
cdef fff_vector *vb
169+
cdef fff_vector *s2
170+
cdef fff_vector *a
165171
cdef fff_vector Vb_flat
166172
cdef fff_matrix *x
167173
cdef fff_glm_RKF *rkfilt

nipy/labs/group/glm_twolevel.pyx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,12 @@ def em(ndarray Y, ndarray VY, ndarray X, ndarray C=None, int axis=0, int niter=D
6161
Keller and Roche, ISBI 2008.
6262
"""
6363
cdef size_t n, p
64-
cdef fff_vector *y, *vy, *b, *s2
65-
cdef fff_matrix *x, *ppx
64+
cdef fff_vector *y
65+
cdef fff_vector *vy
66+
cdef fff_vector *b
67+
cdef fff_vector *s2
68+
cdef fff_matrix *x
69+
cdef fff_matrix *ppx
6670
cdef fff_glm_twolevel_EM *em
6771
cdef fffpy_multi_iterator* multi
6872

@@ -131,7 +135,12 @@ def log_likelihood(Y, VY, X, B, S2, int axis=0):
131135
REFERENCE:
132136
Keller and Roche, ISBI 2008.
133137
"""
134-
cdef fff_vector *y, *vy, *b, *s2, *ll, *tmp
138+
cdef fff_vector *y
139+
cdef fff_vector *vy
140+
cdef fff_vector *b
141+
cdef fff_vector *s2
142+
cdef fff_vector *ll
143+
cdef fff_vector *tmp
135144
cdef fff_matrix *x
136145
cdef fffpy_multi_iterator* multi
137146

0 commit comments

Comments
 (0)