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


Python compiler.compile_isolated函数代码示例

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


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

示例1: _test_compare

    def _test_compare(self, pyfunc):
        def eq(pyfunc, cfunc, args):
            self.assertIs(cfunc(*args), pyfunc(*args),
                          "mismatch for arguments %s" % (args,))

        # Same-sized tuples
        argtypes = [types.Tuple((types.int64, types.float32)),
                    types.UniTuple(types.int32, 2)]
        for ta, tb in itertools.product(argtypes, argtypes):
            cr = compile_isolated(pyfunc, (ta, tb))
            cfunc = cr.entry_point
            for args in [((4, 5), (4, 5)),
                         ((4, 5), (4, 6)),
                         ((4, 6), (4, 5)),
                         ((4, 5), (5, 4))]:
                eq(pyfunc, cfunc, args)
        # Different-sized tuples
        argtypes = [types.Tuple((types.int64, types.float32)),
                    types.UniTuple(types.int32, 3)]
        cr = compile_isolated(pyfunc, tuple(argtypes))
        cfunc = cr.entry_point
        for args in [((4, 5), (4, 5, 6)),
                     ((4, 5), (4, 4, 6)),
                     ((4, 5), (4, 6, 7))]:
            eq(pyfunc, cfunc, args)
开发者ID:denfromufa,项目名称:numba,代码行数:25,代码来源:test_tuples.py

示例2: test_2d_integer_indexing

    def test_2d_integer_indexing(self, flags=enable_pyobj_flags,
                                 pyfunc=integer_indexing_2d_usecase):
        # C layout
        a = np.arange(100, dtype='i4').reshape(10, 10)
        arraytype = types.Array(types.int32, 2, 'C')
        cr = compile_isolated(pyfunc, (arraytype, types.int32, types.int32),
                              flags=flags)
        cfunc = cr.entry_point

        self.assertEqual(pyfunc(a, 0, 0), cfunc(a, 0, 0))
        self.assertEqual(pyfunc(a, 9, 9), cfunc(a, 9, 9))
        self.assertEqual(pyfunc(a, -1, -1), cfunc(a, -1, -1))

        # Any layout
        a = np.arange(100, dtype='i4').reshape(10, 10)[::2, ::2]
        self.assertFalse(a.flags['C_CONTIGUOUS'])
        self.assertFalse(a.flags['F_CONTIGUOUS'])

        arraytype = types.Array(types.int32, 2, 'A')
        cr = compile_isolated(pyfunc, (arraytype, types.int32, types.int32),
                              flags=flags)
        cfunc = cr.entry_point

        self.assertEqual(pyfunc(a, 0, 0), cfunc(a, 0, 0))
        self.assertEqual(pyfunc(a, 2, 2), cfunc(a, 2, 2))
        self.assertEqual(pyfunc(a, -1, -1), cfunc(a, -1, -1))
开发者ID:hargup,项目名称:numba,代码行数:26,代码来源:test_indexing.py

示例3: test_unknown_function

 def test_unknown_function(self):
     try:
         compile_isolated(foo, ())
     except TypingError as e:
         self.assertTrue(e.msg.startswith("Untyped global name"), e.msg)
     else:
         self.fail("Should raise error")
开发者ID:Alexhuszagh,项目名称:numba,代码行数:7,代码来源:test_typingerror.py

示例4: test_unknown_function

 def test_unknown_function(self):
     try:
         compile_isolated(foo, ())
     except TypingError as e:
         self.assertIn("Untyped global name 'what'", str(e))
     else:
         self.fail("Should raise error")
开发者ID:cpcloud,项目名称:numba,代码行数:7,代码来源:test_typingerror.py

示例5: test_unknown_attrs

 def test_unknown_attrs(self):
     try:
         compile_isolated(bar, (types.int32,))
     except TypingError as e:
         self.assertIn("Unknown attribute 'a' of type int32", str(e))
     else:
         self.fail("Should raise error")
开发者ID:cpcloud,项目名称:numba,代码行数:7,代码来源:test_typingerror.py

