Skip to content

ENH: compute mask only once per iteration in fractals notebook #103

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

Merged
merged 1 commit into from
Aug 23, 2021
Merged
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
31 changes: 18 additions & 13 deletions content/tutorial-plotting-fractals.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,11 @@ def divergence_rate(mesh, num_iter=10, radius=2):
z = mesh.copy()
diverge_len = np.zeros(mesh.shape) # Keep tally of the number of iterations

# Iterate on element if and only if |element| < radius (Otherwise assume divergence)
for i in range(num_iter):
# Iterate on element if and only if |element| < radius (Otherwise assume divergence)
diverge_len[np.abs(z) < radius] += 1
z[np.abs(z) < radius] = f(z[np.abs(z) < radius])
conv_mask = np.abs(z) < radius
diverge_len[conv_mask] += 1
z[conv_mask] = f(z[conv_mask])

return diverge_len
```
Expand Down Expand Up @@ -252,8 +253,9 @@ def julia(mesh, c=-1, num_iter=10, radius=2):
diverge_len = np.zeros(z.shape)

for i in range(num_iter):
z[np.abs(z) < radius] = np.square(z[np.abs(z) < radius]) + c
diverge_len[np.abs(z) < radius] += 1
conv_mask = np.abs(z) < radius
z[conv_mask] = np.square(z[conv_mask]) + c
diverge_len[conv_mask] += 1

return diverge_len
```
Expand Down Expand Up @@ -325,8 +327,9 @@ def mandelbrot(mesh, num_iter=10, radius=2):
diverge_len = np.zeros(z.shape)

for i in range(num_iter):
z[np.abs(z) < radius] = np.square(z[np.abs(z) < radius]) + c[np.abs(z) < radius]
diverge_len[np.abs(z) < radius] += 1
conv_mask = np.abs(z) < radius
z[conv_mask] = np.square(z[conv_mask]) + c[conv_mask]
diverge_len[conv_mask] += 1

return diverge_len
```
Expand All @@ -349,8 +352,9 @@ def general_julia(mesh, c=-1, f=np.square, num_iter=100, radius=2):
diverge_len = np.zeros(z.shape)

for i in range(num_iter):
z[np.abs(z) < radius] = f(z[np.abs(z) < radius]) + c
diverge_len[np.abs(z) < radius] += 1
conv_mask = np.abs(z) < radius
z[conv_mask] = f(z[conv_mask]) + c
diverge_len[conv_mask] += 1

return diverge_len
```
Expand Down Expand Up @@ -391,10 +395,11 @@ def newton_fractal(mesh, f, df, num_iter=10, r=2):
diverge_len = np.zeros(z.shape)

for i in range(num_iter):
pz = f(z[np.abs(z) < r])
dp = df(z[np.abs(z) < r])
z[np.abs(z) < r] = z[np.abs(z) < r] - pz/dp
diverge_len[np.abs(z) < r] += 1
conv_mask = np.abs(z) < r
pz = f(z[conv_mask])
dp = df(z[conv_mask])
z[conv_mask] = z[conv_mask] - pz/dp
diverge_len[conv_mask] += 1

return diverge_len
```
Expand Down