Skip to content

Commit 5e6b658

Browse files
authored
PySplashsurf: f32 and f64 variants for tests (#232)
* Test both f32 and f64 for python tests * Remove development binary path
1 parent df35c49 commit 5e6b658

File tree

4 files changed

+123
-40
lines changed

4 files changed

+123
-40
lines changed

pysplashsurf/tests/test_basic.py

Lines changed: 55 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ def test_pipeline_f64():
108108
impl_basic_test(np.float64)
109109

110110

111-
def test_reconstruct():
112-
particles = np.array(meshio.read(VTK_PATH).points, dtype=np.float32)
111+
def reconstruct_test(dtype):
112+
particles = np.array(meshio.read(VTK_PATH).points, dtype=dtype)
113113

114114
reconstruction = pysplashsurf.reconstruct_surface(
115115
particles,
@@ -130,17 +130,25 @@ def test_reconstruct():
130130

131131
mesh = reconstruction.mesh
132132

133-
assert mesh.dtype == np.float32
133+
assert mesh.dtype == dtype
134134

135-
assert reconstruction.particle_densities.dtype == np.float32
135+
assert reconstruction.particle_densities.dtype == dtype
136136
assert len(reconstruction.particle_densities) == len(particles)
137137

138138
assert len(mesh.vertices) in range(25000, 30000)
139139
assert len(mesh.triangles) in range(49000, 53000)
140140

141141

142-
def test_neighborhood_search():
143-
particles = np.array(meshio.read(VTK_PATH).points, dtype=np.float32)
142+
def test_reconstruct_f32():
143+
reconstruct_test(np.float32)
144+
145+
146+
def test_reconstruct_f64():
147+
reconstruct_test(np.float64)
148+
149+
150+
def neighborhood_search_test(dtype):
151+
particles = np.array(meshio.read(VTK_PATH).points, dtype=dtype)
144152

145153
reconstruction = pysplashsurf.reconstruct_surface(
146154
particles,
@@ -174,8 +182,16 @@ def test_neighborhood_search():
174182
# TODO: Compare with naive neighbor search
175183

176184

177-
def test_check_consistency():
178-
particles = np.array(meshio.read(VTK_PATH).points, dtype=np.float32)
185+
def test_neighborhood_search_f32():
186+
neighborhood_search_test(np.float32)
187+
188+
189+
def test_neighborhood_search_f64():
190+
neighborhood_search_test(np.float64)
191+
192+
193+
def check_consistency_test(dtype):
194+
particles = np.array(meshio.read(VTK_PATH).points, dtype=dtype)
179195

180196
reconstruction = pysplashsurf.reconstruct_surface(
181197
particles,
@@ -208,8 +224,16 @@ def test_check_consistency():
208224
# TODO: Delete some triangles and check for failure
209225

210226

211-
def test_tris_to_quads():
212-
particles = np.array(meshio.read(VTK_PATH).points, dtype=np.float32)
227+
def test_check_consistency_f32():
228+
check_consistency_test(np.float32)
229+
230+
231+
def test_check_consistency_f64():
232+
check_consistency_test(np.float64)
233+
234+
235+
def tris_to_quads_test(dtype):
236+
particles = np.array(meshio.read(VTK_PATH).points, dtype=dtype)
213237

214238
mesh_with_data, reconstruction = pysplashsurf.reconstruction_pipeline(
215239
particles,
@@ -251,8 +275,16 @@ def test_tris_to_quads():
251275
assert "wnn" in mesh_with_data.point_attributes
252276

253277

254-
def test_interpolator():
255-
particles = np.array(meshio.read(VTK_PATH).points, dtype=np.float32)
278+
def test_tris_to_quads_f32():
279+
tris_to_quads_test(np.float32)
280+
281+
282+
def test_tris_to_quads_f64():
283+
tris_to_quads_test(np.float64)
284+
285+
286+
def interpolator_test(dtype):
287+
particles = np.array(meshio.read(VTK_PATH).points, dtype=dtype)
256288

257289
mesh_with_data, reconstruction = pysplashsurf.reconstruction_pipeline(
258290
particles,
@@ -280,20 +312,20 @@ def test_interpolator():
280312
)
281313

282314
assert type(mesh_densities) is np.ndarray
283-
assert mesh_densities.dtype == np.float32
315+
assert mesh_densities.dtype == dtype
284316
assert mesh_densities.shape == (len(mesh.vertices),)
285317
assert mesh_densities.min() >= 0.0
286318

287319
mesh_particles = interpolator.interpolate_quantity(particles, mesh.vertices)
288320

289321
assert type(mesh_particles) is np.ndarray
290-
assert mesh_particles.dtype == np.float32
322+
assert mesh_particles.dtype == dtype
291323
assert mesh_particles.shape == (len(mesh.vertices), 3)
292324

293325
mesh_sph_normals = interpolator.interpolate_normals(mesh.vertices)
294326

295327
assert type(mesh_sph_normals) is np.ndarray
296-
assert mesh_sph_normals.dtype == np.float32
328+
assert mesh_sph_normals.dtype == dtype
297329
assert mesh_sph_normals.shape == (len(mesh.vertices), 3)
298330

299331
mesh_with_data.add_point_attribute("density", mesh_densities)
@@ -307,3 +339,11 @@ def test_interpolator():
307339
assert np.array_equal(mesh_with_data.point_attributes["density"], mesh_densities)
308340
assert np.array_equal(mesh_with_data.point_attributes["position"], mesh_particles)
309341
assert np.array_equal(mesh_with_data.point_attributes["normal"], mesh_sph_normals)
342+
343+
344+
def test_interpolator_f32():
345+
interpolator_test(np.float32)
346+
347+
348+
def test_interpolator_f64():
349+
interpolator_test(np.float64)

pysplashsurf/tests/test_bgeo.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,15 @@
77
BGEO_PATH = DIR.joinpath("ParticleData_Fluid_50.bgeo")
88

99

10-
def test_bgeo():
11-
particles = np.array(meshio.read(BGEO_PATH).points, dtype=np.float32)
10+
def bgeo_test(dtype):
11+
particles = np.array(meshio.read(BGEO_PATH).points, dtype=dtype)
1212

1313
assert len(particles) == 4732
14+
15+
16+
def test_bgeo_f32():
17+
bgeo_test(np.float32)
18+
19+
20+
def test_bgeo_f64():
21+
bgeo_test(np.float64)

pysplashsurf/tests/test_calling.py

Lines changed: 48 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ def now_s():
1515
return time.process_time_ns() / (10**9)
1616

1717

18-
def test_marching_cubes_calls():
18+
def marching_cubes_calls(dtype):
1919
print("\nTesting marching cubes calls")
2020

21-
particles = np.array(meshio.read(VTK_PATH).points, dtype=np.float32)
21+
particles = np.array(meshio.read(VTK_PATH).points, dtype=dtype)
2222
reconstruction = pysplashsurf.reconstruct_surface(
2323
particles,
2424
particle_radius=0.025,
@@ -40,6 +40,14 @@ def test_marching_cubes_calls():
4040
assert verts_after < verts_before
4141

4242

43+
def test_marching_cubes_calls_f32():
44+
marching_cubes_calls(np.float32)
45+
46+
47+
def test_marching_cubes_calls_f64():
48+
marching_cubes_calls(np.float64)
49+
50+
4351
def reconstruction_pipeline(
4452
input_file,
4553
output_file,
@@ -76,9 +84,10 @@ def reconstruction_pipeline(
7684
quad_max_interior_angle=135.0,
7785
subdomain_grid=False,
7886
subdomain_num_cubes_per_dim=64,
87+
dtype
7988
):
8089
mesh = meshio.read(input_file)
81-
particles = np.array(mesh.points, dtype=np.float64)
90+
particles = np.array(mesh.points, dtype=dtype)
8291

8392
if attributes_to_interpolate is None:
8493
attributes_to_interpolate = []
@@ -88,7 +97,7 @@ def reconstruction_pipeline(
8897
for attr in attributes_to_interpolate:
8998
if attr in mesh.point_data:
9099
if mesh.point_data[attr].dtype.kind == "f":
91-
attrs[attr] = mesh.point_data[attr].astype(np.float64)
100+
attrs[attr] = mesh.point_data[attr].astype(dtype)
92101
else:
93102
attrs[attr] = mesh.point_data[attr].astype(np.int64)
94103

@@ -131,11 +140,11 @@ def reconstruction_pipeline(
131140
mesh_with_data.write_to_file(output_file)
132141

133142

134-
def test_no_post_processing():
143+
def no_post_processing_test(dtype):
135144
start = now_s()
136145
subprocess.run(
137146
[BINARY_PATH]
138-
+ f"reconstruct {VTK_PATH} -o {DIR.joinpath('test_bin.vtk')} -r=0.025 -l=2.0 -c=0.5 -t=0.6 -d=on --subdomain-grid=on --mesh-cleanup=off --mesh-smoothing-weights=off --mesh-smoothing-iters=0 --normals=off --normals-smoothing-iters=0".split(),
147+
+ f"reconstruct {VTK_PATH} -o {DIR.joinpath('test_bin.vtk')} -r=0.025 -l=2.0 -c=0.5 -t=0.6 {"-d=on" if dtype == np.float64 else ""} --subdomain-grid=on --mesh-cleanup=off --mesh-smoothing-weights=off --mesh-smoothing-iters=0 --normals=off --normals-smoothing-iters=0".split(),
139148
check=True,
140149
)
141150
print("Binary done in", now_s() - start)
@@ -144,24 +153,25 @@ def test_no_post_processing():
144153
reconstruction_pipeline(
145154
VTK_PATH,
146155
DIR.joinpath("test.vtk"),
147-
particle_radius=np.float64(0.025),
148-
smoothing_length=np.float64(2.0),
149-
cube_size=np.float64(0.5),
150-
iso_surface_threshold=np.float64(0.6),
156+
particle_radius=0.025,
157+
smoothing_length=2.0,
158+
cube_size=0.5,
159+
iso_surface_threshold=0.6,
151160
mesh_smoothing_weights=False,
152161
mesh_smoothing_iters=0,
153162
normals_smoothing_iters=0,
154163
mesh_cleanup=False,
155164
compute_normals=False,
156165
subdomain_grid=True,
166+
dtype=dtype
157167
)
158168
print("Python done in", now_s() - start)
159169

160170
binary_mesh = meshio.read(DIR.joinpath("test_bin.vtk"))
161171
python_mesh = meshio.read(DIR.joinpath("test.vtk"))
162172

163-
binary_verts = np.array(binary_mesh.points, dtype=np.float64)
164-
python_verts = np.array(python_mesh.points, dtype=np.float64)
173+
binary_verts = np.array(binary_mesh.points, dtype=dtype)
174+
python_verts = np.array(python_mesh.points, dtype=dtype)
165175

166176
print("# of vertices binary:", len(binary_verts))
167177
print("# of vertices python:", len(python_verts))
@@ -174,11 +184,19 @@ def test_no_post_processing():
174184
assert np.allclose(binary_verts, python_verts)
175185

176186

177-
def test_with_post_processing():
187+
def test_no_post_processing_f32():
188+
no_post_processing_test(np.float32)
189+
190+
191+
def test_no_post_processing_f64():
192+
no_post_processing_test(np.float64)
193+
194+
195+
def with_post_processing_test(dtype):
178196
start = now_s()
179197
subprocess.run(
180198
[BINARY_PATH]
181-
+ f"reconstruct {VTK_PATH} -o {DIR.joinpath('test_bin.vtk')} -r=0.025 -l=2.0 -c=0.5 -t=0.6 -d=on --subdomain-grid=on --interpolate_attribute velocity --decimate-barnacles=on --mesh-cleanup=on --mesh-smoothing-weights=on --mesh-smoothing-iters=25 --normals=on --normals-smoothing-iters=10 --output-smoothing-weights=on --generate-quads=off".split(),
199+
+ f"reconstruct {VTK_PATH} -o {DIR.joinpath('test_bin.vtk')} -r=0.025 -l=2.0 -c=0.5 -t=0.6 {"-d=on" if dtype == np.float64 else ""} --subdomain-grid=on --interpolate_attribute velocity --decimate-barnacles=on --mesh-cleanup=on --mesh-smoothing-weights=on --mesh-smoothing-iters=25 --normals=on --normals-smoothing-iters=10 --output-smoothing-weights=on --generate-quads=off".split(),
182200
check=True,
183201
)
184202
print("Binary done in", now_s() - start)
@@ -188,12 +206,12 @@ def test_with_post_processing():
188206
VTK_PATH,
189207
DIR.joinpath("test.vtk"),
190208
attributes_to_interpolate=["velocity"],
191-
particle_radius=np.float64(0.025),
192-
smoothing_length=np.float64(2.0),
193-
cube_size=np.float64(0.5),
194-
iso_surface_threshold=np.float64(0.6),
209+
particle_radius=0.025,
210+
smoothing_length=2.0,
211+
cube_size=0.5,
212+
iso_surface_threshold=0.6,
195213
mesh_smoothing_weights=True,
196-
mesh_smoothing_weights_normalization=np.float64(13.0),
214+
mesh_smoothing_weights_normalization=13.0,
197215
mesh_smoothing_iters=25,
198216
normals_smoothing_iters=10,
199217
generate_quads=False,
@@ -203,15 +221,16 @@ def test_with_post_processing():
203221
decimate_barnacles=True,
204222
output_mesh_smoothing_weights=True,
205223
output_raw_normals=True,
224+
dtype=dtype
206225
)
207226
print("Python done in", now_s() - start)
208227

209228
binary_mesh = meshio.read(DIR.joinpath("test_bin.vtk"))
210229
python_mesh = meshio.read(DIR.joinpath("test.vtk"))
211230

212231
# Compare number of vertices
213-
binary_verts = np.array(binary_mesh.points, dtype=np.float64)
214-
python_verts = np.array(python_mesh.points, dtype=np.float64)
232+
binary_verts = np.array(binary_mesh.points, dtype=dtype)
233+
python_verts = np.array(python_mesh.points, dtype=dtype)
215234

216235
print("# of vertices binary:", len(binary_verts))
217236
print("# of vertices python:", len(python_verts))
@@ -249,3 +268,11 @@ def test_with_post_processing():
249268
print("Python verts:", python_verts)
250269

251270
assert np.allclose(binary_verts, python_verts)
271+
272+
273+
def test_with_post_processing_f32():
274+
with_post_processing_test(np.float32)
275+
276+
277+
def test_with_post_processing_f64():
278+
with_post_processing_test(np.float64)

pysplashsurf/tests/test_sdf.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import numpy as np
33

44

5-
def test_sphere_sdf_mc():
5+
def sphere_sdf_mc_test(dtype):
66
radius = 1.0
77
num_verts = 100
88

@@ -12,7 +12,7 @@ def test_sphere_sdf_mc():
1212
translation = -0.5 * grid_size
1313

1414
def make_sdf():
15-
coords = np.arange(num_verts, dtype=np.float32) * dx + translation
15+
coords = np.arange(num_verts, dtype=dtype) * dx + translation
1616
x, y, z = np.meshgrid(coords, coords, coords, indexing="ij")
1717
sdf = np.sqrt(x**2 + y**2 + z**2) - radius
1818
return sdf
@@ -31,3 +31,11 @@ def make_sdf():
3131
assert norms.max() < radius + 1e-4
3232

3333
assert pysplashsurf.check_mesh_consistency(mesh, grid) is None
34+
35+
36+
def test_sphere_sdf_mc_f32():
37+
sphere_sdf_mc_test(np.float32)
38+
39+
40+
def test_sphere_sdf_mc_f64():
41+
sphere_sdf_mc_test(np.float64)

0 commit comments

Comments
 (0)