def _while_loop_fn_5(i_max, j_max): j = 1.0 acc = 0.0 while j < j_max: i = 1.0 while i < i_max: acc += i * j i += 1.0 j += 1.0 return acc # ______________________________________________________________________ while_loop_fn_0 = function(_while_loop_fn_0) while_loop_fn_1 = function(_while_loop_fn_1) while_loop_fn_2 = function(_while_loop_fn_2) while_loop_fn_3 = function(_while_loop_fn_3) while_loop_fn_4 = function(_while_loop_fn_4) while_loop_fn_5 = function(_while_loop_fn_5) class TestWhile(unittest.TestCase): def _do_test(self, name, *args, **kws): compiled = globals()[name] uncompiled = globals()["_" + name] self.assertEqual(compiled(*args, **kws), uncompiled(*args, **kws)) def test_while_loop_fn_0(self): test_data = numpy.array([1.0, 2.0, 3.0])
import unittest import numpy import logging logging.basicConfig(level=logging.DEBUG) # ______________________________________________________________________ def _simple_func(arg): if arg > 0.: result = 22. else: result = 42. return result simple_func = decorators.function(_simple_func) def _for_loop(start, stop, inc): acc = 0 for value in range(start, stop, inc): acc += value return acc for_loop = decorators.function(_for_loop) def test_arange(): a = numpy.arange(10) b = numpy.arange(10, dtype=numpy.double) return a, b def test_empty_like(a):
z_real = z_real_n if (z_real * z_real + z_imag * z_imag) >= 4: return i i += 1 return -1 try: mandel_1c = jit(arg_types = ['d', 'd', 'i'], ret_type = 'i')( mandel_1) except: if __debug__: import traceback as tb tb.print_exc() mandel_1c = None mandel_1c_ast = function(mandel_1) #@jit(arg_types = ['d', 'd', 'd', 'i', [['b']], [[['b']]]]) def mandel_driver_1(min_x, max_x, min_y, nb_iterations, colors, image): nb_colors = len(colors) width = image.shape[0] height = image.shape[1] pixel_size = (max_x - min_x) / width for x in range(width): real = min_x + x * pixel_size for y in range(height): imag = min_y + y * pixel_size # For the following to actually compile, mandel_1 must # have already been compiled. color = mandel_1(real, imag, nb_iterations)
def test_avg2d_ast_function(self): compiled_fn = function(avg2d) self._do_test(avg2d, compiled_fn)
def test_avg2d_w_cast_function(self): compiled_fn = function(avg2d_w_cast) self._do_test(avg2d_w_cast, compiled_fn)
def _while_loop_fn_5(i_max, j_max): j = 1. acc = 0. while j < j_max: i = 1. while i < i_max: acc += i * j i += 1. j += 1. return acc # ______________________________________________________________________ while_loop_fn_0 = function(_while_loop_fn_0) while_loop_fn_1 = function(_while_loop_fn_1) while_loop_fn_2 = function(_while_loop_fn_2) while_loop_fn_3 = function(_while_loop_fn_3) while_loop_fn_4 = function(_while_loop_fn_4) while_loop_fn_5 = function(_while_loop_fn_5) class TestWhile(unittest.TestCase): def _do_test(self, name, *args, **kws): compiled = globals()[name] uncompiled = globals()['_' + name] self.assertEqual(compiled(*args, **kws), uncompiled(*args, **kws)) def test_while_loop_fn_0(self): test_data = numpy.array([1., 2., 3.])
# ______________________________________________________________________ def _for_loop_fn_3(stop): acc = 0 for i in range(stop): for j in range(stop): for k in range(stop): for l in range(stop): acc += 1 return acc for_loop_fn_0 = function(_for_loop_fn_0) for_loop_fn_1 = function(_for_loop_fn_1) for_loop_fn_2 = function(_for_loop_fn_2) for_loop_fn_3 = function(_for_loop_fn_3) # ______________________________________________________________________ class TestForLoop(unittest.TestCase): # @unittest.skipUnless(__debug__, "Requires implementation of iteration " # "over arrays.") def test_compiled_for_loop_fn_0(self): for dtype in (np.float32, np.float64, np.int32, np.int64): test_data = np.arange(10, dtype=dtype) result = for_loop_fn_0(test_data) self.assertEqual(result, 45)
# ______________________________________________________________________ def _for_loop_fn_3(stop): acc = 0 for i in range(stop): for j in range(stop): for k in range(stop): for l in range(stop): acc += 1 return acc for_loop_fn_0 = function(_for_loop_fn_0) for_loop_fn_1 = function(_for_loop_fn_1) for_loop_fn_2 = function(_for_loop_fn_2) for_loop_fn_3 = function(_for_loop_fn_3) # ______________________________________________________________________ class TestForLoop(unittest.TestCase): # @unittest.skipUnless(__debug__, "Requires implementation of iteration " # "over arrays.") def test_compiled_for_loop_fn_0(self): for dtype in (np.float32, np.float64, np.int32, np.int64): test_data = np.arange(10, dtype=dtype) result = for_loop_fn_0(test_data) self.assertEqual(result, 45)
z_real = z_real_n if (z_real * z_real + z_imag * z_imag) >= 4: return i i += 1 return -1 try: mandel_1c = jit(arg_types=['d', 'd', 'i'], ret_type='i')(mandel_1) except: if __debug__: import traceback as tb tb.print_exc() mandel_1c = None mandel_1c_ast = function(mandel_1) #@jit(arg_types = ['d', 'd', 'd', 'i', [['b']], [[['b']]]]) def mandel_driver_1(min_x, max_x, min_y, nb_iterations, colors, image): nb_colors = len(colors) width = image.shape[0] height = image.shape[1] pixel_size = (max_x - min_x) / width for x in range(width): real = min_x + x * pixel_size for y in range(height): imag = min_y + y * pixel_size # For the following to actually compile, mandel_1 must # have already been compiled. color = mandel_1(real, imag, nb_iterations)
import numpy import logging logging.basicConfig(level=logging.DEBUG) # ______________________________________________________________________ def _simple_func(arg): if arg > 0.: result = 22. else: result = 42. return result simple_func = decorators.function(_simple_func) def _for_loop(start, stop, inc): acc = 0 for value in range(start, stop, inc): acc += value return acc for_loop = decorators.function(_for_loop) def test_arange(): a = numpy.arange(10) b = numpy.arange(10, dtype=numpy.double)