Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make conway updating considerably faster #6

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions conway.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ def conway(state, k=None):
b = fft_convolve2d(state,k).round()
c = np.zeros(b.shape)

c[np.where((b == 2) & (state == 1))] = 1
c[np.where((b == 3) & (state == 1))] = 1

c[np.where((b == 3) & (state == 0))] = 1
c[((b == 2) & (state == 1)) | (b == 3)] = 1

# return new state
return c
Expand Down
22 changes: 11 additions & 11 deletions lib/lib.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from numpy.fft import fft2, ifft2, fftshift
import numpy as np

def fft_convolve2d(x,y):
"""
2D convolution, using FFT
"""
fr = fft2(x)
fr2 = fft2(np.flipud(np.fliplr(y)))
m,n = fr.shape
cc = np.real(ifft2(fr*fr2))
cc = np.roll(cc, - int(m / 2) + 1, axis=0)
cc = np.roll(cc, - int(n / 2) + 1, axis=1)
return cc
"""
2D convolution, using FFT
"""
fr = fft2(x)
fr2 = fft2(np.flipud(np.fliplr(y)))
m,n = fr.shape
cc = np.real(ifft2(fr*fr2))
cc = np.roll(cc, - int(m / 2) + 1, axis=0)
cc = np.roll(cc, - int(n / 2) + 1, axis=1)
return cc