Code speedup tips

Andrew Henshaw andrew.henshaw at gtri.gatech.edu
Sun Mar 2 04:48:35 CET 2003


Carl Banks wrote:

> Sean Richards wrote:
>> Hi,
> 
...snip...

>         # Apply the rule
>         for step in xrange(Steps):
>             # In the workspace, add the shifted lattices
>             # This uses a bunch of += because it's faster
>             workspace[:] = left
>             workspace[:] += up
>             workspace[:] += right
>             workspace[:] += down
>             # Set the current lattice
>             current[1:-1,1:-1] = where(workspace,1,0)
> 

You also might want to use bitwise or, so that you can elimnate the 'where' 
step

         # Apply the rule
         for step in xrange(Steps):
             workspace[:] = left
             workspace[:] |= up
             workspace[:] |= right
             workspace[:] |= down
             # Set the current lattice
             current[1:-1,1:-1] = workspace





More information about the Python-list mailing list