本文整理汇总了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)
示例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
示例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
示例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
示例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
示例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)
示例7: jit
# 需要导入模块: import numba [as 别名]
# 或者: from numba import jit [as 别名]
def jit(func):
return func
示例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)
示例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]
示例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
示例11: jit
# 需要导入模块: import numba [as 别名]
# 或者: from numba import jit [as 别名]
def jit(fn):
return fn
示例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)
示例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)
示例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
示例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