Exemplo n.º 1
0
 def generic_2d(self, expr, typ):
     # The complex testing is pretty lame...
     ast = parser.suite(expr)
     arg_list = harvest_variables(ast.tolist())
     all_sizes = [(10, 10), (50, 50), (100, 100), (500, 500), (1000, 1000)]
     debug_print('\nExpression:', expr)
     with TempdirBlitz():
         for size in all_sizes:
             arg_dict = {}
             for arg in arg_list:
                 arg_dict[arg] = random.normal(0, 1, size).astype(typ)
                 # set imag part of complex values to non-zero value
                 try:
                     arg_dict[arg].imag = arg_dict[arg].real
                 except:
                     pass
             debug_print('Run:', size, typ)
             standard, compiled = self.generic_check(
                 expr, arg_dict, type, size)
             try:
                 speed_up = standard / compiled
             except:
                 speed_up = -1.
             debug_print("1st run(numpy,compiled,speed up):  %3.4f, %3.4f, "
                         "%3.4f" % (standard, compiled, speed_up))
             standard, compiled = self.generic_check(
                 expr, arg_dict, type, size)
             try:
                 speed_up = standard / compiled
             except:
                 speed_up = -1.
             debug_print("2nd run(numpy,compiled,speed up):  %3.4f, %3.4f, "
                         "%3.4f" % (standard, compiled, speed_up))
Exemplo n.º 2
0
def test_blitz_bug():
    # Assignment to arr[i:] used to fail inside blitz expressions.
    with TempdirBlitz():
        N = 4
        expr_buggy = 'arr_blitz_buggy[{0}:] = arr[{0}:]'
        expr_not_buggy = 'arr_blitz_not_buggy[{0}:{1}] = arr[{0}:]'
        random.seed(7)
        arr = random.randn(N)
        sh = arr.shape[0]
        for lim in [0, 1, 2]:
            arr_blitz_buggy = zeros(N)
            arr_blitz_not_buggy = zeros(N)
            arr_np = zeros(N)
            blitz(expr_buggy.format(lim))
            blitz(expr_not_buggy.format(lim, 'sh'))
            arr_np[lim:] = arr[lim:]
            assert_allclose(arr_blitz_buggy, arr_np)
            assert_allclose(arr_blitz_not_buggy, arr_np)