How to use the numba.njit function in numba

To help you get started, we’ve selected a few numba examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lmcinnes / umap / umap / sparse_nndescent.py View on Github external
@numba.njit()
def sparse_init_from_random(
    n_neighbors,
    inds,
    indptr,
    data,
    query_inds,
    query_indptr,
    query_data,
    heap,
    rng_state,
    sparse_dist,
    dist_args,
):
    for i in range(query_indptr.shape[0] - 1):
        indices = rejection_sample(n_neighbors, indptr.shape[0] - 1, rng_state)
github lmcinnes / umap / umap / sparse.py View on Github external
@numba.njit()
def sparse_diff(ind1, data1, ind2, data2):
    return sparse_sum(ind1, data1, ind2, -data2)
github MrMinimal64 / timezonefinder / timezonefinder / helpers_numba.py View on Github external
@njit(dtype_2int_tuple(f8, f8), cache=True)
def coord2shortcut(lng, lat):
    return int(floor((lng + 180))), int(floor((90 - lat) * 2))
github MrMinimal64 / timezonefinder / timezonefinder / helpers_numba.py View on Github external
@njit(f8(f8, f8, i4, i4[:, :]), cache=True)
def distance_to_polygon(lng_rad, lat_rad, nr_points, points):
    min_distance = MAX_HAVERSINE_DISTANCE

    for i in range(nr_points):
        min_distance = min(min_distance, haversine(lng_rad, lat_rad, radians(int2coord(points[0][i])),
                                                   radians(int2coord(points[1][i]))))
    return min_distance
github theislab / scanpy / scanpy / neighbors / umap / sparse.py View on Github external
@numba.njit()
def sparse_rogers_tanimoto(ind1, data1, ind2, data2, n_features):
    num_true_true = arr_intersect(ind1, ind2).shape[0]
    num_non_zero = arr_union(ind1, ind2).shape[0]
    num_not_equal = num_non_zero - num_true_true

    return (2.0 * num_not_equal) / (n_features + num_not_equal)
github johannfaouzi / pyts / pyts / classification / learning_shapelets.py View on Github external
@njit()
def _reshape_list_shapelets(shapelets, lengths):
    """Reshape shapelets from a 1D-array to a list of 2D-arrays."""
    shapelets_reshaped = []
    start = 0
    for length in lengths:
        n_shapelets = length.size
        length_ = length[0]
        end = start + n_shapelets * length_
        shapelets_reshaped.append(shapelets[start: end].reshape(-1, length_))
        start = end
    return shapelets_reshaped
github mir-group / flare / flare / kernels.py View on Github external
@njit
def triplet_force_en_kernel(ci1, ci2, ri1, ri2, ri3, rj1, rj2, rj3,
                            fi, fj, fdi, ls1, ls2, sig2):
    r11 = ri1-rj1
    r12 = ri1-rj2
    r13 = ri1-rj3
    r21 = ri2-rj1
    r22 = ri2-rj2
    r23 = ri2-rj3
    r31 = ri3-rj1
    r32 = ri3-rj2
    r33 = ri3-rj3

    I1 = three_body_en_helper(ci1, ci2, r11, r22, r33, fi, fj,
                              fdi, ls1, ls2, sig2)
    I2 = three_body_en_helper(ci1, ci2, r13, r21, r32, fi, fj,
                              fdi, ls1, ls2, sig2)
github mir-group / flare / flare / kernels.py View on Github external
@njit
def triplet_kernel(ci1, ci2, cj1, cj2, ri1, ri2, ri3, rj1, rj2, rj3, fi, fj,
                   fdi, fdj, ls1, ls2, ls3, sig2):
    r11 = ri1-rj1
    r12 = ri1-rj2
    r13 = ri1-rj3
    r21 = ri2-rj1
    r22 = ri2-rj2
    r23 = ri2-rj3
    r31 = ri3-rj1
    r32 = ri3-rj2
    r33 = ri3-rj3

    # sum over all six permutations
    M1 = three_body_helper_1(ci1, ci2, cj1, cj2, r11, r22, r33, fi, fj, fdi,
                             fdj, ls1, ls2, ls3, sig2)
    M2 = three_body_helper_2(ci2, ci1, cj2, cj1, r21, r13, r32, fi, fj, fdi,
github masus04 / Deep-Reinforcement-Learning-for-Boardgames / TicTacToe / environment / board.py View on Github external
@njit
def __in_bounds__(position, board_size):
    for p in position:
        if not (p >= 0 and p < board_size):
            return False
    return True
github numba / numba / numba / typed / typeddict.py View on Github external
@njit
def _iter(d):
    return list(d.keys())