Skip to content

Cython: declare pointers one per line #544

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion nipy/algorithms/statistics/_quantile.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ def _quantile(X, double ratio, int interp=False, int axis=0):
Y : array
Array of quantiles
"""
cdef double *x, *y
cdef double *x
cdef double *y
cdef long int size, stride
cdef np.flatiter itX, itY

Expand Down
19 changes: 14 additions & 5 deletions nipy/labs/bindings/array.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ def array_get_block( A, size_t x0, size_t x1, size_t fX=1,
size_t z0=0, size_t z1=0, size_t fZ=1,
size_t t0=0, size_t t1=0, size_t fT=1 )
"""
cdef fff_array *a, *b
cdef fff_array *a
cdef fff_array *b
cdef fff_array asub
a = fff_array_fromPyArray(A)
asub = fff_array_get_block(a, x0, x1, fX, y0, y1, fY, z0, z1, fZ, t0, t1, fT)
Expand All @@ -57,7 +58,9 @@ def array_add(A, B):
"""
C = A + B
"""
cdef fff_array *a, *b, *c
cdef fff_array *a
cdef fff_array *b
cdef fff_array *c

a = fff_array_fromPyArray(A)
b = fff_array_fromPyArray(B)
Expand All @@ -74,7 +77,9 @@ def array_mul(A, B):
"""
C = A * B
"""
cdef fff_array *a, *b, *c
cdef fff_array *a
cdef fff_array *b
cdef fff_array *c

a = fff_array_fromPyArray(A)
b = fff_array_fromPyArray(B)
Expand All @@ -91,7 +96,9 @@ def array_sub(A, B):
"""
C = A - B
"""
cdef fff_array *a, *b, *c
cdef fff_array *a
cdef fff_array *b
cdef fff_array *c

a = fff_array_fromPyArray(A)
b = fff_array_fromPyArray(B)
Expand All @@ -108,7 +115,9 @@ def array_div(A, B):
"""
C = A / B
"""
cdef fff_array *a, *b, *c
cdef fff_array *a
cdef fff_array *b
cdef fff_array *c

