当前位置: 首页>>代码示例>>Python>>正文


Python decorators.jit函数代码示例

本文整理汇总了Python中numba.decorators.jit函数的典型用法代码示例。如果您正苦于以下问题:Python jit函数的具体用法?Python jit怎么用?Python jit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了jit函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: add

 def add(self, restype=None, argtypes=None):
     dec = decorators.jit(restype, argtypes, backend='ast')
     numba_func = dec(self.pyfunc)
     self.args_restypes.append(list(numba_func.signature.args) +
                               [numba_func.signature.return_type])
     self.signatures.append((restype, argtypes, {}))
     self.translates.append(numba_func)
开发者ID:FrancescAlted,项目名称:numba,代码行数:7,代码来源:gufunc.py

示例2: test_set_index_fn_0

 def test_set_index_fn_0 (self):
     arr = numpy.ones((4,4,4))
     compiled_fn = jit(argtypes=[double[:,:,::1]],
                       backend='bytecode')(set_index_fn_0)
     self.assertEqual(arr[1,2,3], 1.)
     compiled_fn(arr)
     self.assertEqual(arr[1,2,3], 0.)
开发者ID:KanzhiWu,项目名称:numba,代码行数:7,代码来源:test_indexing.py

示例3: test_get_index_fn_0

 def test_get_index_fn_0 (self):
     arr = numpy.ones((4,4,4), dtype=numpy.double)
     arr[1,2,3] = 0.
     compiled_fn = jit(restype=double,
                       argtypes=[double[:, :, ::1]],
                       backend='bytecode')(get_index_fn_0)
     self.assertEqual(compiled_fn(arr), 0.)
开发者ID:KanzhiWu,项目名称:numba,代码行数:7,代码来源:test_indexing.py

示例4: test_compiled_for_loop_fn_0

 def test_compiled_for_loop_fn_0(self):
     test_data = numpy.array([1, 2, 3], dtype = 'l')
     compiled_for_loop_fn = jit(
         arg_types = [['l']])(for_loop_fn_0)
     result = compiled_for_loop_fn(test_data)
     self.assertEqual(result, 6)
     self.assertEqual(result, for_loop_fn_0(testdata))
开发者ID:takluyver,项目名称:numba,代码行数:7,代码来源:test_forloop.py

示例5: test_getattr_data_1

 def test_getattr_data_1(self):
     test_data = numpy.array([1., 2., 3.])
     compiled_fn = jit('d*(d[:])')(get_ndarray_data)
     result = compiled_fn(test_data)
     self.assertEqual(result[0], 1.)
     self.assertEqual(result[1], 2.)
     self.assertEqual(result[2], 3.)
开发者ID:ASPP,项目名称:numba,代码行数:7,代码来源:test_getattr.py

示例6: test_vectorized_sum2d

 def test_vectorized_sum2d(self):
     usum2d = jit(arg_types=[double[:,:]],
                  ret_type=double)(sum2d)
     image = numpy.random.rand(10, 10)
     plain_old_result = sum2d(image)
     hot_new_result = usum2d(image)
     self.assertTrue((abs(plain_old_result - hot_new_result) < 1e-9).all())
开发者ID:EricJustusson,项目名称:numba,代码行数:7,代码来源:test_sum.py

示例7: test_vectorized_filter2d

 def test_vectorized_filter2d(self):
     ufilter2d = jit(argtypes=[double[:, :], double[:, :]], restype=double[:, :])(filter2d)
     image = numpy.random.random((50, 50))
     filt = numpy.random.random((5, 5))
     filt /= filt.sum()
     plain_old_result = filter2d(image, filt)
     hot_new_result = ufilter2d(image, filt)
     self.assertTrue((abs(plain_old_result - hot_new_result) < 1e-9).all())
开发者ID:rnowak,项目名称:numba,代码行数:8,代码来源:test_filter2d.py

示例8: __init__

 def __init__(self, py_func, signature, targetoptions={}):
     self.py_func = py_func
     self.nb_func = jit(target='npyufunc')(py_func)
     self.signature = signature
     self.sin, self.sout = parse_signature(signature)
     self.targetoptions = targetoptions
     self._sigs = []
     self._cres = {}
开发者ID:pombreda,项目名称:numba,代码行数:8,代码来源:ufuncbuilder.py

