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)
Beispiel #2
0
    def test_add_function_ordered(self):
        clear_temp_catalog()
        q = catalog.catalog()
        import string

        q.add_function('f', string.upper)
        q.add_function('f', string.lower)
        q.add_function('ff', string.find)
        q.add_function('ff', string.replace)
        q.add_function('fff', string.atof)
        q.add_function('fff', string.atoi)
        del q

        # now we're gonna make a new catalog with same code
        # but different functions in a specified module directory
        env_dir = empty_temp_dir()
        r = catalog.catalog(env_dir)
        r.add_function('ff', os.abort)
        r.add_function('ff', os.chdir)
        r.add_function('fff', os.access)
        r.add_function('fff', os.open)
        del r
        # now we're gonna make a new catalog with same code
        # but different functions in a user specified directory
        user_dir = empty_temp_dir()
        s = catalog.catalog(user_dir)
        import re
        s.add_function('fff', re.match)
        s.add_function('fff', re.purge)
        del s

        # open new catalog and make sure it retreives the functions
        # from d catalog instead of the temp catalog (made by q)
        os.environ['PYTHONCOMPILED'] = env_dir
        t = catalog.catalog(user_dir)
        funcs1 = t.get_functions('f')
        funcs2 = t.get_functions('ff')
        funcs3 = t.get_functions('fff')
        restore_temp_catalog()
        # make sure everything is read back in the correct order
        # a little cheating... I'm ignoring any functions that might have
        # been read in from a prior catalog file (such as the defualt one).
        # the test should really be made so that these aren't read in, but
        # until I get this figured out...
        #assert_(funcs1 == [string.lower,string.upper])
        #assert_(funcs2 == [os.chdir,os.abort,string.replace,string.find])
        #assert_(funcs3 == [re.purge,re.match,os.open,
        #                  os.access,string.atoi,string.atof])
        assert_(funcs1[:2] == [string.lower, string.upper]), ` funcs1 `
        assert_(
            funcs2[:4] == [os.chdir, os.abort, string.replace, string.find])
        assert_(
            funcs3[:6] ==
            [re.purge, re.match, os.open, os.access, string.atoi, string.atof])
        cleanup_temp_dir(user_dir)
        cleanup_temp_dir(env_dir)
Beispiel #3
0
    def test_add_function_ordered(self):
        clear_temp_catalog()
        q = catalog.catalog()
        import string

        q.add_function('f',string.upper)
        q.add_function('f',string.lower)
        q.add_function('ff',string.find)
        q.add_function('ff',string.replace)
        q.add_function('fff',string.atof)
        q.add_function('fff',string.atoi)
        del q

        # now we're gonna make a new catalog with same code
        # but different functions in a specified module directory
        env_dir = empty_temp_dir()
        r = catalog.catalog(env_dir)
        r.add_function('ff',os.abort)
        r.add_function('ff',os.chdir)
        r.add_function('fff',os.access)
        r.add_function('fff',os.open)
        del r
        # now we're gonna make a new catalog with same code
        # but different functions in a user specified directory
        user_dir = empty_temp_dir()
        s = catalog.catalog(user_dir)
        import re
        s.add_function('fff',re.match)
        s.add_function('fff',re.purge)
        del s

        # open new catalog and make sure it retreives the functions
        # from d catalog instead of the temp catalog (made by q)
        os.environ['PYTHONCOMPILED'] = env_dir
        t = catalog.catalog(user_dir)
        funcs1 = t.get_functions('f')
        funcs2 = t.get_functions('ff')
        funcs3 = t.get_functions('fff')
        restore_temp_catalog()
        # make sure everything is read back in the correct order
        # a little cheating... I'm ignoring any functions that might have
        # been read in from a prior catalog file (such as the defualt one).
        # the test should really be made so that these aren't read in, but
        # until I get this figured out...
        #assert_(funcs1 == [string.lower,string.upper])
        #assert_(funcs2 == [os.chdir,os.abort,string.replace,string.find])
        #assert_(funcs3 == [re.purge,re.match,os.open,
        #                  os.access,string.atoi,string.atof])
        assert_(funcs1[:2] == [string.lower,string.upper]),repr(funcs1)
        assert_(funcs2[:4] == [os.chdir,os.abort,string.replace,string.find])
        assert_(funcs3[:6] == [re.purge,re.match,os.open,
                          os.access,string.atoi,string.atof])
        cleanup_temp_dir(user_dir)
        cleanup_temp_dir(env_dir)
 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)
Beispiel #5
0
    def test_add_function_ordered(self):
        backup_dir = clear_temp_catalog()
        q = catalog.catalog()

        q.add_function('f',string_types[0].upper)
        q.add_function('f',string_types[0].lower)
        q.add_function('ff',string_types[0].find)
        q.add_function('ff',string_types[0].replace)
        if PY3:
            q.add_function('fff', float)
            q.add_function('fff', int)
        else:
            q.add_function('fff',string_types[0].atof)
            q.add_function('fff',string_types[0].atoi)
        del q

        # now we're gonna make a new catalog with same code
        # but different functions in a specified module directory
        env_dir = empty_temp_dir()
        r = catalog.catalog(env_dir)
        r.add_function('ff',os.abort)
        r.add_function('ff',os.chdir)
        r.add_function('fff',os.access)
        r.add_function('fff',os.open)
        del r
        # now we're gonna make a new catalog with same code
        # but different functions in a user specified directory
        user_dir = empty_temp_dir()
        s = catalog.catalog(user_dir)
        s.add_function('fff',re.match)
        s.add_function('fff',re.purge)
        del s
        
        env_dir = "C:\\Users\\Sven\\AppData\\Local\\Temp\\Sven\\python34_compiled\\m0"
        user_dir = "C:\\Users\\Sven\\AppData\\Local\\Temp\\Sven\\python34_compiled\\m1"
        
        # open new catalog and make sure it retreives the functions
        # from d catalog instead of the temp catalog (made by q)
        os.environ['PYTHONCOMPILED'] = env_dir
        t = catalog.catalog(user_dir)
        #print(t.build_search_order())
        funcs1 = t.get_functions('f')
        #print("funcs1")
        #print(funcs1)
        funcs2 = t.get_functions('ff')
        #print("funcs2")
        #print(funcs2)
        funcs3 = t.get_functions('fff')
        #print("funcs3")
        #print(funcs3)
        #restore_temp_catalog(backup_dir)
        # make sure everything is read back in the correct order
        # a little cheating... I'm ignoring any functions that might have
        # been read in from a prior catalog file (such as the defualt one).
        # the test should really be made so that these aren't read in, but
        # until I get this figured out...
        #assert_(funcs1 == [string_types[0].lower,string_types[0].upper])
        #assert_(funcs2 == [os.chdir,os.abort,string_types[0].replace,string_types[0].find])
        #assert_(funcs3 == [re.purge,re.match,os.open,
        #                  os.access,string_types[0].atoi,string_types[0].atof])
        assert_(funcs1[:2] == [string_types[0].lower,string_types[0].upper])#,repr(funcs1)
        assert_(funcs2[:4] == [os.chdir,os.abort,string_types[0].replace,string_types[0].find])
        assert_(funcs3[:6] == [re.purge,re.match,os.open, os.access,string_types[0].atoi,string_types[0].atof])
        
        cleanup_temp_dir(user_dir)
        cleanup_temp_dir(env_dir)