%%cython
cimport cython
import numpy as np
cimport openmp
from numpy.linalg import inv
from cython.parallel cimport prange
@cython.boundscheck(False)
@cython.wraparound(False)
def inv_unit_diagon_blocks(double[::1,:] A,double[::1,:] U,int m):
cdef n=int(len(A)/m)
cdef double[::1,:] Lambda=np.empty((A.shape[0],A.shape[1]))
cdef int i
A=A.reshape(A.shape[0]//n, n, A.shape[1]//n, n).swapaxes(1, 2).reshape(-1, n, n)
with nogil:
for i in prange(m*m, schedule='static'):
Lambda[i]=inv(U[i])@A[i]@U[i]
return Lambda
Error compiling Cython file:
------------------------------------------------------------
...
cdef double[::1,:] Lambda=np.empty((A.shape[0],A.shape[1]))
cdef int i
A=A.reshape(A.shape[0]//n, n, A.shape[1]//n, n).swapaxes(1, 2).reshape(-1, n, n)
with nogil:
for i in prange(m*m, schedule='static'):
Lambda[i]=inv(U[i])@A[i]@U[i]
^
------------------------------------------------------------
.ipython\cython\_cython_magic_f2335949c00c765c6ffad6f007548be3.pyx:15:36: Coercion from Python not allowed without the GIL
It gives this error probably cause I try to multiply the nxn matrices. Can somebody tell me how can I do that? How to multiply parallel m*m times the 2 matrices? I know that it can be done using prange but it needs gil to operate matrix mul and prange can only be used with nogil. Is there anyway to make it work?