-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
47 lines (41 loc) · 1.27 KB
/
test.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
import shaysweep
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
import time
from drjit.cuda import TensorXf
import fastsweep
def show(fig, phi):
from matplotlib import colors
divnorm = colors.TwoSlopeNorm(vmin=-0.005, vcenter=0.0, vmax=0.005)
img = fig.imshow(phi.T, origin="lower", animated=True,
cmap='PiYG', norm=divnorm) # , interpolation="antialiased")
phinp = phi
print(f"phi max = {np.max(phinp)}, min = {np.min(phinp)}")
def test():
r = shaysweep.Redistance(3)
res = 128
phi = np.zeros((res, res, res))
h = 1.0 / phi.shape[0]
scale = h / 2
# scale =
phi[:] = 1.0 * scale
phi[:, : res // 2, :] = -1.0 * scale
# r.redistance_3d(phi, h, 0)
init = phi.copy()
start = time.time()
phi = r.redistance_rb(phi, h, 1)
end = time.time()
start_0 = time.time()
# init_ = TensorXf(init)
# ref = fastsweep.redistance(init_).numpy()
ref = r.redistance_3d(init, h, 1)
end_0 = time.time()
fig, (ax1, ax2) = plt.subplots(1, 2)
err = ref - phi
print(f"max error = {np.max(np.abs(err))}")
show(ax1, phi[res // 2, :, :])
show(ax2, err[res // 2, :, :])
plt.show()
print(f"time = {end -start}s, ref = {end_0 - start_0}")
test()