3 ms·
This is the problem that Numba was designed to solve. https://numba.readthedocs.io/en/stable/user/5minguide.html https://numba.readthedocs.io/en/stable/user/5m
by nerpderp82 3y ago
This is the problem that Numba was designed to solve.
https://numba.readthedocs.io/en/stable/user/5minguide.html https://numba.readthedocs.io/en/stable/user/5minguide.html
- cl3misch 3y agoNo. The problem in this post can be vectorized (== expressed as array OPs) with idiomatic numpy, making it very fast (see sibling comment). Numba is designed to speed up code where looping is unavoidable, i.e. the code can't be (easily) expressed as array OPs.
- GeompMankle 3y agoNegative again, a series of array operations which are individually idiomatic numpy like this will run very very fast in numba as it can coalesce the ops into a single pass through memory. Numpy can't do this and has to pass through the array for each individually array operation. There's nothing wrong with straight numpy but if you want it compiled-C fast for the whole ensemble of array ops, you need a JIT.
- cl3misch 3y agoAh, I was under the impression that using array OPs inside a numba njit gave worse performance. Has this changed, or is my memory tricking me? Do you have a source for this? I have not seen it in the numba docs.
- physicsguy 3y agoNumba replaces ops with LLVM byte code equivalent so the compiler will optimise out and coalesce the operations as part of the optimisation stage. If you want to look at the sort of things compilers do though, take a look at “common subexpression elimination”