gpt4 book ai didi

python - 我可以在带有子例程调用的子例程上使用 F2PY 吗?

转载 作者:太空狗 更新时间:2023-10-30 02:43:50 25 4
gpt4 key购买 nike

使用 F2PY 作为包装器,是否可以使用带有子程序调用的子程序?如果是这样,怎么做到的?

如果我不清楚,我的意思是这样的:

    SUBROUTINE average(a, b, out)

real a, b, out
cf2py intent(in) a, b
cf2py intent(out) out

call add(a, b, out)

out=out/2

END

添加子程序如下:

  subroutine add(a, b, out)

real a, b, out

out = a + b

return
end

尝试 f2py -c -m average average.f 并导入 python 我得到:

ImportError: ./average.so: undefined symbol: add_

此外,向第二个子例程添加意图并不能解决问题。

最佳答案

您需要在编译命令中包含包含add 的文件,例如

f2py -c -m average average.f add.f

您导入的共享库需要在导入时解析其引用,这意味着它们需要包含在库中或链接到库。您可以像这样将函数保存在单独的库中:

gfortran -shared -fPIC -o add.so add.f
f2py -c -m average average.f add.so

这将生成一个 python 模块,该模块本身不包含 add,但该函数将具有对 add.so 的运行时链接依赖性。

关于python - 我可以在带有子例程调用的子例程上使用 F2PY 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31949748/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com