-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmandelbrot.pyx
40 lines (35 loc) · 1.18 KB
/
mandelbrot.pyx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
cimport numpy as np
cimport cython
import numpy
cdef np.float64_t magnitude_squared(np.complex64_t z) nogil:
return z.real * z.real + z.imag * z.imag
@cython.boundscheck(False)
@cython.wraparound(False)
cpdef mandelbrot(np.complex64_t [:, :] in_coords,
np.uint32_t [:, :] out_counts,
int max_iterations=511):
cdef:
int i, j, iter
np.complex64_t c, z
with nogil:
for i in range(in_coords.shape[0]):
for j in range(in_coords.shape[1]):
c = in_coords[i, j]
z = 0
for iter in range(max_iterations):
if magnitude_squared(z) > 4:
break
z = z * z + c
out_counts[i, j] = iter
def mandelbrot_python(in_coords,
out_counts,
max_iterations=511):
for i in range(in_coords.shape[0]):
for j in range(in_coords.shape[1]):
c = in_coords[i, j]
z = 0
for iter in range(max_iterations):
if magnitude_squared(z) > 4:
break
z = z * z + c
out_counts[i, j] = iter