def updateCache(self): # Import Psyco if available and not disabled import platform if platform.machine() in ['i386', 'i486', 'i586', 'i686']: if not self.configuration.disable_psyco: try: import psyco except ImportError: bb.msg.note(1, bb.msg.domain.Collection, "Psyco JIT Compiler (http://psyco.sf.net) not available. Install it to increase performance.") else: psyco.bind( self.parse_bbfiles ) else: bb.msg.note(1, bb.msg.domain.Collection, "You have disabled Psyco. This decreases performance.") self.status = bb.cache.CacheData() ignore = bb.data.getVar("ASSUME_PROVIDED", self.configuration.data, 1) or "" self.status.ignored_dependencies = Set( ignore.split() ) self.handleCollections( bb.data.getVar("BBFILE_COLLECTIONS", self.configuration.data, 1) ) bb.msg.debug(1, bb.msg.domain.Collection, "collecting .bb files") (filelist, masked) = self.collect_bbfiles() bb.data.renameVar("__depends", "__base_depends", self.configuration.data) self.parse_bbfiles(filelist, masked, self.myProgressCallback) bb.msg.debug(1, bb.msg.domain.Collection, "parsing complete") self.buildDepgraph()
def fbenchmark(f, var=[Symbol('x')]): """ Do some benchmarks with f using clambdify, lambdify and psyco. """ global cf, pf, psyf start = time() cf = clambdify(var, f) print 'compile time (including sympy overhead): %f s' % (time() - start) pf = lambdify(var, f, 'math') psyf = None try: import psyco psyf = lambdify(var, f, 'math') psyco.bind(psyf) except ImportError: pass code = '''for x in (i/1000. for i in xrange(1000)): f(%s)''' % ('x,'*len(var)).rstrip(',') t1 = Timer(code, 'from __main__ import cf as f') t2 = Timer(code, 'from __main__ import pf as f') if psyf: t3 = Timer(code, 'from __main__ import psyf as f') else: t3 = None print 'for x = (0, 1, 2, ..., 999)/1000' print '20 times in 3 runs' print 'compiled: %.4f %.4f %.4f' % tuple(t1.repeat(3, 20)) print 'Python lambda: %.4f %.4f %.4f' % tuple(t2.repeat(3, 20)) if t3: print 'Psyco lambda: %.4f %.4f %.4f' % tuple(t3.repeat(3, 20))
def fbenchmark(f, var=[Symbol("x")]): """ Do some benchmarks with f using clambdify, lambdify and psyco. """ global cf, pf, psyf start = time() cf = clambdify(var, f) print "compile time (including sympy overhead): %f s" % (time() - start) pf = lambdify(var, f, "math") psyf = None try: import psyco psyf = lambdify(var, f, "math") psyco.bind(psyf) except ImportError: pass code = """for x in (i/1000. for i in range(1000)): f(%s)""" % ( "x," * len(var) ).rstrip( "," ) t1 = Timer(code, "from __main__ import cf as f") t2 = Timer(code, "from __main__ import pf as f") if psyf: t3 = Timer(code, "from __main__ import psyf as f") else: t3 = None print "for x = (0, 1, 2, ..., 999)/1000" print "20 times in 3 runs" print "compiled: %.4f %.4f %.4f" % tuple(t1.repeat(3, 20)) print "Python lambda: %.4f %.4f %.4f" % tuple(t2.repeat(3, 20)) if t3: print "Psyco lambda: %.4f %.4f %.4f" % tuple(t3.repeat(3, 20))
def __init__(self, infile, debug=0, firstblock=None, lastblock=None) : """Initialize the generic parser.""" self.infile = infile self.debug = debug if firstblock is None : self.infile.seek(0) firstblock = self.infile.read(FIRSTBLOCKSIZE) try : self.infile.seek(-LASTBLOCKSIZE, 2) lastblock = self.infile.read(LASTBLOCKSIZE) except IOError : lastblock = "" self.infile.seek(0) self.firstblock = firstblock self.lastblock = lastblock if not self.isValid() : raise PDLParserError, "Invalid file format !" try : import psyco except ImportError : pass # Psyco is not installed else : # Psyco is installed, tell it to compile # the CPU intensive methods : PCL and PCLXL # parsing will greatly benefit from this, # for PostScript and PDF the difference is # barely noticeable since they are already # almost optimal, and much more speedy anyway. psyco.bind(self.getJobSize)
def main(n=1000, n_iter=100): print "Doing %d iterations on a %dx%d grid" % (n_iter, n, n) methods = [ 'numeric', 'blitz', 'inline', 'fastinline', ] # 'pyrex', #'fortran77', 'fortran90-arrays', 'fortran95-forall'] for i in methods: print i, sys.stdout.flush() print "took", time_test(n, n, stepper=i, n_iter=n_iter), "seconds" print "slow (1 iteration)", sys.stdout.flush() s = time_test(n, n, stepper='slow', n_iter=1) print "took", s, "seconds" print "%d iterations should take about %f seconds" % (n_iter, s * n_iter) try: import psyco except ImportError: print "You don't have Psyco installed!" else: psyco.bind(LaplaceSolver) psyco.bind(Grid) print "slow with Psyco (1 iteration)", sys.stdout.flush() s = time_test(n, n, stepper='slow', n_iter=1) print "took", s, "seconds" print "%d iterations should take about %f seconds"%\ (n_iter, s*n_iter)
def main(n=1000, n_iter=100): print "Doing %d iterations on a %dx%d grid" % (n_iter, n, n) methods = ["numeric", "blitz", "inline", "fastinline"] # 'pyrex', #'fortran77', 'fortran90-arrays', 'fortran95-forall'] for i in methods: print i, sys.stdout.flush() print "took", time_test(n, n, stepper=i, n_iter=n_iter), "seconds" print "slow (1 iteration)", sys.stdout.flush() s = time_test(n, n, stepper="slow", n_iter=1) print "took", s, "seconds" print "%d iterations should take about %f seconds" % (n_iter, s * n_iter) try: import psyco except ImportError: print "You don't have Psyco installed!" else: psyco.bind(LaplaceSolver) psyco.bind(Grid) print "slow with Psyco (1 iteration)", sys.stdout.flush() s = time_test(n, n, stepper="slow", n_iter=1) print "took", s, "seconds" print "%d iterations should take about %f seconds" % (n_iter, s * n_iter)
def main(n=500, n_iter=100): print "Doing %d iterations on a %dx%d grid"%(n_iter, n, n) for i in ['numeric', 'blitz', 'inline', 'fastinline', 'fortran', 'pyrex']: print i, sys.stdout.flush() print "took", time_test(n, n, stepper=i, n_iter=n_iter), "seconds" print "slow (1 iteration)", sys.stdout.flush() s = time_test(n, n, stepper='slow', n_iter=1) print "took", s, "seconds" print "%d iterations should take about %f seconds"%(n_iter, s*n_iter) try: import psyco except ImportError: print "You don't have Psyco installed!" else: psyco.bind(LaplaceSolver) psyco.bind(Grid) print "slow with Psyco (1 iteration)", sys.stdout.flush() s = time_test(n, n, stepper='slow', n_iter=1) print "took", s, "seconds" print "%d iterations should take about %f seconds"%\ (n_iter, s*n_iter)
def fbenchmark(f, var=[Symbol('x')]): """ Do some benchmarks with f using clambdify, lambdify and psyco. """ global cf, pf, psyf start = time() cf = clambdify(var, f) print 'compile time (including sympy overhead): %f s' % (time() - start) pf = lambdify(var, f, 'math') psyf = None try: import psyco psyf = lambdify(var, f, 'math') psyco.bind(psyf) except ImportError: pass code = '''for x in (i/1000. for i in range(1000)): f(%s)''' % ('x,' * len(var)).rstrip(',') t1 = Timer(code, 'from __main__ import cf as f') t2 = Timer(code, 'from __main__ import pf as f') if psyf: t3 = Timer(code, 'from __main__ import psyf as f') else: t3 = None print 'for x = (0, 1, 2, ..., 999)/1000' print '20 times in 3 runs' print 'compiled: %.4f %.4f %.4f' % tuple(t1.repeat(3, 20)) print 'Python lambda: %.4f %.4f %.4f' % tuple(t2.repeat(3, 20)) if t3: print 'Psyco lambda: %.4f %.4f %.4f' % tuple(t3.repeat(3, 20))
def updateCache(self): # Import Psyco if available and not disabled import platform if platform.machine() in ['i386', 'i486', 'i586', 'i686']: if not self.configuration.disable_psyco: try: import psyco except ImportError: bb.msg.note(1, bb.msg.domain.Collection, "Psyco JIT Compiler (http://psyco.sf.net) not available. Install it to increase performance.") else: psyco.bind( self.parse_bbfiles ) else: bb.msg.note(1, bb.msg.domain.Collection, "You have disabled Psyco. This decreases performance.") self.status = bb.cache.CacheData() ignore = bb.data.getVar("ASSUME_PROVIDED", self.configuration.data, 1) or "" self.status.ignored_dependencies = Set( ignore.split() ) self.handleCollections( bb.data.getVar("BBFILE_COLLECTIONS", self.configuration.data, 1) ) bb.msg.debug(1, bb.msg.domain.Collection, "collecting .bb files") (filelist, masked) = self.collect_bbfiles() self.parse_bbfiles(filelist, masked, self.myProgressCallback) bb.msg.debug(1, bb.msg.domain.Collection, "parsing complete") self.buildDepgraph()
def run(s, sockaddr, *args, **kw): try: import psyco except ImportError: pass else: psyco.bind(Playfield.update_sprites) Playfield(s, sockaddr).run(*args, **kw)
def optimize(self, functions): try: from psyco import bind for function in functions: bind(function) except ImportError: pass return False
def enable_psyco(template_class): try: import psyco except ImportError: pass else: psyco.bind(SpitfireTemplate) psyco.bind(template_class)
def psyco_speedup(): try: import psyco psyco.bind(chessboard) psyco.bind(evaluation) except: pass return 0
def psyco_speedup (): try: import psyco psyco.bind(chessboard) psyco.bind(evaluation) except: pass return 0
def test_circular_obj(): def f1(): x = Rect(5, 6) x.foo = x return x psyco.bind(f1) x = f1() assert x.foo is x
def __init__(self, *args): self.objimap = None apply(mailserver.MailServer.__init__, (self,) + args) try: # Psyco increase speed about a 40% here... psyco.bind(self.get_message) except NameError: pass
def __init__(self, *args): self.objpop = None self.deleted_msgs = [] apply(mailserver.MailServer.__init__, (self, ) + args) try: # Psyco increase speed about a 40% here... import psyco psyco.bind(self.get_message) except ImportError: pass
def __init__(self, *args): self.objpop = None self.deleted_msgs = [] apply(mailserver.MailServer.__init__, (self,) + args) try: # Psyco increase speed about a 40% here... import psyco psyco.bind(self.get_message) except ImportError: pass
def setup_psyco(): """ Оптимизировать узкие места в MrdDataSource с помощью psyco """ try: import psyco psyco.bind(MrdDataSource._calculate_endings) psyco.bind(MrdDataSource._load_lemmas) psyco.bind(MrdDataSource._cleanup_endings) psyco.bind(MrdDataSource._section_lines) psyco.bind(DictDataSource.calculate_rule_freq) except ImportError: pass
def __init__( self, redis_host='localhost', redis_port=6379, redis_db=0, ): self._REDIS_DELIM = '$' self._redis = redis.Redis(host=redis_host, port=redis_port, db=redis_db) try: import psyco psyco.bind(self.resolveUserInfoForKeys) print 'Using psyco to compile resolveUserInfoForKeys method' except ImportError, e: pass # psyco not installed
def speedup(): try: import psyco psyco.bind(disjointset) psyco.bind(vector2d) psyco.bind(line2d) psyco.bind(savebmp) except ImportError: pass
def updateCache(self): self.parseConfiguration() if self.cookerState == cookerParsed: return # Import Psyco if available and not disabled import platform if platform.machine() in ['i386', 'i486', 'i586', 'i686']: if not self.configuration.disable_psyco: try: import psyco except ImportError: bb.msg.note( 1, bb.msg.domain.Collection, "Psyco JIT Compiler (http://psyco.sf.net) not available. Install it to increase performance." ) else: psyco.bind(self.parse_bbfiles) else: bb.msg.note( 1, bb.msg.domain.Collection, "You have disabled Psyco. This decreases performance.") self.status = bb.cache.CacheData() ignore = bb.data.getVar("ASSUME_PROVIDED", self.configuration.data, 1) or "" self.status.ignored_dependencies = set(ignore.split()) for dep in self.configuration.extra_assume_provided: self.status.ignored_dependencies.add(dep) self.handleCollections( bb.data.getVar("BBFILE_COLLECTIONS", self.configuration.data, 1)) bb.msg.debug(1, bb.msg.domain.Collection, "collecting .bb files") (filelist, masked) = self.collect_bbfiles() bb.data.renameVar("__depends", "__base_depends", self.configuration.data) self.parse_bbfiles(filelist, masked) bb.msg.debug(1, bb.msg.domain.Collection, "parsing complete") self.buildDepgraph() self.cookerState = cookerParsed
def test_constant_obj(): def f1(): return rect1.w * rect1.h def f2(a): rect1.w = a psyco.bind(f1) psyco.bind(f2) rect1.w = 6 rect1.h = 7 res = f1() assert res == 42 f2(4) res = f1() assert res == 28 f2(0.5) res = f1() assert res == 3.5
def _psyco_speedup(): try: import psyco psyco.bind(rc4crypt) psyco.bind(netstream) psyco.bind(nethost) psyco.bind(CCLIB) except: return False return True
def accelerate_functions(): try: import psyco except ImportError: print "Psyco not found. Some features may run slowly." return print "Psyco found, accelerating functions." import bmh_search import behavior psyco.bind(bmh_search.BMHSearchForward) psyco.bind(bmh_search.BMHSearchBackward) import commands.save_and_load psyco.bind(commands.save_and_load.compressList) psyco.bind(behavior.BehaviorArray) psyco.bind(behavior.BehaviorArray._getBlankCommands)
def main(run, parse=one_arg_per_line, log='', precompile=None): if not isinstance(log, logging.Logger): log = logging.getLogger(log) globals().update(log=log) from optparse import OptionParser optparser = OptionParser(usage="%prog [-dtTn] [FILELIST]", version="%prog 0.1") optparser.add_option("-d", "--debug", action="store_true", help="log debug messages") optparser.add_option("-t", "--timer", action="store_true", help="log execution time") optparser.add_option("-T", "--test", action="store_true", help="run doctests instead of processing input") optparser.add_option("-n", "--nocompile", action="store_false", default=True, dest="precompile", help="do not precompile functions using psyco") options, args = optparser.parse_args() if options.debug: log.setLevel(logging.DEBUG) # globals().update(debug=log.debug) from sys import stderr globals().update(debug=lambda message: stderr.write( '# DEBUG: %s\n' % message)) # much faster if options.precompile: try: import psyco except ImportError, e: log.warning('psyco not imported: %s' % e) if precompile is None: precompile = [] elif not isinstance(precompile, list): precompile = list(precompile) precompile[0:0] = [run] log.info('precompiling using psyco: %s' % ', '.join([f.__name__ for f in precompile])) [psyco.bind(f) for f in precompile]
def __init__(self, primary, matrix, secondary=[]): if primary == []: raise RunTimeError("No primary columns!") if matrix == []: raise RunTimeError("No membership matrix") self.columns = primary + secondary for row in matrix: for col in row[:-1]: if not col in self.columns: raise ColumnError(col) self.nodes = {} self.headers = {} self.rows = {} self.updates = 0 self.solutions = [] self.setHeaders(primary, secondary) self.readRows(matrix) psyco.bind(self.backTrack)
def UsePsyco(): 'Tries to use psyco if it is installed' try: import psyco import elementtree.XMLTreeBuilder as XMLTreeBuilder import GCCXMLParser psyco.bind(XMLTreeBuilder.fixtext) psyco.bind(XMLTreeBuilder.fixname) psyco.bind(XMLTreeBuilder.TreeBuilder) psyco.bind(GCCXMLParser.GCCXMLParser) except ImportError: pass
def _start_psyco(self): """Enable psyco if the setting tells us to""" if self.coreSettings.usePsyco and Globals.USE_PSYCO: try: import psyco from gui.gtk.display import PriorityDisplay psyco.bind(PriorityDisplay.PriorityDisplay.update_completion) from BitTorrent.BT1 import PiecePicker, Downloader psyco.bind(PiecePicker.PiecePicker.next) psyco.bind(PiecePicker.PiecePicker.got_have) psyco.bind(Downloader.DownloadPeer.got_have_bitfield) except Exception, error: log_ex(error, "Failed to bind psyco optimizations!")
def bibrank_engine(run): """Run the indexing task. Return 1 in case of success and 0 in case of failure. """ try: import psyco psyco.bind(single_tag_rank) psyco.bind(single_tag_rank_method_exec) psyco.bind(serialize_via_marshal) psyco.bind(deserialize_via_marshal) except StandardError, e: pass
def _speedUp(): """ Speed up execution by importing Psyco and binding the slowest functions with it. """ try: import psyco psyco.bind(cake.engine.Configuration.checkDependencyInfo) psyco.bind(cake.engine.Configuration.createDependencyInfo) #psyco.full() #psyco.profile() #psyco.log() except ImportError: # Only report import failures on systems we know Psyco supports. version = platform.python_version_tuple() supportsVersion = version[0] == "2" and version[1] in ["5", "6"] if platform.system() == "Windows" and supportsVersion: sys.stderr.write( "warning: Psyco is not installed. Installing it may halve your incremental build time.\n" )
def __init__(self, primary, matrix, secondary = []): if primary == []: raise RunTimeError("No primary columns!") if matrix == []: raise RunTimeError("No membership matrix") self.columns = primary + secondary for row in matrix: for col in row[:-1]: if not col in self.columns: raise ColumnError(col) headers = {} # temporary dict used to construct self.matrix self.matrix = [] # "jagged array" of nodes: a list of lists of ones in the matrix self.rows = {} # symbolic names for the rows, indexed by row number self.root = Column() self.readColumns(primary, secondary, headers) # modifies headers self.readRows(headers, matrix) # initializes self.matrix and self.rows self.solutions = [] self.updates = 0 psyco.bind(self.backTrack)
def addMethods(self): # Add the auxiliary function specs to this Generator's namespace for auxfnname in self.funcspec.auxfns: fninfo = self.funcspec.auxfns[auxfnname] if not hasattr(self, fninfo[1]): # user-defined auxiliary functions # (built-ins are provided explicitly) if self._solver: fnstr = fninfo[0].replace(self._solver.name, 'ds._solver') ## self._funcreg[self._solver.name] = self._solver else: fnstr = fninfo[0] try: exec fnstr except: print 'Error in supplied auxiliary function code' self._funcreg[fninfo[1]] = ('self', fnstr) setattr(self, fninfo[1], types.MethodType(locals()[fninfo[1]], self, self.__class__)) # bind all the auxfns here if HAVE_PSYCO: psyco.bind(getattr(self, fninfo[1])) # Add the spec function to this Generator's namespace fninfo = self.funcspec.spec if self._solver: fnstr = fninfo[0].replace(self._solver.name, 'ds._solver') else: fnstr = fninfo[0] try: exec fnstr except: print 'Error in supplied functional specification code' raise self._funcreg[fninfo[1]] = ('self', fnstr) setattr(self, fninfo[1], types.MethodType(locals()[fninfo[1]], self, self.__class__)) if HAVE_PSYCO and not self._solver: psyco.bind(getattr(self, fninfo[1])) # Add the auxiliary spec function (if present) to this # Generator's namespace if self.funcspec.auxspec != '': fninfo = self.funcspec.auxspec if self._solver: fnstr = fninfo[0].replace(self._solver.name, 'ds._solver') else: fnstr = fninfo[0] try: exec fnstr except: print 'Error in supplied auxiliary variable code' raise self._funcreg[fninfo[1]] = ('self', fnstr) setattr(self, fninfo[1], types.MethodType(locals()[fninfo[1]], self, self.__class__)) if HAVE_PSYCO and not self._solver: psyco.bind(getattr(self, fninfo[1]))
def __init__(self, adress, name, passwd, port): self.nummesg = 0 # Bytes totales que quedan en el servidor x transferir: self.server_bytes_left = 0 self.totalserv = 0 self.downloaded = [] self.adress = adress self.name = name self.passwd = passwd self.port = port self.config = AnimailMain.Application.config self.num_trans = 0 self.deliverycount = 0 self.some_deleted = 0 self.info = {} self.lmsg = [] self.clean_session = 1 self.error_time = 0 try: psyco.bind(self.process_body) psyco.bind(self.look_message) except NameError: pass
def _psyco_speedup(): try: import psyco psyco.bind(rc4crypt) psyco.bind(NetStream) psyco.bind(NetHost) except: return False return True
def __init__(self, filename) : """Initializes the PDL analyzer. filename is the name of the file or '-' for stdin. filename can also be a file-like object which supports read() and seek(). """ self.filename = filename try : import psyco except ImportError : pass # Psyco is not installed else : # Psyco is installed, tell it to compile # the CPU intensive methods : PCL and PCLXL # parsing will greatly benefit from this, # for PostScript and PDF the difference is # barely noticeable since they are already # almost optimal, and much more speedy anyway. psyco.bind(PostScriptAnalyzer.getJobSize) psyco.bind(PDFAnalyzer.getJobSize) psyco.bind(ESCP2Analyzer.getJobSize) psyco.bind(PCLAnalyzer.getJobSize) psyco.bind(PCLXLAnalyzer.getJobSize)
def initInteractive(ipy, baselang): package = __name__[:__name__.rfind(".")] logix = sys.modules[package] ipy.locals['logix'] = logix global _ipy _ipy = ipy logix.init() # {{{ optimisations if 0: import psyco import compiler psyco.bind(language.Language) psyco.bind(compiler.pycodegen, rec=10) if 0: import optimize import compiler optimize.bind_all(compiler) optimize.bind_all(parser) # }}} if baselang: ipy.locals['__currentlang__'] = logix.baselang else: mod = logix.imp('%s.std' % package, {}) tmpstd = language.tmpLanguage(mod.std, '__main__') ipy.locals['__currentlang__'] = tmpstd ipy.locals[tmpstd.__impl__.name] = tmpstd logix.stdlang = mod.std print "(type logix.license for more information)" print "Welcome to Logix"
def addMethods(self, usePsyco=False): """Add Python-specific functions to this object's methods, accelerating them with psyco, if it is available.""" # Add the auxiliary function specs to this Generator's namespace for auxfnname in self.funcspec.auxfns: fninfo = self.funcspec.auxfns[auxfnname] if not hasattr(self, fninfo[1]): # user-defined auxiliary functions # (built-ins are provided explicitly) try: exec fninfo[0] except: print 'Error in supplied auxiliary function code' # print "\n", fninfo[0], "\n" self._funcreg[fninfo[1]] = ('self', fninfo[0]) #setattr(self.__class__, fninfo[1], eval(fninfo[1])) setattr(self, fninfo[1], types.MethodType(locals()[fninfo[1]], self, self.__class__)) # bind all the auxfns here if HAVE_PSYCO and usePsyco: psyco.bind(getattr(self, fninfo[1])) # Add the spec function to this Generator's namespace fninfo = self.funcspec.spec try: exec fninfo[0] except: print 'Error in supplied functional specification code' raise # print "\n", fninfo[0], "\n" self._funcreg[fninfo[1]] = ('self', fninfo[0]) setattr(self, fninfo[1], types.MethodType(locals()[fninfo[1]], self, self.__class__)) if HAVE_PSYCO and usePsyco: psyco.bind(getattr(self, fninfo[1])) # Add the auxiliary spec function (if present) to this # Generator's namespace if self.funcspec.auxspec != '': fninfo = self.funcspec.auxspec try: exec fninfo[0] except: print 'Error in supplied auxiliary variable code' raise # print "\n", fninfo[0], "\n" self._funcreg[fninfo[1]] = ('self', fninfo[0]) setattr(self, fninfo[1], types.MethodType(locals()[fninfo[1]], self, self.__class__)) if HAVE_PSYCO and usePsyco: psyco.bind(getattr(self, fninfo[1]))
def addMethods(self): # Add the auxiliary function specs to this Generator's namespace for auxfnname in self.funcspec.auxfns: fninfo = self.funcspec.auxfns[auxfnname] if not hasattr(self, fninfo[1]): # user-defined auxiliary functions # (built-ins are provided explicitly) if self._solver: fnstr = fninfo[0].replace(self._solver.name, "ds._solver") ## self._funcreg[self._solver.name] = self._solver else: fnstr = fninfo[0] try: exec fnstr except: print "Error in supplied auxiliary function code" self._funcreg[fninfo[1]] = ("self", fnstr) setattr(self, fninfo[1], types.MethodType(locals()[fninfo[1]], self, self.__class__)) # bind all the auxfns here if HAVE_PSYCO: psyco.bind(getattr(self, fninfo[1])) # Add the spec function to this Generator's namespace fninfo = self.funcspec.spec if self._solver: fnstr = fninfo[0].replace(self._solver.name, "ds._solver") else: fnstr = fninfo[0] try: exec fnstr except: print "Error in supplied functional specification code" raise self._funcreg[fninfo[1]] = ("self", fnstr) setattr(self, fninfo[1], types.MethodType(locals()[fninfo[1]], self, self.__class__)) if HAVE_PSYCO and not self._solver: psyco.bind(getattr(self, fninfo[1])) # Add the auxiliary spec function (if present) to this # Generator's namespace if self.funcspec.auxspec != "": fninfo = self.funcspec.auxspec if self._solver: fnstr = fninfo[0].replace(self._solver.name, "ds._solver") else: fnstr = fninfo[0] try: exec fnstr except: print "Error in supplied auxiliary variable code" raise self._funcreg[fninfo[1]] = ("self", fnstr) setattr(self, fninfo[1], types.MethodType(locals()[fninfo[1]], self, self.__class__)) if HAVE_PSYCO and not self._solver: psyco.bind(getattr(self, fninfo[1]))
def run(self, coord_x, coord_y): try: import gmpy coord_x = [gmpy.mpz(i) for i in coord_x] coord_y = [gmpy.mpz(i) for i in coord_y] except ImportError: warning("module gmpy not found") try: import psyco psyco.bind(self._run) psyco.bind(self.NevilleAlgorithm) psyco.bind(self.interpolate) except ImportError: warning("module psyco not found") return self._run(coord_x, coord_y)
def run(self, coord_x, coord_y) : try : import gmpy coord_x = [ gmpy.mpz(i) for i in coord_x ] coord_y = [ gmpy.mpz(i) for i in coord_y ] except ImportError : warning("module gmpy not found") try : import psyco psyco.bind(self._run) psyco.bind(self.NevilleAlgorithm) psyco.bind(self.interpolate) except ImportError : warning("module psyco not found") return self._run( coord_x, coord_y )
lerp( v, lerp(u, grad(p[AA], x, y, z), grad(p[BA], x - 1, y, z)), lerp(u, grad(p[AB], x, y - 1, z), grad(p[BB], x - 1, y - 1, z))), lerp( v, lerp(u, grad(p[AA + 1], x, y, z - 1), grad(p[BA + 1], x - 1, y, z - 1)), lerp(u, grad(p[AB + 1], x, y - 1, z - 1), grad(p[BB + 1], x - 1, y - 1, z - 1)))) # We may get lucky, there's a psyco patch for intel. try: import psyco psyco.bind(perlin) except: pass ###################################################################################################### def generate(x, y=0.0, z=0.0, width=1.0, height=1.0, depth=1.0, scale=1.0): """ Returns a random value between 0.0 and 1.0 Returns random Perlin noise in one, two or three dimensions. The random sequence is more naturally ordered (like a gradient) than normal random sequences. Noise is generated on an infinite plane, so the actual value of a coordinate is less important than the distance between
def __init__(self, iterations=1000, distance=1.0, layout=LAYOUT_SPRING): self.nodes = [] self.edges = [] self.root = None # Calculates positions for nodes. self.layout = layout_.__dict__[layout+"_layout"](self, iterations) self.d = node(None).r * 2.5 * distance # Hover, click and drag event handler. self.events = event.events(self, _ctx) # Enhanced dictionary of all styles. self.styles = style.styles(self) self.styles.append(style.style(style.DEFAULT, _ctx)) self.alpha = 0 # Try to specialize intensive math operations. try: import psyco psyco.bind(self.layout._bounds) psyco.bind(self.layout.iterate) psyco.bind(self.__or__) psyco.bind(cluster.flatten) psyco.bind(cluster.subgraph) psyco.bind(cluster.clique) psyco.bind(cluster.partition) psyco.bind(proximity.dijkstra_shortest_path) psyco.bind(proximity.brandes_betweenness_centrality) psyco.bind(proximity.eigenvector_centrality) psyco.bind(style.edge_arrow) psyco.bind(style.edge_label) #print "using psyco" except: pass
value = [] for arg in parser.rargs: # Stop on "--foo" like options but not on "--" alone. if arg[:2] == "--" and len(arg) > 2: break # Stop on "-a" like options but not on "-" alone. if arg[:1] == "-" and len(arg) > 1: break value.append(arg) # Delete the command line arguments we consumed so they're not parsed again. del parser.rargs[:len(value)] # Append the value to the destination list. destination.append(value) # ------------------------------------------------------------------------------ if __name__ == "__main__": try: import psyco psyco.bind(main) except ImportError: pass main(sys.argv)
fp.write(row + '\n') fp.flush() fp.write('\n') roomset = cm.roomset for root in roomset: room = roomset[root] center = room.center fp.write('AREA %d %d\n' % (center[0], center[1])) for e in entrances: fp.write('ENTRANCE %d %d\n' % (e[0], e[1])) fp.flush() try: import psyco psyco.bind(disjointset) psyco.bind(cavemake) except ImportError: pass if __name__ == '__main__': FILE = '-' WIDTH = 72 HEIGHT = 21 RATIO = 0.24 FAULT = -1 FRATIO = 0.4 FLOORS = '' ENTRANCE = 0 import time SEED = int(time.time())