python-3.x - 如何使用 Numba 加速 scipy.sparse.linalg 中提供的 Python 中的稀疏线性系统求解器?
问题描述
我希望使用 Numba 加速我的代码中的稀疏系统求解器部分。这是我到目前为止所拥有的:
# Both numba and numba-scipy packages are installed. I am using PyCharm IDE
import numba
import numba_scipy
# import other required stuff
@numba.jit(nopython=True)
def solve_using_numba(A, b):
return sp.linalg.gmres(A, b)
# total = the number of points in the system
A = sp.lil_matrix((total, total), dtype=float)
# populate A with appropriate data
A = A.tocsc()
b = np.zeros((total, 1), dtype=float)
# populate b with appropriate data
y, exit_code = solve_using_numba(A, b)
# plot solution
这会引发错误
argument 0: cannot determine Numba type of <class 'scipy.sparse.csc.csc_matrix'>
在官方文档中,numba-scipy extends Numba to make it aware of SciPy.
但似乎在这里,numba 无法使用 scipy 稀疏矩阵类。我哪里出错了,我能做些什么来解决这个问题?
我只需要加速代码的稀疏系统解决方案部分,因为其他东西非常轻量级,比如接受几个用户输入、构建 A 和 b 矩阵以及绘制最终结果。
解决方案
推荐阅读
- php - 在 PHP 302 重定向期间无法在浏览器 URL 栏中保留地址
- java - 我一直在尝试将数据库日志导入 logstash,但我收到 SSL 错误
- python - 在 if 条件下 db.commit() 之后分配变量忽略
- ios - 适用于 iOS 14 的 Strongswan 密码设置
- python - 如何清除我的数据框中的所有数据,以便通过我的 for 循环进行下一次迭代它们是空的?
- jmeter - JMeter - Safari 中的移动客户端
- vb.net - 带循环的数字总和
- laravel - 如何验证电话号码和电子邮件地址
- python - TypeError:尝试在python中反转字典时'int'对象不可迭代
- php - Laravel:通过 Carbon 获取月份日期表