f2py 无法转换为 C/Fortran 数组

问题描述 投票:0回答:0

我尝试为 Python 编写 Fortran 包装器并获得了

failed in converting hidden c of test.wrap to C/Fortran array
。我可以知道如何解决吗?这是
python
部分

import test
import numpy as np


A = np.random.random((5,5))
B = np.random.random((5,5))
C = np.zeros((5, 5))

A = np.asfortranarray(A)
B = np.asfortranarray(B)
C = np.asfortranarray(C)

test.wrap(A, B)
print(C[0,0])

这里是

Fortran
部分,叫做
test.f90
。我用了
python -m numpy.f2py -c  --f90flags='-O3'  -m test test.f90
.

subroutine wrap(A, B, C)
    implicit none
    real, intent(in) :: A(:, :), B(:, :)
    real, intent(out) :: C(:, :)
    integer :: m, n, p

    m = size(A, 1)
    n = size(A, 2)
    p = size(B, 2)
    
    if (n /= size(B, 1)) then
        print *, "Error: Incompatible dimensions for matrix multiplication"
        return
    end if

    C = matmul(A, B)
end 
python fortran f2py
© www.soinside.com 2019 - 2024. All rights reserved.