numba - Numba 缓存和迭代求解
问题描述
我正在尝试使用 NumbaLSODA(参见此处)来迭代地解决许多系统。但是,似乎我无法将该函数放入 numba 缓存中,因此每次迭代都有很大的开销。我想知道是否有人可以提供帮助。
这是我的代码。首先,我将所有与 numba 相关的函数放在一个文件中
numba_func.py
NOPYTHON = True
CACHE = True
PARALLEL = True
@nb.cfunc(lsoda_sig, nopython=NOPYTHON, cache=CACHE)
def rhs(x, i, di, p):
di[0] = ...
di[1] = ...
di[2] = ...
funcptr = rhs.address
@nb.njit('(float64)(float64, float64, float64, int16)', nopython=NOPYTHON, parallel=PARALLEL, cache=CACHE)
def solve(a, b, c, funcptr):
w0 = np.array([a, b, ...], dtype=np.float64)
p = np.array([c], dtype=np.float64)
x = np.linspace(0, 100, 500)
usol, success = lsoda(funcptr, w0, x, data=p)
return usol[-1][1]
然后我使用另一个文件一个接一个地解决系统
from numba_func import solve, funcptr
gs = []
for a, b, c in zip(as, bs, cs):
gs = np.append(gs, solve(a, b, c, funcptr))
我收到以下警告:
NumbaWarning: Cannot cache compiled function "solve" as it uses dynamic globals (such as ctypes pointers and large global arrays)
我想这个想法是正确传递变量 funcptr 以便 numba 很高兴但到目前为止我失败了......
解决方案
推荐阅读
- ios - 具有模拟器支持的核心图像着色器语言转换为金属
- r - 在 R 中将 mp4 文件转换为 wav 或 mp3 文件
- npm - 使用 npm 链接时,无法从另一个模块或领域使用 GraphQLSchema “[object GraphQLSchema]”
- iis - IIS 中的 Asp.Net MVC 核心应用程序 Windows 身份验证
- sql-server - 如何将 List(of String) 写入 SQL Server 表中,其中每个字符串都是逗号分隔的值列表
- html - CSS 通配符选择器 - 没有覆盖?
- python - 如何将两个文本文档与 tfidf 矢量化器进行比较?
- java - 为什么当我已经拥有 BufferReader 对象时,它要求我用 try catch 包围它?
- c# - 按下触发器时未注册
- c# - Discord.NET Kick Command