How to use the numba.jit 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 bbfrederick / rapidtide / tide_funcs.py View on Github external
def resdec(f):
        if not numbaexists:
            return f
        return jit(f)
    return resdec
github jaantollander / crowddynamics / crowddynamics / core / agent / agent.py View on Github external
@numba.jit(UniTuple(f8[:, :], 3)(f8[:, :], f8[:], f8[:]), nopython=True, nogil=True)
def positions_vector(position, orientation, radius_ts):
    """Center and shoulder positions"""
    x = np.cos(orientation)
    y = np.sin(orientation)
    t = np.stack((y, -x), axis=1)
    offset = t * radius_ts
    position_ls = position - offset
    position_rs = position + offset
    return position, position_ls, position_rs
github MrMinimal64 / multivar_horner / multivar_horner / helpers_fcts_numba.py View on Github external
@jit(u4(u4[:, :]), nopython=True, cache=True)
def true_num_ops(exponent_matrix):
    """
    without counting additions (just MUL & POW) and but WITH considering the coefficients (1 MUL per monomial)
    """
    num_ops = 0
    for monomial_nr in range(exponent_matrix.shape[0]):
        for dim in range(exponent_matrix.shape[1]):
            exp = exponent_matrix[monomial_nr, dim]
            if exp > 0:
                # per scalar factor 1 MUL operation is required
                num_ops += 1
                if exp >= 2:
                    # for scalar factors with exponent >= 2 additionally 1 POW operation is required
                    num_ops += 1

    return num_ops
github Thierry-Dumont / BenchmarksPythonJuliaAndCo / Weno / Numba / GB.py View on Github external
@jit(float64(float64, float64),nopython=True)
def gb(X,Y):
    return Godunov.NumFlux(Burg,X,Y)
github TianxiaoHu / GomokuAgent / AI4.py View on Github external
@numba.jit(nopython=True,nogil=True)
def i_will_win(state, last_move, player):
    """ Return true if I will win next step if the opponent don't have 4-in-a-row.
    Winning Conditions:
        1. 5 in a row.
        2. 4 in a row with both end open. (free 4)
        3. 4 in a row with one missing stone x 2 (hard 4 x 2)
     """
    r, c = last_move
    # try all 4 directions, the other 4 is equivalent
    directions = [(1,1), (1,0), (0,1), (1,-1)]
    n_hard_4 = 0 # number of hard 4s found
    for dr, dc in directions:
        line_length = 1 # last_move
        # try to extend in the positive direction (max 4 times)
        ext_r = r
        ext_c = c
github ryanfwy / KCF-DSST-py / fhog.py View on Github external
@jit(cache=True)
def func2(dx, dy, boundary_x, boundary_y, r, alfa, nearest, w, k, height, width, sizeX, sizeY, p, stringSize):
    mapp = np.zeros((sizeX*sizeY*p), np.float32)
    for i in xrange(sizeY):
        for j in xrange(sizeX):
            for ii in xrange(k):
                for jj in xrange(k):
                    if((i * k + ii > 0) and (i * k + ii < height - 1) and (j * k + jj > 0) and (j * k + jj < width  - 1)):
                        mapp[i*stringSize + j*p + alfa[k*i+ii,j*k+jj,0]] +=  r[k*i+ii,j*k+jj] * w[ii,0] * w[jj,0]
                        mapp[i*stringSize + j*p + alfa[k*i+ii,j*k+jj,1] + NUM_SECTOR] +=  r[k*i+ii,j*k+jj] * w[ii,0] * w[jj,0]
                        if((i + nearest[ii] >= 0) and (i + nearest[ii] <= sizeY - 1)):
                            mapp[(i+nearest[ii])*stringSize + j*p + alfa[k*i+ii,j*k+jj,0]] += r[k*i+ii,j*k+jj] * w[ii,1] * w[jj,0]
                            mapp[(i+nearest[ii])*stringSize + j*p + alfa[k*i+ii,j*k+jj,1] + NUM_SECTOR] += r[k*i+ii,j*k+jj] * w[ii,1] * w[jj,0]
                        if((j + nearest[jj] >= 0) and (j + nearest[jj] <= sizeX - 1)):
                            mapp[i*stringSize + (j+nearest[jj])*p + alfa[k*i+ii,j*k+jj,0]] += r[k*i+ii,j*k+jj] * w[ii,0] * w[jj,1]
                            mapp[i*stringSize + (j+nearest[jj])*p + alfa[k*i+ii,j*k+jj,1] + NUM_SECTOR] += r[k*i+ii,j*k+jj] * w[ii,0] * w[jj,1]
                        if((i + nearest[ii] >= 0) and (i + nearest[ii] <= sizeY - 1) and (j + nearest[jj] >= 0) and (j + nearest[jj] <= sizeX - 1)):
github ucbdrive / 3d-vehicle-tracking / 3d-tracking / tools / object-ap-eval / eval.py View on Github external
@numba.jit(nopython=True)
def fused_compute_statistics(overlaps,
                             pr,
                             gt_nums,
                             dt_nums,
                             dc_nums,
                             gt_datas,
                             dt_datas,
                             dontcares,
                             ignored_gts,
                             ignored_dets,
                             metric,
                             min_overlap,
                             thresholds,
                             compute_aos=False):
    gt_num = 0
    dt_num = 0
github ngcm / interactive-fluid-demo / Sim_numpy_jit.py View on Github external
@jit
def pressure_solve(p, div, b, notb, dx):
    p[notb] = 0

    bound = 0.0 + b[0:-2,1:-1] + b[2:,1:-1] + b[1:-1,0:-2] + b[1:-1,2:]

    for i in range(50):
        p[1:-1,1:-1] = 1 / 4 * (p[1:-1,1:-1] * bound
            + p[0:-2,1:-1] * notb[0:-2,1:-1]
            + p[2:,1:-1] * notb[2:,1:-1]
            + p[1:-1,0:-2] * notb[1:-1,0:-2]
            + p[1:-1,2:] * notb[1:-1,2:]
            - dx[0] * dx[1] * div[1:-1,1:-1])

    return p
github ECreates / py-mandelbrot / mandelbrot / calculate.py View on Github external
@jit
def calculate(x, y): # Self explanatory
	complex_value = complex(x, y)
	z = 0
	for i in range(128): # TODO: Change from hardcoded value
		z = z**2 + complex_value
		if z.real >= 2 or z.real <= -2:
			return i + 1
	return -1