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

Viewed 999

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.

0 Answers
Related