當前位置: 首頁>>代碼示例>>Python>>正文


Python numba.jit方法代碼示例

本文整理匯總了Python中numba.jit方法的典型用法代碼示例。如果您正苦於以下問題:Python numba.jit方法的具體用法?Python numba.jit怎麽用?Python numba.jit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在numba的用法示例。


在下文中一共展示了numba.jit方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: calc_XVX_numba

# 需要導入模塊: import numba [as 別名]
# 或者: from numba import jit [as 別名]
def calc_XVX_numba(X, VX):

        XVX = np.zeros((VX.shape[1], X.shape[0], VX.shape[2]))

        for i in range(XVX.shape[2]):

            XVX[:, :, i] = np.dot(VX[:, :, i].T, X.T)

        return XVX


    #@nb.jit(nopython=True, parallel=True)
    # use numba here leads to the following issue in test_0087_o2_gw.py
    # m_rf0_den.py:122: NumbaPerformanceWarning: np.dot() is faster
    # on contiguous arrays, called on (array(float64, 2d, A), array(float64, 2d, C))
    # np.dot(k_c.imag, kernel_sq) 
開發者ID:pyscf,項目名稱:pyscf,代碼行數:18,代碼來源:m_rf0_den.py

示例2: try_jit

# 需要導入模塊: import numba [as 別名]
# 或者: from numba import jit [as 別名]
def try_jit(f, *args, **kwargs):
    """ Apply numba.jit to function ``f`` if Numba is available

    Accepts arguments to Numba jit function (signature, nopython, etc.).

    Examples:

    .. code-block:: python

        @try_jit
        @try_jit()
        @try_jit(nopython=True)
        @try_jit("float32[:](float32[:], float32[:])", nopython=True)

    """
    if has_numba:
        @wraps(f)
        def wrap(*args, **kwargs):
            return nb.jit(*args, **kwargs)
        return wrap(f, *args, **kwargs)
    else:
        return f 
開發者ID:ceholden,項目名稱:yatsm,代碼行數:24,代碼來源:accel.py

示例3: _chebval

# 需要導入模塊: import numba [as 別名]
# 或者: from numba import jit [as 別名]
def _chebval(x, c):
    """
    Evaluate a Chebyshev series at points x.
    This is just a lightly modified copy/paste job from the numpy
    implementation of the same function, copied over here to put a
    jit wrapper around it.
    """
    if len(c) == 1:
        c0 = c[0]
        c1 = 0
    elif len(c) == 2:
        c0 = c[0]
        c1 = c[1]
    else:
        x2 = 2 * x
        c0 = c[-2]
        c1 = c[-1]
        for i in range(3, len(c) + 1):
            tmp = c0
            c0 = c[-i] - c1
            c1 = tmp + c1 * x2
    return c0 + c1 * x 
開發者ID:geodynamics,項目名稱:burnman,代碼行數:24,代碼來源:debye.py

示例4: Timeline_Integral_with_cross_before

# 需要導入模塊: import numba [as 別名]
# 或者: from numba import jit [as 別名]
def Timeline_Integral_with_cross_before(Tm:np.ndarray,):
    """
    explanation:
         計算時域金叉/死叉信號的累積卷積和(死叉(1-->0)不清零,金叉(0-->1)清零)		
         經測試for最快,比reduce快(無jit,jit的話for就更快了)

    params:
        * Tm ->:
            meaning: 數據
            type: null
            optional: [null]

    return:
        np.array
	
    demonstrate:
        Not described
	
    output:
        Not described
    """
    T = np.zeros(len(Tm)).astype(np.int32)
    for i, Tmx in enumerate(Tm):
        T[i] = (T[i - 1] + 1) if (Tmx != 1) else 0
    return T 
開發者ID:QUANTAXIS,項目名稱:QUANTAXIS,代碼行數:27,代碼來源:QAAnalysis_signal.py

示例5: _jit

# 需要導入模塊: import numba [as 別名]
# 或者: from numba import jit [as 別名]
def _jit(function):
    """
    Compile a function using a jit compiler.

    The function is always compiled to check errors, but is only used outside
    tests, so that code coverage analysis can be performed in jitted functions.

    The tests set sys._called_from_test in conftest.py.

    """
    import sys

    compiled = numba.jit(function)

    if hasattr(sys, '_called_from_test'):
        return function
    else:  # pragma: no cover
        return compiled 
開發者ID:vnmabus,項目名稱:dcor,代碼行數:20,代碼來源:_utils.py

示例6: test_Colebrook_ignored

# 需要導入模塊: import numba [as 別名]
# 或者: from numba import jit [as 別名]
def test_Colebrook_ignored():
    fd = fluids.numba.Colebrook(1e5, 1e-5)
    assert_close(fd, 0.018043802895063684, rtol=1e-14)


# Not compatible with cache
#@pytest.mark.numba
#@pytest.mark.skipif(numba is None, reason="Numba is missing")
#def test_secant_runs():
#    # Really feel like the kwargs should work in object mode, but it doesn't
#    # Just gets slower
#    @numba.jit
#    def to_solve(x):
#        return sin(x*.3) - .5
#    fluids.numba.secant(to_solve, .3, ytol=1e-10)
#
#@pytest.mark.numba
#@pytest.mark.skipif(numba is None, reason="Numba is missing")
#def test_brenth_runs():
#    @numba.njit
#    def to_solve(x, goal):
#        return sin(x*.3) - goal
#    
#    ans = fluids.numba.brenth(to_solve, .3, 2, args=(.45,))
#    assert_close(ans, 1.555884463490988) 
開發者ID:CalebBell,項目名稱:fluids,代碼行數:27,代碼來源:test_numba.py

