We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 781ad00 commit bb3e125Copy full SHA for bb3e125
e2e/mandelbrot/mandelbrot.png
82.9 KB
e2e/mandelbrot/mandelbrot.py
@@ -60,10 +60,11 @@ def sq2(a):
60
61
62
@torch.compile
63
-def step(n, c, Z, N, horizon):
64
- I = abs2(Z) < horizon**2
65
- N = np.where(I, n, N) # N[I] = n
66
- Z = np.where(I[..., None], sq2(Z) + c, Z) # Z[I] = Z[I]**2 + C[I]
+def step(n, c, Z, N, horizon, chunksize):
+ for _ in range(chunksize):
+ I = abs2(Z) < horizon**2
+ N = np.where(I, n, N) # N[I] = n
67
+ Z = np.where(I[..., None], sq2(Z) + c, Z) # Z[I] = Z[I]**2 + C[I]
68
return Z, N
69
70
@@ -75,8 +76,11 @@ def mandelbrot_c(xmin, xmax, ymin, ymax, xn, yn, horizon=2**10, maxiter=5):
75
76
N = np.zeros(c.shape[:-1], dtype='int')
77
Z = np.zeros_like(c, dtype='float32')
78
- for n in range(maxiter):
79
- Z, N = step(n, c, Z, N, horizon)
+ chunksize = 20
80
+ n_chunks = maxiter // chunksize
81
+
82
+ for n in range(n_chunks):
83
+ Z, N = step(n, c, Z, N, horizon, chunksize)
84
85
N = np.where(N == maxiter-1, 0, N) # N[N == maxiter-1] = 0
86
0 commit comments