douglas1997
V2EX  ›  问与答

f2py 将 C 语言编译成 so 文件后运行对输入是不是很敏感呢?

  •  
  •   douglas1997 · Jan 4, 2020 · 1274 views
    This topic created in 2417 days ago, the information mentioned may be changed or developed.

    流程是这样的:

    1. 先写了一个 C 语言函数,接受的都是指针形式的输入( 2 个 int 类型的指针)
    2. 然后写了一个 f2py 的脚本,将 C 语言函数编译成 python 能 import 的库
    3. 在 python 中运行这个库,在少量数据的情况下( 10x512x512 int )的情况下正常,在大量输入的情况下 segmentation fault ( 100x512x512 )

    这是因为 f2py 打包的问题还是因为 C 代码本身的问题呢,静态语言检查要爆炸了。。= =

    将 C 语言运行前几行直接 return 0,发现还是会 segmentation fault,不知道是为啥了,f2py 脚本如下

    python module region_growing
    interface
        subroutine grow(m, n, p, img, seg, si, sj, sk, t)
            intent(c) grow
            intent(c)
    
            integer intent(hide), depend(img) :: m = shape(img,0)
            integer intent(hide), depend(img) :: n = shape(img,1)
            integer intent(hide), depend(img) :: p = shape(img,2)
    
            integer intent(in)                           :: img(m,n,p)
            integer(kind=1) intent(in)              :: seg(m,n,p)
            integer intent(in)                           :: si, sj, sk, t
        end subroutine grow
    end interface
    end python module region_growing
    
    2 replies    2020-01-04 16:27:59 +08:00
    douglas1997
        1
    douglas1997  
    OP
       Jan 4, 2020
    但是其实输入本质上是差不多的,我个人感觉更多的可能是 C 语言的 bug,而不是 f2py 的问题。
    douglas1997
        2
    douglas1997  
    OP
       Jan 4, 2020 via iPhone
    解决了,是因为栈空间不足导致的。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5617 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 38ms · UTC 09:03 · PVG 17:03 · LAX 02:03 · JFK 05:03
    ♥ Do have faith in what you're doing.