示例7: jit

# 需要導入模塊: import numba [as 別名]
# 或者: from numba import jit [as 別名]
def jit(func):
    return func 
開發者ID:abewley,項目名稱:sort,代碼行數:4,代碼來源:sort.py

示例8: get_index_lm

# 需要導入模塊: import numba [as 別名]
# 或者: from numba import jit [as 別名]
def get_index_lm(l, m):
    """
        return the index of an array ordered as 
        [l=0 m=0, l=1 m=-1, l=1 m=0, l=1 m=1, ....]
    """
    return (l+1)**2 -1 -l + m


#@nb.jit(nopython=True, parallel=True) 
開發者ID:pyscf,項目名稱:pyscf,代碼行數:11,代碼來源:m_comp_vext_tem_numba.py

示例9: relu_p

# 需要導入模塊: import numba [as 別名]
# 或者: from numba import jit [as 別名]
def relu_p(A):
    return s0 if A < s0 else s1


# @nb.jit("{f2}({f2})".format(f2=Xd(2)), nopython=True)
# def softmax(Z):
#     eZ = np.exp(Z)
#     return eZ / np.sum(eZ, axis=1)
#
#
# @nb.jit("{f2}({f2})".format(f2=Xd(2)), nopython=True)
# def softmax_p(A):
#     I = np.eye(A.shape[1], dtype=floatX)
#     idx = np.arange(A.shape[1])
#     return A * (A[..., None] - I[None, ...])[:, idx, idx] 
開發者ID:csxeba,項目名稱:brainforge,代碼行數:17,代碼來源:_llactivation.py

示例10: jit

# 需要導入模塊: import numba [as 別名]
# 或者: from numba import jit [as 別名]
def jit():
    def decorator(func):
        try:
            return numba.jit(cache=True)(func)
        except RuntimeError:
            return numba.jit(cache=False)(func)

    return decorator 
開發者ID:rusty1s,項目名稱:pytorch_geometric,代碼行數:10,代碼來源:gdc.py

示例11: jit

# 需要導入模塊: import numba [as 別名]
# 或者: from numba import jit [as 別名]
def jit(fn):
        return fn 
開發者ID:geodynamics,項目名稱:burnman,代碼行數:4,代碼來源:solutionmodel.py

示例12: _grueneisen_parameter_fast

# 需要導入模塊: import numba [as 別名]
# 或者: from numba import jit [as 別名]
def _grueneisen_parameter_fast(V_0, volume, gruen_0, q_0):
    """global function with plain parameters so jit will work"""
    x = V_0 / volume
    f = 1. / 2. * (pow(x, 2. / 3.) - 1.)
    a1_ii = 6. * gruen_0  # EQ 47
    a2_iikk = -12. * gruen_0 + 36. * \
        gruen_0 * gruen_0 - 18. * q_0 * gruen_0  # EQ 47
    nu_o_nu0_sq = 1. + a1_ii * f + (1. / 2.) * a2_iikk * f * f  # EQ 41
    return 1. / 6. / nu_o_nu0_sq * (2. * f + 1.) * (a1_ii + a2_iikk * f) 
開發者ID:geodynamics,項目名稱:burnman,代碼行數:11,代碼來源:slb.py

示例13: index_of

# 需要導入模塊: import numba [as 別名]
# 或者: from numba import jit [as 別名]
def index_of(array,value):
    idx = (np.abs(array-value)).argmin()
    return idx


# if numba_avail:
    # @nb.jit('void(double[:,:], double[:,:], int32, int32)', nopython=True, nogil=True) 
開發者ID:ocelot-collab,項目名稱:ocelot,代碼行數:9,代碼來源:math_op.py

示例14: __init__

# 需要導入模塊: import numba [as 別名]
# 或者: from numba import jit [as 別名]
def __init__(self):
        self.full_matrix = False
        if ne_flag:
            # print("SecondTM: NumExpr")
            self.tmat_multip = self.numexpr_apply
        elif nb_flag and self.full_matrix:
            # print("SecondTM: NUMBA")
            self.tmat_multip = nb.jit(nopython=True, parallel=True)(self.numba_apply)
        else:
            # print("SecondTM: Numpy")
            self.tmat_multip = self.numpy_apply 
開發者ID:ocelot-collab,項目名稱:ocelot,代碼行數:13,代碼來源:optics.py

示例15: __init__

# 需要導入模塊: import numba [as 別名]
# 或者: from numba import jit [as 別名]
def __init__(self):
        self.print_log = False
        if nb_flag:
            logger.debug("Smoothing: NUMBA")
            self.q_per_step_ip2 = nb.jit()(self.q_per_step_ip2_py)
        else:
            logger.debug("Smoothing: Python")
            self.q_per_step_ip2 = self.q_per_step_ip2_py 
開發者ID:ocelot-collab,項目名稱:ocelot,代碼行數:10,代碼來源:csr.py


注:本文中的numba.jit方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。