a = fff_array_fromPyArray(A)
b = fff_array_fromPyArray(B)
Expand Down
72 changes: 53 additions & 19 deletions nipy/labs/bindings/linalg.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ def vector_set(X, size_t i, double a):
Set i-th element.
vector_set(x, i, a)
"""
cdef fff_vector *x, *y
cdef fff_vector *x
cdef fff_vector *y
x = fff_vector_fromPyArray(X)
y = fff_vector_new(x.size)
fff_vector_memcpy(y, x)
Expand All @@ -119,7 +120,8 @@ def vector_set_all(X, double a):
Set to a constant value.
vector_set_all(x, a)
"""
cdef fff_vector *x, *y
cdef fff_vector *x
cdef fff_vector *y
x = fff_vector_fromPyArray(X)
y = fff_vector_new(x.size)
fff_vector_memcpy(y, x)
Expand All @@ -133,7 +135,8 @@ def vector_scale(X, double a):
Multiply by a constant value.
y = vector_scale(x, a)
"""
cdef fff_vector *x, *y
cdef fff_vector *x
cdef fff_vector *y
x = fff_vector_fromPyArray(X)
y = fff_vector_new(x.size)
fff_vector_memcpy(y, x)
Expand All @@ -147,7 +150,8 @@ def vector_add_constant(X, double a):
Add a constant value.
y = vector_add_constant(x, a)
"""
cdef fff_vector *x, *y
cdef fff_vector *x
cdef fff_vector *y
x = fff_vector_fromPyArray(X)
y = fff_vector_new(x.size)
fff_vector_memcpy(y, x)
Expand All @@ -161,7 +165,9 @@ def vector_add(X, Y):
Add two vectors.
z = vector_add(x, y)
"""
cdef fff_vector *x, *y, *z
cdef fff_vector *x
cdef fff_vector *y
cdef fff_vector *z
x = fff_vector_fromPyArray(X)
y = fff_vector_fromPyArray(Y)
z = fff_vector_new(x.size)
Expand All @@ -177,7 +183,9 @@ def vector_sub(X, Y):
Substract two vectors: x - y
z = vector_sub(x, y)
"""
cdef fff_vector *x, *y, *z
cdef fff_vector *x
cdef fff_vector *y
cdef fff_vector *z
x = fff_vector_fromPyArray(X)
y = fff_vector_fromPyArray(Y)
z = fff_vector_new(x.size)
Expand All @@ -193,7 +201,9 @@ def vector_mul(X, Y):
Element-wise multiplication.
z = vector_mul(x, y)
"""
cdef fff_vector *x, *y, *z
cdef fff_vector *x
cdef fff_vector *y
cdef fff_vector *z
x = fff_vector_fromPyArray(X)
y = fff_vector_fromPyArray(Y)
z = fff_vector_new(x.size)
Expand All @@ -209,7 +219,9 @@ def vector_div(X, Y):
Element-wise division.
z = vector_div(x, y)
"""
cdef fff_vector *x, *y, *z
cdef fff_vector *x
cdef fff_vector *y
cdef fff_vector *z
x = fff_vector_fromPyArray(X)
y = fff_vector_fromPyArray(Y)
z = fff_vector_new(x.size)
Expand Down Expand Up @@ -300,7 +312,8 @@ def matrix_transpose(A):
Transpose a matrix.
B = matrix_transpose(A)
"""
cdef fff_matrix *a, *b
cdef fff_matrix *a
cdef fff_matrix *b
a = fff_matrix_fromPyArray(A)
b = fff_matrix_new(a.size2, a.size1)
fff_matrix_transpose(b, a)
Expand All @@ -312,7 +325,9 @@ def matrix_add(A, B):
"""
C = matrix_add(A, B)
"""
cdef fff_matrix *a, *b, *c
cdef fff_matrix *a
cdef fff_matrix *b
cdef fff_matrix *c
a = fff_matrix_fromPyArray(A)
b = fff_matrix_fromPyArray(B)
c = fff_matrix_new(a.size1, a.size2)
Expand Down Expand Up @@ -368,13 +383,16 @@ def blas_dasum(X):
return fff_blas_dasum(x)

def blas_ddot(X, Y):
cdef fff_vector *x, *y
cdef fff_vector *x
cdef fff_vector *y
x = fff_vector_fromPyArray(X)
y = fff_vector_fromPyArray(Y)
return fff_blas_ddot(x, y)

def blas_daxpy(double alpha, X, Y):
cdef fff_vector *x, *y, *z
cdef fff_vector *x
cdef fff_vector *y
cdef fff_vector *z
x = fff_vector_fromPyArray(X)
y = fff_vector_fromPyArray(Y)
z = fff_vector_new(y.size)
Expand All @@ -384,7 +402,8 @@ def blas_daxpy(double alpha, X, Y):
return Z

def blas_dscal(double alpha, X):
cdef fff_vector *x, *y
cdef fff_vector *x
cdef fff_vector *y
x = fff_vector_fromPyArray(X)
y = fff_vector_new(x.size)
fff_vector_memcpy(y, x)
Expand All @@ -403,7 +422,10 @@ def blas_dgemm(int TransA, int TransB, double alpha, A, B, double beta, C):
beta C where op(A) = A, A^T, A^H for TransA = CblasNoTrans,
CblasTrans, CblasConjTrans and similarly for the parameter TransB.
"""
cdef fff_matrix *a, *b, *c, *d
cdef fff_matrix *a
cdef fff_matrix *b
cdef fff_matrix *c
cdef fff_matrix *d
a = fff_matrix_fromPyArray(A)
b = fff_matrix_fromPyArray(B)
c = fff_matrix_fromPyArray(C)
Expand All @@ -428,7 +450,10 @@ def blas_dsymm(int Side, int Uplo, double alpha, A, B, beta, C):
when Uplo is CblasLower then the lower triangle and diagonal of A
are used.
"""
cdef fff_matrix *a, *b, *c, *d
cdef fff_matrix *a
cdef fff_matrix *b
cdef fff_matrix *c
cdef fff_matrix *d
a = fff_matrix_fromPyArray(A)
b = fff_matrix_fromPyArray(B)
c = fff_matrix_fromPyArray(C)
Expand All @@ -455,7 +480,9 @@ def blas_dtrmm(int Side, int Uplo, int TransA, int Diag, double alpha, A, B):
diagonal elements of the matrix A are taken as unity and are not
referenced.
"""
cdef fff_matrix *a, *b, *c
cdef fff_matrix *a
cdef fff_matrix *b
cdef fff_matrix *c
a = fff_matrix_fromPyArray(A)
b = fff_matrix_fromPyArray(B)
c = fff_matrix_new(a.size1, a.size2)
Expand All @@ -482,7 +509,9 @@ def blas_dtrsm(int Side, int Uplo, int TransA, int Diag, double alpha, A, B):
CblasUnit then the diagonal elements of the matrix A are taken as
unity and are not referenced.
"""
cdef fff_matrix *a, *b, *c
cdef fff_matrix *a
cdef fff_matrix *b
cdef fff_matrix *c
a = fff_matrix_fromPyArray(A)
b = fff_matrix_fromPyArray(B)
c = fff_matrix_new(a.size1, a.size2)
Expand All @@ -507,7 +536,9 @@ def blas_dsyrk(int Uplo, int Trans, double alpha, A, double beta, C):
when Uplo is CblasLower then the lower triangle and diagonal of C
are used.
"""
cdef fff_matrix *a, *c, *d
cdef fff_matrix *a
cdef fff_matrix *c
cdef fff_matrix *d
a = fff_matrix_fromPyArray(A)
c = fff_matrix_fromPyArray(C)
d = fff_matrix_new(a.size1, a.size2)
Expand All @@ -529,7 +560,10 @@ def blas_dsyr2k(int Uplo, int Trans, double alpha, A, B, double beta, C):
and when Uplo is CblasLower then the lower triangle and diagonal of C
are used.
"""
cdef fff_matrix *a, *b, *c, *d
cdef fff_matrix *a
cdef fff_matrix *b
cdef fff_matrix *c
cdef fff_matrix *d
a = fff_matrix_fromPyArray(A)
b = fff_matrix_fromPyArray(B)
c = fff_matrix_fromPyArray(C)
Expand Down
19 changes: 13 additions & 6 deletions nipy/labs/bindings/wrapper.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ def pass_vector(ndarray X):
"""
Y = pass_vector(X)
"""
cdef fff_vector *x, *y
cdef fff_vector *x
cdef fff_vector *y
x = fff_vector_fromPyArray(X)
y = fff_vector_new(x.size)
fff_vector_memcpy(y, x)
Expand Down Expand Up @@ -105,7 +106,8 @@ def pass_matrix(ndarray X):
"""
Y = pass_matrix(X)
"""
cdef fff_matrix *x, *y
cdef fff_matrix *x
cdef fff_matrix *y
x = fff_matrix_fromPyArray(X)
y = fff_matrix_new(x.size1, x.size2)
fff_matrix_memcpy(y, x)
Expand All @@ -117,7 +119,8 @@ def pass_array(ndarray X):
"""
Y = pass_array(X)
"""
cdef fff_array *x, *y
cdef fff_array *x
cdef fff_array *y
x = fff_array_fromPyArray(X)
y = fff_array_new(x.datatype, x.dimX, x.dimY, x.dimZ, x.dimT)
fff_array_copy(y, x)
Expand All @@ -129,7 +132,9 @@ def pass_vector_via_iterator(ndarray X, int axis=0, int niters=0):
"""
Y = pass_vector_via_iterator(X, axis=0, niters=0)
"""
cdef fff_vector *x, *y, *z
cdef fff_vector *x
cdef fff_vector *y
cdef fff_vector *z
cdef fffpy_multi_iterator* multi

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

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

# Allocate output array
Expand Down
10 changes: 8 additions & 2 deletions nipy/labs/glm/kalman.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ def ols(ndarray Y, ndarray X, int axis=0):

REFERENCE: Roche et al, ISBI 2004.
"""
cdef fff_vector *y, *b, *s2
cdef fff_vector *y
cdef fff_vector *b
cdef fff_vector *s2
cdef fff_matrix *x
cdef fff_glm_KF *kfilt
cdef size_t p
Expand Down Expand Up @@ -161,7 +163,11 @@ def ar1(ndarray Y, ndarray X, int niter=2, int axis=0):
REFERENCE:
Roche et al, MICCAI 2004.
"""
cdef fff_vector *y, *b, *vb, *s2, *a
cdef fff_vector *y
cdef fff_vector *b
cdef fff_vector *vb
cdef fff_vector *s2
cdef fff_vector *a
cdef fff_vector Vb_flat
cdef fff_matrix *x
cdef fff_glm_RKF *rkfilt
Expand Down
15 changes: 12 additions & 3 deletions nipy/labs/group/glm_twolevel.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,12 @@ def em(ndarray Y, ndarray VY, ndarray X, ndarray C=None, int axis=0, int niter=D
Keller and Roche, ISBI 2008.
"""
cdef size_t n, p
cdef fff_vector *y, *vy, *b, *s2
cdef fff_matrix *x, *ppx
cdef fff_vector *y
cdef fff_vector *vy
cdef fff_vector *b
cdef fff_vector *s2
cdef fff_matrix *x
cdef fff_matrix *ppx
cdef fff_glm_twolevel_EM *em
cdef fffpy_multi_iterator* multi

Expand Down Expand Up @@ -131,7 +135,12 @@ def log_likelihood(Y, VY, X, B, S2, int axis=0):
REFERENCE:
Keller and Roche, ISBI 2008.
"""
cdef fff_vector *y, *vy, *b, *s2, *ll, *tmp
cdef fff_vector *y
cdef fff_vector *vy
cdef fff_vector *b
cdef fff_vector *s2
cdef fff_vector *ll
cdef fff_vector *tmp
cdef fff_matrix *x
cdef fffpy_multi_iterator* multi

Expand Down
Loading