FIX: ensuring contiguity of the buffers for BLAS call and returning a Numpy array

This commit is contained in:
David Menéndez Hurtado 2015-08-17 13:39:03 +02:00
parent fb77c00da7
commit 629e57257f
2 changed files with 201 additions and 155 deletions

View file

@ -80,7 +80,7 @@ def backprop_gradient_par(double[:,:] dL, double[:,:] L):
dL_dK[k, k] /= (2. * L[k, k])
return dL_dK
cdef void chol_backprop(int N, double[:, :] dL, double[:, :] L) nogil:
cdef void chol_backprop(int N, double[:, ::1] dL, double[:, ::1] L) nogil:
cdef int i, k, n
# DSYMV required constant arguments
@ -105,10 +105,10 @@ cdef void chol_backprop(int N, double[:, :] dL, double[:, :] L) nogil:
dL[k, k] -= cblas.ddot(&n, &dL[k + 1, k], &N, &L[k, k], &incx)
dL[k, k] /= (2.0 * L[k, k])
def backprop_gradient_par_c(np.ndarray[double, ndim=2] dL, np.ndarray[double, ndim=2] L):
def backprop_gradient_par_c(double[:, :] dL, double[:, :] L):
cdef double[:, ::1] dL_dK = np.tril(dL) # makes a copy, c-contig
cdef double[:, ::1] L_cont = np.ascontiguousarray(L)
cdef int N = L.shape[0]
with nogil:
chol_backprop(N, dL_dK, L)
return dL_dK
chol_backprop(N, dL_dK, L_cont)
return np.asarray(dL_dK)