f2py 将 C 语言编译成 so 文件后运行对输入是不是很敏感呢?
資深大佬 : douglas1997 53
流程是这样的:
- 先写了一个 C 语言函数,接受的都是指针形式的输入( 2 个 int 类型的指针)
- 然后写了一个 f2py 的脚本,将 C 语言函数编译成 python 能 import 的库
- 在 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)