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

0

2

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.

Eserine answered 5/6, 2020 at 3:18 Comment(3)
A quick glance and numba_scipy indicates that it has only added support for the scipy.special submodule. It looks like a pretty new (and experimental) addition.Puseyism
So basically numba is no good for sparse matrices?Eserine
All the solvers that I know of are implemented in C. Numba will not do anything to increase the performance of code that is already written in C. Even if the sparse matrices were valid numba types it wouldn't matter for this.Charioteer

© 2022 - 2025 — McMap. All rights reserved.