Calmcode - numba: types

Types

1 2 3 4 5 6

Numba has an interesting way to define function signatures.

from numba import float64

float64[:, :](float64[:, :], float64[:, :])

You can pass the signature to njit.

@nb.njit(float64[:, :](float64[:, :], float64[:, :]), parallel=True, fastmath=True)
def hypot_t(x, y):
    return (x**2 + y**2)**0.5

Adding types will make the function even faster.

%timeit hypot_t(r1, r2)