示例6: test_1d_integer_indexing

    def test_1d_integer_indexing(self, flags=enable_pyobj_flags):
        # C layout
        pyfunc = integer_indexing_1d_usecase
        arraytype = types.Array(types.int32, 1, 'C')
        cr = compile_isolated(pyfunc, (arraytype, types.int32), flags=flags)
        cfunc = cr.entry_point

        a = np.arange(10, dtype='i4')
        self.assertEqual(pyfunc(a, 0), cfunc(a, 0))
        self.assertEqual(pyfunc(a, 9), cfunc(a, 9))
        self.assertEqual(pyfunc(a, -1), cfunc(a, -1))

        # Any layout
        arraytype = types.Array(types.int32, 1, 'A')
        cr = compile_isolated(pyfunc, (arraytype, types.int32), flags=flags)
        cfunc = cr.entry_point

        a = np.arange(10, dtype='i4')[::2]
        self.assertFalse(a.flags['C_CONTIGUOUS'])
        self.assertFalse(a.flags['F_CONTIGUOUS'])
        self.assertEqual(pyfunc(a, 0), cfunc(a, 0))
        self.assertEqual(pyfunc(a, 2), cfunc(a, 2))
        self.assertEqual(pyfunc(a, -1), cfunc(a, -1))

        # Using a 0-d array as integer index
        arraytype = types.Array(types.int32, 1, 'C')
        indextype = types.Array(types.int16, 0, 'C')
        cr = compile_isolated(pyfunc, (arraytype, indextype), flags=flags)
        cfunc = cr.entry_point

        a = np.arange(3, 13, dtype=np.int32)
        for i in (0, 9, -2):
            idx = np.array(i).astype(np.int16)
            assert idx.ndim == 0
            self.assertEqual(pyfunc(a, idx), cfunc(a, idx))
开发者ID:FedericoStra,项目名称:numba,代码行数:35,代码来源:test_indexing.py

示例7: check_argument_cleanup

    def check_argument_cleanup(self, typ, obj):
        """
        Check that argument cleanup doesn't leak references.
        """
        def f(x, y):
            pass

        def _objects(obj):
            objs = [obj]
            if isinstance(obj, tuple):
                for v in obj:
                    objs += _objects(v)
            return objs

        objects = _objects(obj)

        cres = compile_isolated(f, (typ, types.uint32))
        with self.assertRefCount(*objects):
            cres.entry_point(obj, 1)
        with self.assertRefCount(*objects):
            with self.assertRaises(OverflowError):
                cres.entry_point(obj, -1)

        cres = compile_isolated(f, (types.uint32, typ))
        with self.assertRefCount(*objects):
            cres.entry_point(1, obj)
        with self.assertRefCount(*objects):
            with self.assertRaises(OverflowError):
                cres.entry_point(-1, obj)
开发者ID:Alexhuszagh,项目名称:numba,代码行数:29,代码来源:test_conversion.py

示例8: test_index

    def test_index(self):
        pyfunc = tuple_index
        cr = compile_isolated(pyfunc,
                              [types.UniTuple(types.int64, 3), types.int64])
        tup = (4, 3, 6)
        for i in range(len(tup)):
            self.assertPreciseEqual(cr.entry_point(tup, i), tup[i])

        # Test empty tuple
        cr = compile_isolated(pyfunc,
                              [types.UniTuple(types.int64, 0), types.int64])
        with self.assertRaises(IndexError) as raises:
            cr.entry_point((), 0)
        self.assertEqual("tuple index out of range", str(raises.exception))

        # With a compile-time static index (the code generation path is different)
        pyfunc = tuple_index_static
        for typ in (types.UniTuple(types.int64, 4),
                    types.Tuple((types.int64, types.int32, types.int64, types.int32))):
            cr = compile_isolated(pyfunc, (typ,))
            tup = (4, 3, 42, 6)
            self.assertPreciseEqual(cr.entry_point(tup), pyfunc(tup))

        typ = types.UniTuple(types.int64, 1)
        with self.assertTypingError():
            cr = compile_isolated(pyfunc, (typ,))
开发者ID:cpcloud,项目名称:numba,代码行数:26,代码来源:test_tuples.py

示例9: test_unknown_attrs

 def test_unknown_attrs(self):
     try:
         compile_isolated(bar, (types.int32,))
     except TypingError as e:
         self.assertTrue(e.msg.startswith("Unknown attribute"), e.msg)
     else:
         self.fail("Should raise error")
开发者ID:Alexhuszagh,项目名称:numba,代码行数:7,代码来源:test_typingerror.py

示例10: test_complex2

    def test_complex2(self):
        pyfunc = docomplex2

        x_types = [
            types.int32, types.int64, types.float32, types.float64
        ]
        x_values = [1, 1000, 12.2, 23.4]
        y_values = [x - 3 for x in x_values]

        for ty, x, y in zip(x_types, x_values, y_values):
            cres = compile_isolated(pyfunc, [ty, ty])
            cfunc = cres.entry_point
            self.assertPreciseEqual(pyfunc(x, y), cfunc(x, y),
                prec='single' if ty is types.float32 else 'exact')

        # Check that complex(float32, float32) really creates a complex64,
        # by checking the accuracy of computations.
        pyfunc = complex_calc2
        x = 1.0 + 2**-50
        cres = compile_isolated(pyfunc, [types.float32, types.float32])
        cfunc = cres.entry_point
        self.assertPreciseEqual(cfunc(x, x), 2.0)
        # Control (complex128)
        cres = compile_isolated(pyfunc, [types.float64, types.float32])
        cfunc = cres.entry_point
        self.assertGreater(cfunc(x, x), 2.0)
