quemb.shared.helper.njit

quemb.shared.helper.njit(f=None, *, nogil, **kwargs)

Type-safe jit wrapper that caches the compiled function

With this jit wrapper, you can actually use static typing together with numba. The crucial declaration is that the decorated function’s interface is preserved, i.e. mapping Function to Function. Otherwise the following example would not raise a type error:

@numba.njit
def f(x: int) -> int:
    return x

f(2.0)   # No type error for numba < 0.68

While the same example, using this custom njit() would raise a type error. Since numba 0.68, numba.njit is typed itself and also raises the type error, but this wrapper is kept because it also sets cache=True by default.

Return type:

TypeVar(_Function, bound= Callable) | Callable[[TypeVar(_Function, bound= Callable)], TypeVar(_Function, bound= Callable)]