Skip to content

Commit

Permalink
Merge pull request #4 from bh107/wireworld-fix
Browse files Browse the repository at this point in the history
Fix Wireworld to work with NumPy 1.10.4
  • Loading branch information
madsbk committed Feb 19, 2016
2 parents e36505b + 29781a4 commit cb25671
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions benchmarks/wireworld/python_numpy/wireworld.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,19 @@ def wireworld_init(size):
def wireworld(world, iterations):
"""TODO: Describe the benchmark."""

sim = no_border(world, 1) # Active Machine
stencil = D2P8(world) # Stencil for counting heads
sim = no_border(world, 1) # Active Machine
stencil = D2P8(world) # Stencil for counting heads
NC = sum([v==2 for v in stencil]) # Count number of head neighbors
for _ in xrange(iterations):
NC = sum([v==2 for v in stencil]) # Count number of head neighbors
# Mask conductor->head
MASK = ((NC==1) & (sim==8)) | ((NC==2) & (sim==8))
sim *= ~MASK # New head pos->0
sim += MASK * 1 # New head pos->1
MASK = (sim==8) # Mask non conductors
sim *= ~MASK # conductors->0
sim += MASK * 4 # conductors->4
sim *= 2 # Upgrade all to new state

sim *= ~MASK # New head pos->0
sim += np.array(MASK * 1, np.uint8) # New head pos->1
MASK = (sim==8) # Mask non conductors
sim *= ~MASK # conductors->0
sim += np.array(MASK * 4, np.uint8) # conductors->4
sim *= 2 # Upgrade all to new state

util.Benchmark().flush()

Expand Down

0 comments on commit cb25671

Please sign in to comment.