numpy matmul_r8_avx2:失败.在增加维度与python f2py

lmyy7pcs  于 2023-05-07  发布在  Python
关注(0)|答案(1)|浏览(133)

我使用Fortran Package 器f2py。它以前使用n=5~30进行矩阵乘法(f2py failed in converting to C/Fortran array)。
当我增加到50时,它告诉我问题python: /home/rdonnelly/mc/conda-bld/compilers_linux-64_1534627447954/work/.build/x86_64-conda_cos6-linux-gnu/src/gcc/libgfortran/generated/matmul_r8.c:642: matmul_r8_avx2: Assertion((a)-〉dtype & 0x 07)== 2||((B)-〉dtype & 0x 07)== 2'失败。已中止(核心转储)。 下面是python部分test-f2py.py`

import numpy as np
import test

dim_n = 50
A = np.random.random((dim_n, dim_n))
B = np.random.random((dim_n, dim_n))
C = np.zeros((dim_n, dim_n))

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

test.wrap(A, B, C)
print("Fortran result:")
#print(C)

# Cross-check with numpy.einsum
C_check = np.einsum('ij,jk->ik', A, B)
print("Numpy einsum result:")
#print(C_check)

# Compare the two results
print("Are the results equal?")
print(np.allclose(C, C_check))

fortran部分,test.f90,由python -m numpy.f2py -c --f90flags='-O3' -m test test.f90运行

!f2py dp selected_real_kind(15, 307)
subroutine wrap(A, B, C)
    real(kind=8), intent(in) :: A(:, :), B(:, :)
    real(kind=8), intent(inout) :: 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 subroutine wrap

如果我运行python代码,例如python test-f2py.py,我得到

python: /home/rdonnelly/mc/conda-bld/compilers_linux-64_1534627447954/work/.build/x86_64-conda_cos6-linux-gnu/src/gcc/libgfortran/generated/matmul_r8.c:642: matmul_r8_avx2: Assertion `((a)->dtype & 0x07) == 2 || ((b)->dtype & 0x07) == 2' failed.
Aborted (core dumped)
i34xakig

i34xakig1#

升级numpygfortran没有帮助。我想出了一个散步。如果我使用f2py而不是numpy.f2py,它会告诉我

/usr/include/python3.8/pyconfig.h:3:12: fatal error: x86_64-linux-gnu/python3.8/pyconfig.h: No such file or directory  #  include <x86_64-linux-gnu/python3.8/pyconfig.h>

然后我在coda中切换到python3.9env,它工作正常

相关问题