-
It seems that shape of an array forces numba to recompile. In my case it makes arrays useless to use with numba. import numpy as np
import awkward as ak
import numba as nb
from timeit import timeit
@nb.njit
def test(arr):
return
if __name__ == "__main__":
a1 = ak.Array([1, 2])
a2 = ak.Array([1, 2, 3])
a3 = ak.Array([1, 2, 3, 4])
t = timeit("test(a1[np.newaxis])", number=1, globals=globals())
print(f"{t*1000:.2f} ms")
t = timeit("test(a1[np.newaxis])", number=1, globals=globals())
print(f"{t*1000:.2f} ms")
t = timeit("test(a2[np.newaxis])", number=1, globals=globals())
print(f"{t*1000:.2f} ms")
t = timeit("test(a2[np.newaxis])", number=1, globals=globals())
print(f"{t*1000:.2f} ms")
t = timeit("test(a3[np.newaxis])", number=1, globals=globals())
print(f"{t*1000:.2f} ms")
t = timeit("test(a3[np.newaxis])", number=1, globals=globals())
print(f"{t*1000:.2f} ms")
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Regular dimensions in Awkward (if your type has In this case, your In general, this should only matter if the regular sizes of your array are changing between compiles. Usually that doesn't make sense; it's often a user error, but if it is needed in this case, then |
Beta Was this translation helpful? Give feedback.
Regular dimensions in Awkward (if your type has
... * N * ...
, you have a regular dimension) include the shape information in theirtype
. I believe that Numba does this differently for native NumPy arrays; the shape metadata is runtime-only. We have discussed this here before, and the decision at the time was "this is a compromise": #1343In this case, your
np.newaxis
inserts a new regular axis ataxis=0, meaning that your innermost shape changes with the list length. If you make that extra dimension ragged, e.g. with
ak.from_regular(..., axis=...), then you will end up with an array whose Numba type (you can see this via
array.numba_type` ) does not change with its length.In general, th…