[Numpy-discussion] Re: Function that searches arrays for the first element that satisfies a condition

2023-11-01 Thread Dom Grigonis
Ok, I think I didn’t do a full justice. So actually, numba is fairly fast, given everything is precompiled. Predicates still make things slower, but not as much as I initially thought. However, the way your code is structured, it has to re-compile both predicate and target function (with new pr

[Numpy-discussion] Re: Function that searches arrays for the first element that satisfies a condition

2023-11-01 Thread Dom Grigonis
Your comparisons do not paint correct picture. a) Most of time here is spent for array allocation and the actual time of the loop gets swallowed in the noise a) You do not test early stop - your benchmarks simply test full loop as condition is almost never hit - 5 standard deviations... Here is

[Numpy-discussion] Re: Function that searches arrays for the first element that satisfies a condition

2023-11-01 Thread Neal Becker
Thanks Juan, this is really great! I plan to make use of this right away. On Wed, Nov 1, 2023 at 8:13 AM Juan Nunez-Iglesias wrote: > Have you tried timing things? Thankfully this is easy to test because the > Python source of numba-jitted functions is available at jitted_func.py_func. > > In [

[Numpy-discussion] Re: Function that searches arrays for the first element that satisfies a condition

2023-11-01 Thread Juan Nunez-Iglesias
Have you tried timing things? Thankfully this is easy to test because the Python source of numba-jitted functions is available at jitted_func.py_func. In [23]: @numba.njit ...: def _first(arr, pred): ...: for i, elem in enumerate(arr): ...: if pred(elem): ...: