PyLops / pylops

PyLops – A Linear-Operator Library for Python
https://pylops.readthedocs.io
GNU Lesser General Public License v3.0
428 stars 102 forks source link

Numba decorators #23

Open mrava87 opened 5 years ago

mrava87 commented 5 years ago

Some of the main linear operators may get a speed-up by simply adding numba <http://numba.pydata.org>_ @jit decorators to _matvec and _rmatvec methods.

Others, such as FirstDerivative may be suited to stencil decorator.

Note: it may be enough to simply add numba to dependencies as it is a fairly common library but to keep dependencies to a minimum it may be better to implement private functions such as _matvec_serial and _matvec_numba and try importingnumba, always falling back to by _matvec_serial if that is not available in the python environment of the user.

mrava87 commented 5 years ago

Done for Spread operator (forward and adjoint). Follow that structure for future operator optimization

AhmedA1559 commented 2 years ago

Is this still a goal for some of the other operators?

mrava87 commented 2 years ago

Yes, as long as they show performance improvements over pure NumPy ones this is always welcome.

@AhmedA1559, do you have something specific in mind?

AhmedA1559 commented 2 years ago

Yes, as long as they show performance improvements over pure NumPy ones this is always welcome.

@AhmedA1559, do you have something specific in mind?

Yes. I was thinking of implementing Numba decorators for some of the dunder methods in the LinearOperator base class at first, if they yielded performance benefits with it.

mrava87 commented 2 years ago

Sounds good. My reccomandation is that anything that simply calls NumPy/Scipy routines will likely not yield much benefit. In cases where writing a for...loop is the only way to go, then Numba may help.

Please make sure to always compare pre and after Numba decoration as we will only accept to include changes where the performance gain is evident :)

dikwickley commented 1 year ago

@mrava87 do we still need to add this? I would like to work on this if it is still relevant.

mrava87 commented 1 year ago

Yes, still relevant. Read the comments above and do some digging of what methods you think may benefit from adding Numba decorators (which likely means you need to reimplement the matvec/rmatvec in a form that is Numba friendly more than Numpy friendly - eg with numpy you want to avoid for..loops as much as possible, with Numba you want them to allow Numba to parallelize if you use prange...)