I have the following fortran code:
SUBROUTINE MMUL(A,B,D,n)
C
INTEGER :: n
REAL, DIMENSION (n, n) :: A, B, D
C
CF2PY INTENT(IN) :: A
CF2PY INTENT(IN) :: B
CF2PY INTENT(IN) :: n
CF2PY INTENT(OUT) :: D
D = MATMUL(A, B)
END
It says this code takes two 1D arrays (i.e. vectors) and returns dot product between these vectors. I need to wrap it into my python script. I use smth like this:
f2py.compile(fsqrtmatmul.encode(), modulename='fsqrtmatmul', verbose=0)
import fsqrtmatmul
res = fsqrtmatmul.mmul([[1., 2.0]], [[2., 1.]])
But it doesn't work:
fsqrtmatmul.error: failed in converting 2nd argument `b' of fsqrtmatmul.mmul to C/Fortran array
How to fix it?
Your description is wrong.
A
andB
are arraysn x n
and it clearly computes their matrix product.