示例9: test_getattr_shape_2_unpack

 def test_getattr_shape_2_unpack(self):
     compiler_fn = jit('i%d(d[:,:])' % (_plat_bits // 8))
     dim0_fn, dim1_fn = (compiler_fn(fn)
                         for fn in (get_ndarray_2_shape_unpack_0,
                                    get_ndarray_2_shape_unpack_1))
     test_data2 = numpy.array([[1., 2., 3.], [4., 5., 6.]])
     self.assertEqual(dim0_fn(test_data2), 2)
     self.assertEqual(dim1_fn(test_data2), 3)
开发者ID:ASPP,项目名称:numba,代码行数:8,代码来源:test_getattr.py

示例10: test_set_index_fn_1

 def test_set_index_fn_1 (self):
     control_arr = numpy.zeros((50, 50, 2))
     test_arr = numpy.zeros_like(control_arr)
     set_index_fn_1(-1., 1., -1., control_arr)
     compiled_fn = jit(
         arg_types = ['d', 'd', 'd', ['d']])(set_index_fn_1)
     compiled_fn(-1., 1., -1., test_arr)
     self.assertTrue((numpy.abs(control_arr - test_arr) < 1e9).all())
开发者ID:nfoti,项目名称:numba,代码行数:8,代码来源:test_indexing.py

示例11: _do_test

 def _do_test (self, _avg2d):
     compiled_fn = jit(arg_types = [d[:,:], d[:]])(_avg2d)
     test_data = numpy.random.random((5,5))
     control_result = numpy.zeros((5,))
     test_result = control_result[:]
     _avg2d(test_data, control_result)
     compiled_fn(test_data, test_result)
     self.assertTrue((control_result == test_result).all())
开发者ID:takluyver,项目名称:numba,代码行数:8,代码来源:test_avg2d.py

示例12: test_set_index_fn_1

 def test_set_index_fn_1 (self):
     control_arr = numpy.zeros((50, 50, 2), dtype=numpy.double)
     test_arr = numpy.zeros_like(control_arr)
     set_index_fn_1(-1., 1., -1., control_arr)
     argtypes = double, double, double, double[:,:,:]
     compiled_fn = jit(argtypes=argtypes)(set_index_fn_1)
     compiled_fn(-1., 1., -1., test_arr)
     self.assertTrue((numpy.abs(control_arr - test_arr) < 1e9).all())
开发者ID:ASPP,项目名称:numba,代码行数:8,代码来源:test_indexing.py

示例13: main

def main (*args, **kws):
    compiled_demo_function = jit(
        argtypes = ['d', 'd', 'd', [[['d']]]])(demo_function)
    control_arr = numpy.zeros((5, 5, 2))
    demo_function(-1., 1., -1., control_arr)
    test_arr = numpy.zeros_like(control_arr)
    compiled_demo_function(-1., 1., -1., test_arr)
    assert (numpy.abs(control_arr - test_arr) < 1e9).all()
开发者ID:KanzhiWu,项目名称:numba,代码行数:8,代码来源:debugout.py

示例14: __init__

 def __init__(self, py_func, signature, identity=None, cache=False,
              targetoptions={}):
     self.py_func = py_func
     self.identity = parse_identity(identity)
     self.nb_func = jit(target='npyufunc', cache=cache)(py_func)
     self.signature = signature
     self.sin, self.sout = parse_signature(signature)
     self.targetoptions = targetoptions
     self._sigs = []
     self._cres = {}
开发者ID:stuartarchibald,项目名称:numba,代码行数:10,代码来源:ufuncbuilder.py

示例15: test_getattr_data_2

 def test_getattr_data_2(self):
     test_data = numpy.array([[1., 2., 3.], [4., 5., 6.]])
     compiled_fn = jit('d*(d[:,:])')(get_ndarray_data)
     result = compiled_fn(test_data)
     self.assertEqual(result[0], 1.)
     self.assertEqual(result[1], 2.)
     self.assertEqual(result[2], 3.)
     self.assertEqual(result[3], 4.)
     self.assertEqual(result[4], 5.)
     self.assertEqual(result[5], 6.)
开发者ID:ASPP,项目名称:numba,代码行数:10,代码来源:test_getattr.py


注:本文中的numba.decorators.jit函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。