• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python decorators.jit函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: add

 def add(self, restype=None, argtypes=None, **kwds):
     """
     Add a specialization to the vectorizer. Pass any keyword arguments
     to numba.jit().
     """
     dec = decorators.jit(restype, argtypes, **kwds)
     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,代码行数:11,代码来源:_common.py


示例17: test_vectorized_fbcorr

    def test_vectorized_fbcorr(self):
        ufbcorr = jit(arg_types=(nd4type, nd4type, nd4type))(fbcorr)

        imgs = np.random.randn(10, 64, 64, 3)
        filt = np.random.randn(6, 5, 5, 3)
        old_output = np.zeros((10, 6, 60, 60))
        fbcorr(imgs, filt, old_output)
        new_output = np.zeros((10, 6, 60, 60))
        ufbcorr(imgs, filt, new_output)

        self.assertTrue((abs(old_output - new_output) < 1e-9).all())
开发者ID:takluyver,项目名称:numba,代码行数:11,代码来源:test_fbcorr.py


示例18: test_vectorized_fbcorr

    def test_vectorized_fbcorr(self):
        ufbcorr = jit(argtypes=(nd4type, nd4type, nd4type), backend='bytecode')(fbcorr)

        imgs = np.random.randn(10, 16, 16, 3)
        filt = np.random.randn(6, 5, 5, 3)
        old_output = np.zeros((10, 6, 15, 15))
        fbcorr(imgs, filt, old_output)
        new_output = np.zeros((10, 6, 15, 15))
        ufbcorr(imgs, filt, new_output)

        self.assertTrue((abs(old_output - new_output) < 1e-9).all())
开发者ID:KanzhiWu,项目名称:numba,代码行数:11,代码来源:test_fbcorr.py


示例19: test_numba

    def test_numba(self):
        jit_matmulcore = jit((float32[:, :], float32[:, :], float32[:,:]))(matmulcore)

        A = np.arange(16, dtype=np.float32).reshape(4, 4)
        B = np.arange(16, dtype=np.float32).reshape(4, 4)
        C = np.zeros(16, dtype=np.float32).reshape(4, 4)
        Gold = np.matrix(A) * np.matrix(B)

        jit_matmulcore(A, B, C)

        self.assertTrue((C == Gold).all())
开发者ID:GaZ3ll3,项目名称:numba,代码行数:11,代码来源:test_gufunc.py


示例20: test_set_index_fn_2

    def test_set_index_fn_2 (self):
        control_arr = numpy.zeros((10, 10), dtype=numpy.double)
        test_arr = numpy.zeros_like(control_arr)

        set_index_fn_2(control_arr)

        argtypes = double[:, :],
        compiled_fn = jit(argtypes=argtypes)(set_index_fn_2)

        compiled_fn(test_arr)

        self.assertTrue((numpy.abs(control_arr - test_arr) < 1e9).all())
开发者ID:ASPP,项目名称:numba,代码行数:12,代码来源:test_indexing.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python dummyarray.Array类代码示例发布时间:2022-05-27
下一篇:
Python cuda.to_device函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap