10x speedup; still slightly off though
parent
e64dfa9e79
commit
94211ab723
|
@ -16,4 +16,4 @@ if __name__ == '__main__':
|
|||
p = cam_parser.CAMParser('B3/S23', c)
|
||||
|
||||
c.randomize()
|
||||
c.start_plot(100, p.ruleset)
|
||||
c.start_plot(50, p.ruleset)
|
||||
|
|
|
@ -45,14 +45,14 @@ class Neighborhood:
|
|||
|
||||
Offsetted cells belonging in the given neighborhood must be added separately.
|
||||
"""
|
||||
self.states = None
|
||||
self.bit_indices = None
|
||||
self.flat_indices = None
|
||||
|
||||
self.total = total
|
||||
self.bit_index = bit_index
|
||||
self.flat_index = flat_index
|
||||
|
||||
self.states = np.array([])
|
||||
self.bit_indices = np.array([])
|
||||
self.flat_indices = np.array([])
|
||||
|
||||
|
||||
def process_offsets(self, plane, offsets):
|
||||
"""
|
||||
|
@ -179,9 +179,9 @@ class Configuration:
|
|||
"""
|
||||
if not vfunc(plane, neighborhood, *args):
|
||||
return (False, None)
|
||||
elif callable(self.next_state):
|
||||
try:
|
||||
return (True, self.next_state(plane, neighborhood, *args))
|
||||
else:
|
||||
except TypeError:
|
||||
return (True, self.next_state)
|
||||
|
||||
|
||||
|
|
|
@ -95,10 +95,11 @@ class Ruleset:
|
|||
# Chunk into groups of 9 and sum all values
|
||||
# These summations represent the total number of active states in a given neighborhood
|
||||
totals = [0] * plane.N
|
||||
chunks = list(map(sum, [neighboring[i:i+9] for i in range(0, len(neighboring), 9)]))
|
||||
chunks = map(sum, [neighboring[i:i+9] for i in range(0, len(neighboring), 9)])
|
||||
for chunk in chunks:
|
||||
i_chunk = list(map(int, str(chunk).zfill(plane.N)))
|
||||
totals = list(map(sum, zip(totals, i_chunk)))
|
||||
i_chunk = map(int, str(chunk).zfill(plane.N))
|
||||
totals = map(sum, zip(totals, i_chunk))
|
||||
totals = list(totals)
|
||||
|
||||
# Determine which function should be used to test success
|
||||
if self.method == Ruleset.Method.MATCH:
|
||||
|
@ -111,6 +112,7 @@ class Ruleset:
|
|||
vfunc = lambda *args: True
|
||||
|
||||
# Apply change to all successful configurations
|
||||
|
||||
for bit_index in to_update:
|
||||
neighborhood = c.Neighborhood(flat_index, bit_index, totals[bit_index])
|
||||
success, state = config.passes(plane, neighborhood, vfunc, *args)
|
||||
|
|
Loading…
Reference in New Issue