20 lines
597 B
Cython
20 lines
597 B
Cython
|
import cython
|
||
|
cimport scipy.linalg.cython_blas as blas
|
||
|
import numpy as np
|
||
|
|
||
|
@cython.boundscheck(False)
|
||
|
@cython.wraparound(False)
|
||
|
def kron(double[:, ::1] a, double[:, ::1] b):
|
||
|
cdef int i = a.shape[0]
|
||
|
cdef int j = a.shape[1]
|
||
|
cdef int k = b.shape[0]
|
||
|
cdef int l = b.shape[1]
|
||
|
cdef int onei = 1
|
||
|
cdef double oned = 1
|
||
|
cdef int m, n
|
||
|
result = np.zeros((i*k, j*l), float)
|
||
|
cdef double[:, ::1] result_v = result
|
||
|
for n in range(i):
|
||
|
for m in range(k):
|
||
|
blas.dger(&l, &j, &oned, &b[m, 0], &onei, &a[n, 0], &onei, &result_v[m+k*n, 0], &l)
|
||
|
return result
|