当前位置: 首页>>代码示例>>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;未经允许,请勿转载。