pylops icon indicating copy to clipboard operation
pylops copied to clipboard

Numba decorators

Open mrava87 opened this issue 7 years ago • 7 comments

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 avatar Jan 08 '19 20:01 mrava87

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

mrava87 avatar Mar 15 '19 06:03 mrava87

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

AhmedA1559 avatar Aug 05 '22 08:08 AhmedA1559

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

@AhmedA1559, do you have something specific in mind?

mrava87 avatar Aug 05 '22 08:08 mrava87

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.

AhmedA1559 avatar Aug 05 '22 12:08 AhmedA1559

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 :)

mrava87 avatar Aug 05 '22 12:08 mrava87

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

dikwickley avatar Feb 16 '23 05:02 dikwickley

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...)

mrava87 avatar Feb 16 '23 06:02 mrava87