SiLab-Bonn / pylandau

Simple Landau distribution definitions to be used in Python.
GNU Lesser General Public License v2.1
20 stars 4 forks source link

WIP: port pylandau to use Numba #24

Closed leloup314 closed 2 years ago

leloup314 commented 2 years ago

This PR ports the pylandau package from using Cython-extensions, generated from cpp source code, to architecture-specific, pre-compiled bytecode from pure Python scripts using Numbas Ahead-Of-Time (AOT) compilation capabilities.

All functionality has been ported already, just the package structure needs to be adapted and Numbas AOT API has to be integrated into the package setup.

Performance stays the same:

Cython-based (current) version:

In [8]: a = np.arange(0, 100, 0.01)

In [9]: %timeit pylandau.landau(a)
1.03 ms ± 19.6 µs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)

In [10]: %timeit pylandau.langau(a)
19.1 ms ± 15.3 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)

Numba-based version:

In [13]: a = np.arange(0, 100, 0.01)

In [14]: %timeit pylandau.landau(a)
1.02 ms ± 2.17 µs per loop (mean ± std. dev. of 7 runs, 1,000 loops each)

In [15]: %timeit pylandau.langau(a)
17.6 ms ± 24.4 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
leloup314 commented 2 years ago

Test are not expected to succeed due package structure / setup not working yet.

leloup314 commented 2 years ago

Related to https://github.com/SiLab-Bonn/beam_telescope_analysis/issues/20

leloup314 commented 2 years ago

@cbespin let's have a chat on how to integrate this

cbespin commented 2 years ago

Related to https://github.com/SiLab-Bonn/beam_telescope_analysis/issues/20

At least this is solve with today's release (coming to pypi tomorrow).

I am always down to get away from cython, we can discuss the details. Changes look good so far

leloup314 commented 2 years ago

Move development to new branch in this repo