开发者ID:maartenscholl,项目名称:numba,代码行数:26,代码来源:test_numberctor.py

示例11: test_try_except_raises

 def test_try_except_raises(self):
     pyfunc = try_except_usecase
     for f in [no_pyobj_flags, enable_pyobj_flags]:
         with self.assertRaises(errors.UnsupportedError) as e:
             compile_isolated(pyfunc, (), flags=f)
         msg = "Use of unsupported opcode (SETUP_EXCEPT) found"
         self.assertIn(msg, str(e.exception))
开发者ID:numba,项目名称:numba,代码行数:7,代码来源:test_flow_control.py

示例12: test_2d_slicing3

    def test_2d_slicing3(self, flags=enable_pyobj_flags):
        """
        arr_2d[a:b:c, d]
        """
        # C layout
        pyfunc = slicing_2d_usecase3
        arraytype = types.Array(types.int32, 2, "C")
        argtys = (arraytype, types.int32, types.int32, types.int32, types.int32)
        cr = compile_isolated(pyfunc, argtys, flags=flags)
        cfunc = cr.entry_point

        a = np.arange(100, dtype="i4").reshape(10, 10)

        args = [(0, 10, 1, 0), (2, 3, 1, 1), (10, 0, -1, 8), (9, 0, -2, 4), (0, 10, 2, 3), (0, -1, 3, 1)]
        for arg in args:
            expected = pyfunc(a, *arg)
            self.assertPreciseEqual(cfunc(a, *arg), expected)

        # Any layout
        arraytype = types.Array(types.int32, 2, "A")
        argtys = (arraytype, types.int32, types.int32, types.int32, types.int32)
        cr = compile_isolated(pyfunc, argtys, flags=flags)
        cfunc = cr.entry_point

        a = np.arange(400, dtype="i4").reshape(20, 20)[::2, ::2]

        for arg in args:
            expected = pyfunc(a, *arg)
            self.assertPreciseEqual(cfunc(a, *arg), expected)
开发者ID:maartenscholl,项目名称:numba,代码行数:29,代码来源:test_indexing.py

示例13: test_random_randrange

 def test_random_randrange(self):
     for tp, max_width in [(types.int64, 2**63), (types.int32, 2**31)]:
         cr1 = compile_isolated(random_randrange1, (tp,))
         cr2 = compile_isolated(random_randrange2, (tp, tp))
         cr3 = compile_isolated(random_randrange3, (tp, tp, tp))
         self._check_randrange(cr1.entry_point, cr2.entry_point,
                               cr3.entry_point, py_state_ptr, max_width)
开发者ID:denfromufa,项目名称:numba,代码行数:7,代码来源:test_random.py

示例14: test_2d_slicing3

    def test_2d_slicing3(self, flags=enable_pyobj_flags):
        # C layout
        pyfunc = slicing_2d_usecase3
        arraytype = types.Array(types.int32, 2, 'C')
        argtys = (arraytype, types.int32, types.int32, types.int32,
                  types.int32)
        cr = compile_isolated(pyfunc, argtys, flags=flags)
        cfunc = cr.entry_point

        a = np.arange(100, dtype='i4').reshape(10, 10)

        args = [
            (0, 10, 1, 0),
            (2, 3, 1, 2),
            (10, 0, 1, 9),
            (0, 10, -1, 0),
            (0, 10, 2, 4),
        ]
        for arg in args:
            self.assertEqual(pyfunc(a, *arg), cfunc(a, *arg))

        # Any layout
        arraytype = types.Array(types.int32, 2, 'A')
        argtys = (arraytype, types.int32, types.int32, types.int32,
                  types.int32)
        cr = compile_isolated(pyfunc, argtys, flags=flags)
        cfunc = cr.entry_point

        a = np.arange(400, dtype='i4').reshape(20, 20)[::2, ::2]

        for arg in args:
            self.assertEqual(pyfunc(a, *arg), cfunc(a, *arg))
开发者ID:hargup,项目名称:numba,代码行数:32,代码来源:test_indexing.py

示例15: test_func1_isolated

 def test_func1_isolated(self):
     pyfunc = call_func1_nullary
     cr = compile_isolated(pyfunc, ())
     self.assertPreciseEqual(cr.entry_point(), 42)
     pyfunc = call_func1_unary
     cr = compile_isolated(pyfunc, (types.float64,))
     self.assertPreciseEqual(cr.entry_point(18.0), 6.0)
开发者ID:esc,项目名称:numba,代码行数:7,代码来源:test_extending.py


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