How to use Numba to speed up sparse linear system solvers in Python that are provided in scipy.sparse.linalg?

别来无恙 提交于 2021-01-05 07:33:43

问题


I wish to speed up the sparse system solver part of my code using Numba. Here is what I have up till now:

# 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

This raises the error

argument 0: cannot determine Numba type of <class 'scipy.sparse.csc.csc_matrix'>   

In the official documentation, numba-scipy extends Numba to make it aware of SciPy. But it seems that here, numba cannot work with scipy sparse matrix classes. Where am I going wrong and what can I do to fix this?

I only need to speed up the sparse system solution part of the code because the other stuff is pretty lightweight like taking a couple of user inputs, constructing the A and b matrices, and plotting the end result.

来源:https://stackoverflow.com/questions/62207548/how-to-use-numba-to-speed-up-sparse-linear-system-solvers-in-python-that-are-pro

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!