コード例 #1
0
    def test_arrayscalar_const(self):
        pyfunc = use_arrayscalar_const
        cres = compile_isolated(pyfunc, ())
        cfunc = cres.entry_point

        self.assertEqual(pyfunc(), cfunc())
コード例 #2
0
ファイル: test_builtins.py プロジェクト: srchilukoori/numba
 def check_min_max_unary_non_iterable(self,
                                      pyfunc,
                                      flags=enable_pyobj_flags):
     cr = compile_isolated(pyfunc, (types.int32, ), flags=flags)
     cfunc = cr.entry_point
     cfunc(1)
コード例 #3
0
ファイル: test_builtins.py プロジェクト: vishalbelsare/numba
 def run_nullary_func(self, pyfunc, flags):
     cr = compile_isolated(pyfunc, (), flags=flags)
     cfunc = cr.entry_point
     expected = pyfunc()
     self.assertPreciseEqual(cfunc(), expected)
コード例 #4
0
 def test_mod_complex(self, flags=force_pyobj_flags):
     pyfunc = self.op.mod_usecase
     with self.assertTypingError():
         cres = compile_isolated(pyfunc, (types.complex64, types.complex64))
コード例 #5
0
ファイル: test_builtins.py プロジェクト: srchilukoori/numba
 def test_locals(self, flags=enable_pyobj_flags):
     pyfunc = locals_usecase
     with self.assertRaises(errors.ForbiddenConstruct):
         cr = compile_isolated(pyfunc, (types.int64, ), flags=flags)
コード例 #6
0
 def compile_func(arr):
     cr = compile_isolated(pyfunc,
                           (typeof(arr), types.intp, types.intp),
                           flags=flags)
     return cr.entry_point
コード例 #7
0
 def get_cfunc(self, pyfunc):
     rectype = numpy_support.from_dtype(recordwithcharseq)
     cres = compile_isolated(pyfunc, (rectype[:], types.intp))
     return cres.entry_point
コード例 #8
0
ファイル: test_tuples.py プロジェクト: asellappen/numba
 def test_unituple(self):
     tuple_type = types.UniTuple(types.int32, 2)
     cr_first = compile_isolated(tuple_first, (tuple_type,))
     cr_second = compile_isolated(tuple_second, (tuple_type,))
     self.assertPreciseEqual(cr_first.entry_point((4, 5)), 4)
     self.assertPreciseEqual(cr_second.entry_point((4, 5)), 5)
コード例 #9
0
ファイル: test_tuples.py プロジェクト: asellappen/numba
 def test_hetero_tuple(self):
     tuple_type = types.Tuple((types.int64, types.float32))
     cr_first = compile_isolated(tuple_first, (tuple_type,))
     cr_second = compile_isolated(tuple_second, (tuple_type,))
     self.assertPreciseEqual(cr_first.entry_point((2**61, 1.5)), 2**61)
     self.assertPreciseEqual(cr_second.entry_point((2**61, 1.5)), 1.5)
コード例 #10
0
 def generic_run(pyfunc, arr, shape):
     cres = compile_isolated(pyfunc, (typeof(arr), typeof(shape)))
     return cres.entry_point(arr, shape)
コード例 #11
0
 def test_bad_float_index_npm(self):
     with self.assertTypingError() as raises:
         compile_isolated(bad_float_index,
                          (types.Array(types.float64, 2, "C"), ))
     self.assertIn("unsupported array index type float64",
                   str(raises.exception))
コード例 #12
0
 def check_array_const(self, pyfunc):
     cres = compile_isolated(pyfunc, (types.int32,))
     cfunc = cres.entry_point
     for i in [0, 1, 2]:
         np.testing.assert_array_equal(pyfunc(i), cfunc(i))
コード例 #13
0
    def test_constant_bytes(self):
        pyfunc = bytes_as_const_array
        cres = compile_isolated(pyfunc, ())
        cfunc = cres.entry_point

        np.testing.assert_array_equal(pyfunc(), cfunc())
コード例 #14
0
 def test_write_to_global_array(self):
     pyfunc = write_to_global_array
     with self.assertRaises(TypingError):
         compile_isolated(pyfunc, ())
コード例 #15
0
 def compile_simple_nopython(self):
     with captured_stdout() as out:
         cres = compile_isolated(simple_nopython, (types.int64, ))
         # Sanity check compiled function
         self.assertPreciseEqual(cres.entry_point(2), 3)
     return out.getvalue()
コード例 #16
0
ファイル: test_tuples.py プロジェクト: asellappen/numba
 def check_conversion(self, fromty, toty, val):
     pyfunc = identity
     cr = compile_isolated(pyfunc, (fromty,), toty)
     cfunc = cr.entry_point
     res = cfunc(val)
     self.assertEqual(res, val)
コード例 #17
0
 def compile_simple_gen(self):
     with captured_stdout() as out:
         cres = compile_isolated(simple_gen, (types.int64, types.int64))
         # Sanity check compiled function
         self.assertPreciseEqual(list(cres.entry_point(2, 5)), [2, 5])
     return out.getvalue()
コード例 #18
0
 def check_array_iter_items(self, arr):
     pyfunc = array_iter_items
     cres = compile_isolated(pyfunc, [typeof(arr)])
     cfunc = cres.entry_point
     expected = pyfunc(arr)
     self.assertPreciseEqual(cfunc(arr), expected)
コード例 #19
0
 def get_cfunc(self, pyfunc, argspec):
     cres = compile_isolated(pyfunc, argspec)
     return cres.entry_point
