Example #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))
Example #2
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))
    def generic_2d(self, expr, typ):
        """ The complex testing is pretty lame...
        """
        mod_location = empty_temp_dir()
        import parser

        ast = parser.suite(expr)
        arg_list = harvest_variables(ast.tolist())
        # print arg_list
        all_sizes = [(10, 10), (50, 50), (100, 100), (500, 500), (1000, 1000)]
        print "\nExpression:", expr
        for size in all_sizes:
            result = zeros(size, typ)
            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
            print "Run:", size, typ
            standard, compiled = self.generic_check(expr, arg_dict, type, size, mod_location)
            try:
                speed_up = standard / compiled
            except:
                speed_up = -1.0
            print "1st run(numpy.numerix,compiled,speed up):  %3.4f, %3.4f, " "%3.4f" % (standard, compiled, speed_up)
            standard, compiled = self.generic_check(expr, arg_dict, type, size, mod_location)
            try:
                speed_up = standard / compiled
            except:
                speed_up = -1.0
            print "2nd run(numpy.numerix,compiled,speed up):  %3.4f, %3.4f, " "%3.4f" % (standard, compiled, speed_up)
        cleanup_temp_dir(mod_location)
Example #4
0
    def generic_check(self,expr,desired,**kw):
        ast_list = parser.expr(expr).tolist()
        args = harvest_variables(ast_list)
        loc = locals().update(kw)
        for var in args:
            s = '%s = size_check.dummy_array(%s)' % (var,var)
            exec(s,loc)
        try:
            actual = eval(expr,locals()).shape
        except:
            actual = 'failed'

        if actual is 'failed' and desired is 'failed':
            return

        assert_array_equal(actual,desired, expr)
    def generic_check(self, expr, desired, **kw):
        import parser

        ast_list = parser.expr(expr).tolist()
        args = harvest_variables(ast_list)
        loc = locals().update(kw)
        for var in args:
            s = "%s = size_check.dummy_array(%s)" % (var, var)
            exec (s, loc)
        try:
            actual = eval(expr, locals()).shape
        except:
            actual = "failed"
        if actual is "failed" and desired is "failed":
            return
        try:
            assert_array_equal(actual, desired, expr)
        except:
            print "EXPR:", expr
            print "ACTUAL:", actual
            print "DESIRED:", desired
Example #6
0
 def generic_2d(self, expr, typ):
     """ The complex testing is pretty lame...
     """
     mod_location = empty_temp_dir()
     import parser
     ast = parser.suite(expr)
     arg_list = harvest_variables(ast.tolist())
     #print arg_list
     all_sizes = [(10, 10), (50, 50), (100, 100), (500, 500), (1000, 1000)]
     print '\nExpression:', expr
     for size in all_sizes:
         result = zeros(size, typ)
         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
         print 'Run:', size, typ
         standard, compiled = self.generic_check(expr, arg_dict, type, size,
                                                 mod_location)
         try:
             speed_up = standard / compiled
         except:
             speed_up = -1.
         print "1st run(numpy.numerix,compiled,speed up):  %3.4f, %3.4f, " \
               "%3.4f" % (standard,compiled,speed_up)
         standard, compiled = self.generic_check(expr, arg_dict, type, size,
                                                 mod_location)
         try:
             speed_up = standard / compiled
         except:
             speed_up = -1.
         print "2nd run(numpy.numerix,compiled,speed up):  %3.4f, %3.4f, " \
               "%3.4f" % (standard,compiled,speed_up)
     cleanup_temp_dir(mod_location)
Example #7
0
 def generic_check(self,expr,desired):
     import parser
     ast_list = parser.suite(expr).tolist()
     actual = ast_tools.harvest_variables(ast_list)
     assert_equal(actual,desired,expr)
Example #8
0
 def generic_check(self,expr,desired):
     import parser
     ast_list = parser.suite(expr).tolist()
     actual = ast_tools.harvest_variables(ast_list)
     assert_equal(actual,desired,expr)