I am using cython to do a rank one update of a rectangular matrix A. I cannot get dger to do the update as I want, so I've isolated it in a function:
from scipy.linalg.cython_blas cimport dger
cimport cython
def test_dger(double[:, :] A, double[:] x, double[:] y):
cdef int inc = 1
cdef double one = 1
cdef int n_= A.shape[0]
cdef int m = A.shape[1]
dger(&n, &m, &one, &x[0], &inc, &y[0], &inc, &A[0, 0], &n)
return np.array(A)
which compiles just fine. However, doing:
n = 3
m = 4
A = np.zeros([n, m])
y = np.arange(m, dtype=float)
x = np.array([1., 4, 0])
test_dger(A, x, y)
gives me
array([[ 0., 0., 0., 1.],
[ 4., 0., 2., 8.],
[ 0., 3., 12., 0.]])
which has the desired n by m shape, but the values in the wrong order. I assum C order vs fortran order has something to do with this, but I have not been able to solve the problem by myself.
The result I'm expecting is what would be given by
np.dot(x[:, None], y[None, :])
array([[ 0., 1., 2., 3.],
[ 0., 4., 8., 12.],
[ 0., 0., 0., 0.]])