コード例 #20
0
 def check_array_view_iter(self, arr, index):
     pyfunc = array_view_iter
     cres = compile_isolated(pyfunc, [typeof(arr), typeof(index)])
     cfunc = cres.entry_point
     expected = pyfunc(arr, index)
     self.assertPreciseEqual(cfunc(arr, index), expected)
コード例 #21
0
 def test_is_ellipsis(self):
     cres = compile_isolated(self.op.is_usecase,
                             (types.ellipsis, types.ellipsis))
     cfunc = cres.entry_point
     self.assertTrue(cfunc(Ellipsis, Ellipsis))
コード例 #22
0
 def check_array_unary(self, arr, arrty, func):
     cres = compile_isolated(func, [arrty])
     cfunc = cres.entry_point
     self.assertPreciseEqual(cfunc(arr), func(arr))
コード例 #23
0
ファイル: test_builtins.py プロジェクト: srchilukoori/numba
 def test_globals(self, flags=enable_pyobj_flags):
     pyfunc = globals_usecase
     cr = compile_isolated(pyfunc, (), flags=flags)
     cfunc = cr.entry_point
     g = cfunc()
     self.assertIs(g, globals())
コード例 #24
0
 def test_np_ndindex_empty(self):
     func = np_ndindex_empty
     cres = compile_isolated(func, [])
     cfunc = cres.entry_point
     self.assertPreciseEqual(cfunc(), func())
コード例 #25
0
ファイル: test_builtins.py プロジェクト: srchilukoori/numba
 def check_min_max_invalid_types(self, pyfunc, flags=enable_pyobj_flags):
     cr = compile_isolated(pyfunc, (types.int32, types.Dummy('list')),
                           flags=flags)
     cfunc = cr.entry_point
     cfunc(1, [1])
コード例 #26
0
 def get_cfunc(self, pyfunc):
     cres = compile_isolated(pyfunc, (self.nbrecord, ))
     return cres.entry_point
コード例 #27
0
ファイル: test_builtins.py プロジェクト: srchilukoori/numba
 def check_min_max_empty_tuple(self, pyfunc, func_name):
     with self.assertTypingError() as raises:
         compile_isolated(pyfunc, (), flags=no_pyobj_flags)
     self.assertIn("%s() argument is an empty tuple" % func_name,
                   str(raises.exception))
コード例 #28
0
    def assert_prune(self, func, args_tys, prune, *args, **kwargs):
        # This checks that the expected pruned branches have indeed been pruned.
        # func is a python function to assess
        # args_tys is the numba types arguments tuple
        # prune arg is a list, one entry per branch. The value in the entry is
        # encoded as follows:
        # True: using constant inference only, the True branch will be pruned
        # False: using constant inference only, the False branch will be pruned
        # None: under no circumstances should this branch be pruned
        # *args: the argument instances to pass to the function to check
        #        execution is still valid post transform
        # **kwargs:
        #        - flags: compiler.Flags instance to pass to `compile_isolated`,
        #          permits use of e.g. object mode

        func_ir = compile_to_ir(func)
        before = func_ir.copy()
        if self._DEBUG:
            print("=" * 80)
            print("before prune")
            func_ir.dump()

        rewrite_semantic_constants(func_ir, args_tys)
        dead_branch_prune(func_ir, args_tys)

        after = func_ir
        if self._DEBUG:
            print("after prune")
            func_ir.dump()

        before_branches = self.find_branches(before)
        self.assertEqual(len(before_branches), len(prune))

        # what is expected to be pruned
        expect_removed = []
        for idx, prune in enumerate(prune):
            branch = before_branches[idx]
            if prune is True:
                expect_removed.append(branch.truebr)
            elif prune is False:
                expect_removed.append(branch.falsebr)
            elif prune is None:
                pass  # nothing should be removed!
            elif prune == 'both':
                expect_removed.append(branch.falsebr)
                expect_removed.append(branch.truebr)
            else:
                assert 0, "unreachable"

        # compare labels
        original_labels = set([_ for _ in before.blocks.keys()])
        new_labels = set([_ for _ in after.blocks.keys()])
        # assert that the new labels are precisely the original less the
        # expected pruned labels
        try:
            self.assertEqual(new_labels, original_labels - set(expect_removed))
        except AssertionError as e:
            print("new_labels", sorted(new_labels))
            print("original_labels", sorted(original_labels))
            print("expect_removed", sorted(expect_removed))
            raise e

        supplied_flags = kwargs.pop('flags', False)
        compiler_kws = {'flags': supplied_flags} if supplied_flags else {}
        cres = compile_isolated(func, args_tys, **compiler_kws)
        if args is None:
            res = cres.entry_point()
            expected = func()
        else:
            res = cres.entry_point(*args)
            expected = func(*args)
        self.assertEqual(res, expected)
コード例 #29
0
ファイル: test_builtins.py プロジェクト: vishalbelsare/numba
 def test_enumerate_start_invalid_start_type_npm(self):
     pyfunc = enumerate_invalid_start_usecase
     with self.assertRaises(errors.TypingError) as raises:
         cr = compile_isolated(pyfunc, (), flags=no_pyobj_flags)
     msg = "Only integers supported as start value in enumerate"
     self.assertIn(msg, str(raises.exception))
コード例 #30
0
ファイル: test_extending.py プロジェクト: yumasheta/numba
 def test_cast_mydummy(self):
     pyfunc = get_dummy
     cr = compile_isolated(pyfunc, (), types.float64)
     self.assertPreciseEqual(cr.entry_point(), 42.0)