Skip to content

Commit 069863a

Browse files
committed
Fix const-ness of some functions for rate matrix code
this can refer to msmbuilder #1102 issue, and it can solve the problems when using cython>=0.28 and build msmbuilder using python>=3.7
1 parent 36c2478 commit 069863a

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

msmbuilder/msm/_ratematrix.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ cpdef double dK_dtheta_ij(const double[::1] theta, npy_intp n, npy_intp u,
216216

217217

218218
cpdef int dK_dtheta_u(const double[::1] theta, npy_intp n, npy_intp i,
219-
npy_intp j, double[:] out, double[:, :] A=None,
219+
npy_intp j, double[:] out, const double[:, :] A=None,
220220
double[:] out2=None) nogil:
221221
r"""
222222
Compute :math:`dK_ij / dtheta_u` over all `u` for fixed (`i`, `j`).

msmbuilder/msm/_ratematrix_support.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ cdef int hadamard_X(const double[::1] w, const double[::1] expwt, double t,
102102
A[i, j] *= t * expwt[i]
103103

104104

105-
cdef int hadamard_inplace(const double[:, ::1] A, const double[:, ::1] B) nogil:
105+
cdef int hadamard_inplace(double[:, ::1] A, const double[:, ::1] B) nogil:
106106
"""Overwrite the matrix A by its element-wise product with matrix B
107107
"""
108108
if (A.shape[0] != B.shape[0]) or (A.shape[1] != B.shape[1]):

msmbuilder/src/cy_blas.pyx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ cdef extern from "f2py/f2pyptr.h":
4242
void *f2py_pointer(object) except NULL
4343

4444
ctypedef double d
45-
ctypedef int dgemm_t(char *transa, char *transb, int *m, int *n, int *k, d *alpha, d *a,
46-
int *lda, d *b, int *ldb, d *beta, d *c, int *ldc) nogil
47-
ctypedef int dgemv_t(char *transa, int *m, int *n, d *alpha, d *a,
48-
int *lda, d *x, int *incx, d *beta, d *y, int *incy) nogil
49-
ctypedef d ddot_t(int *n, d *dx, int *incx, d *dy, int *incy) nogil
50-
ctypedef d dnrm2_t(int *n, d *x, int *incx) nogil
51-
ctypedef int daxpy_t(int *n, d *alpha, d *x, int *incx, d *y, int *incy) nogil
45+
ctypedef int dgemm_t(char *transa, char *transb, int *m, int *n, int *k, d *alpha, const d *a,
46+
int *lda, const d *b, int *ldb, d *beta, d *c, int *ldc) nogil
47+
ctypedef int dgemv_t(char *transa, int *m, int *n, d *alpha, const d *a,
48+
int *lda, const d *x, int *incx, d *beta, d *y, int *incy) nogil
49+
ctypedef d ddot_t(int *n, const d *dx, int *incx, const d *dy, int *incy) nogil
50+
ctypedef d dnrm2_t(int *n, const d *x, int *incx) nogil
51+
ctypedef int daxpy_t(int *n, const d *alpha, const d *x, int *incx, d *y, int *incy) nogil
5252
ctypedef int dger_t(int *n, int *m, d *alpha, d *x, int *incx, d *y, int *incy, d *a, int *lda) nogil
5353

5454
cdef dgemm_t *FORTRAN_DGEMM = <dgemm_t*>f2py_pointer(blas.dgemm._cpointer)
@@ -60,7 +60,7 @@ cdef dger_t *FORTRAN_DGER = <dger_t*>f2py_pointer(blas.dger._cpointer)
6060

6161

6262
@cython.boundscheck(False)
63-
cdef inline int cdgemm_NN(double[:, ::1] a, double[:, ::1] b, double[:, ::1] c, double alpha=1.0, double beta=0.0) nogil:
63+
cdef inline int cdgemm_NN(const double[:, ::1] a, const double[:, ::1] b, double[:, ::1] c, double alpha=1.0, double beta=0.0) nogil:
6464
"""c = beta*c + alpha*dot(a, b)
6565
"""
6666
cdef int m, k, n
@@ -75,7 +75,7 @@ cdef inline int cdgemm_NN(double[:, ::1] a, double[:, ::1] b, double[:, ::1] c,
7575

7676

7777
@cython.boundscheck(False)
78-
cdef inline int cdgemm_NT(double[:, ::1] a, double[:, ::1] b, double[:, ::1] c, double alpha=1.0, double beta=0.0) nogil:
78+
cdef inline int cdgemm_NT(const double[:, ::1] a, const double[:, ::1] b, double[:, ::1] c, double alpha=1.0, double beta=0.0) nogil:
7979
"""c = beta*c + alpha*dot(a, b.T)
8080
"""
8181
cdef int m, k, n
@@ -90,7 +90,7 @@ cdef inline int cdgemm_NT(double[:, ::1] a, double[:, ::1] b, double[:, ::1] c,
9090

9191

9292
@cython.boundscheck(False)
93-
cdef inline int cdgemm_TN(double[:, ::1] a, double[:, ::1] b, double[:, ::1] c, double alpha=1.0, double beta=0.0) nogil:
93+
cdef inline int cdgemm_TN(const double[:, ::1] a, const double[:, ::1] b, double[:, ::1] c, double alpha=1.0, double beta=0.0) nogil:
9494
"""c = beta*c + alpha*dot(a.T, b)
9595
"""
9696
cdef int m, k, n
@@ -105,7 +105,7 @@ cdef inline int cdgemm_TN(double[:, ::1] a, double[:, ::1] b, double[:, ::1] c,
105105

106106

107107
@cython.boundscheck(False)
108-
cdef int cdgemv_N(double[:, ::1] a, double[:] x, double[:] y, double alpha=1.0, double beta=0.0) nogil:
108+
cdef int cdgemv_N(const double[:, ::1] a, const double[:] x, double[:] y, double alpha=1.0, double beta=0.0) nogil:
109109
cdef int m, n, incx, incy
110110
m = a.shape[0]
111111
n = a.shape[1]
@@ -119,7 +119,7 @@ cdef int cdgemv_N(double[:, ::1] a, double[:] x, double[:] y, double alpha=1.0,
119119

120120

121121
@cython.boundscheck(False)
122-
cdef int cdgemv_T(double[:, ::1] a, double[:] x, double[:] y, double alpha=1.0, double beta=0.0) nogil:
122+
cdef int cdgemv_T(const double[:, ::1] a, const double[:] x, double[:] y, double alpha=1.0, double beta=0.0) nogil:
123123
cdef int m, n, incx, incy
124124
m = a.shape[1]
125125
n = a.shape[0]
@@ -133,7 +133,7 @@ cdef int cdgemv_T(double[:, ::1] a, double[:] x, double[:] y, double alpha=1.0,
133133

134134

135135
@cython.boundscheck(False)
136-
cdef int cddot(double[:] x, double[:] y, double *result) nogil:
136+
cdef int cddot(const double[:] x, const double[:] y, double *result) nogil:
137137
cdef int n, incx, incy
138138
n = x.shape[0]
139139
incx = x.strides[0] / sizeof(double)
@@ -154,7 +154,7 @@ cdef int cdnrm2(double[:] x, double* result) nogil:
154154

155155

156156
@cython.boundscheck(False)
157-
cdef int cdaxpy(double alpha, double[:] x, double[:] y) nogil:
157+
cdef int cdaxpy(double alpha, const double[:] x, double[:] y) nogil:
158158
cdef int n = x.shape[0]
159159
cdef int incx = x.strides[0] / sizeof(double)
160160
cdef int incy = y.strides[0] / sizeof(double)

0 commit comments

Comments
 (0)