forked from EskoSalaka/Fractals-py-cuda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kernels.py
93 lines (64 loc) · 2.64 KB
/
kernels.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
from numba import complex128
from cmath import isinf, sinh, cosh, exp, phase, log
from colors import *
@cuda.jit('complex128(complex128, float64)', device=True)
def power(z, x):
return abs(z) ** x * exp(phase(z) * x * complex128(1j))
@cuda.jit('complex128(complex128, complex128)', device=True)
def power(z, c):
return exp(c * log(z))
@cuda.jit('boolean(complex128, complex128)', device=True)
def is_close(a, b):
return abs(a-b) <= max(1e-9 * max(abs(a), abs(b)), 1e-9)
@cuda.jit('void(int8[:,:,:], complex128, float64, float64, int32)')
def exp_m(image_array, topleft, xstride, ystride, max_iter):
y, x = cuda.grid(2)
if x < image_array.shape[1] and y < image_array.shape[0]:
c = complex128(topleft + x * xstride - 1j * y * ystride)
z = c
i = 0
while i < max_iter and not isinf(z):
z = exp(z) + c
i += 1
get_log_color_rgb(image_array, x, y, i, max_iter)
@cuda.jit('void(int8[:,:,:], complex128, float64, float64, int32)')
def lambert(image_array, topleft, xstride, ystride, max_iter):
y, x = cuda.grid(2)
if x < image_array.shape[1] and y < image_array.shape[0]:
c = complex128(topleft + x * xstride - complex128(1j) * y * ystride)
c = exp(c * exp(-c))
z = c
o = complex128(0.0)
for i in range(max_iter):
z = power(c, z)
if isinf(z):
get_log_color_rgb(image_array, x, y, i, max_iter)
return
if is_close(z, o):
get_log_color_b(image_array, x, y, i, max_iter)
return
if i % 3 == 0:
o = z
@cuda.jit('void(int8[:,:,:], complex128, float64, float64, int32)')
def mandelbrot(image_array, topleft, xstride, ystride, max_iter):
y, x = cuda.grid(2)
if x < image_array.shape[1] and y < image_array.shape[0]:
c = complex128(topleft + x * xstride - 1j * y * ystride)
z = 0
i = 0
while i < max_iter and z.real * z.real + z.imag * z.imag < 4:
z = z * z + c
i += 1
get_log_color_rgb(image_array, x, y, i, max_iter)
@cuda.jit('void(int8[:,:,:], complex128, float64, float64, int32, int32, int32)')
def mandelbrot_split(image_array, topleft, xstride, ystride, max_iter, split_start, split_end):
y, x = cuda.grid(2)
y = y + split_start
if x < image_array.shape[1] and y < split_end:
c = complex128(topleft + x * xstride - 1j * y * ystride)
z = 0
i = 0
while i < max_iter and z.real * z.real + z.imag * z.imag < 4:
z = z * z + c
i += 1
get_log_color_rgb(image_array, x, y, i, max_iter)