warp-lang 1.0.1__py3-none-macosx_10_13_universal2.whl → 1.1.0__py3-none-macosx_10_13_universal2.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of warp-lang might be problematic. Click here for more details.
- warp/__init__.py +108 -97
- warp/__init__.pyi +1 -1
- warp/bin/libwarp-clang.dylib +0 -0
- warp/bin/libwarp.dylib +0 -0
- warp/build.py +115 -113
- warp/build_dll.py +383 -375
- warp/builtins.py +3425 -3354
- warp/codegen.py +2878 -2792
- warp/config.py +40 -36
- warp/constants.py +45 -45
- warp/context.py +5194 -5102
- warp/dlpack.py +442 -442
- warp/examples/__init__.py +16 -16
- warp/examples/assets/bear.usd +0 -0
- warp/examples/assets/bunny.usd +0 -0
- warp/examples/assets/cartpole.urdf +110 -110
- warp/examples/assets/crazyflie.usd +0 -0
- warp/examples/assets/cube.usd +0 -0
- warp/examples/assets/nv_ant.xml +92 -92
- warp/examples/assets/nv_humanoid.xml +183 -183
- warp/examples/assets/quadruped.urdf +267 -267
- warp/examples/assets/rocks.nvdb +0 -0
- warp/examples/assets/rocks.usd +0 -0
- warp/examples/assets/sphere.usd +0 -0
- warp/examples/benchmarks/benchmark_api.py +383 -383
- warp/examples/benchmarks/benchmark_cloth.py +278 -279
- warp/examples/benchmarks/benchmark_cloth_cupy.py +88 -88
- warp/examples/benchmarks/benchmark_cloth_jax.py +97 -100
- warp/examples/benchmarks/benchmark_cloth_numba.py +146 -142
- warp/examples/benchmarks/benchmark_cloth_numpy.py +77 -77
- warp/examples/benchmarks/benchmark_cloth_pytorch.py +86 -86
- warp/examples/benchmarks/benchmark_cloth_taichi.py +112 -112
- warp/examples/benchmarks/benchmark_cloth_warp.py +146 -146
- warp/examples/benchmarks/benchmark_launches.py +295 -295
- warp/examples/browse.py +29 -28
- warp/examples/core/example_dem.py +234 -221
- warp/examples/core/example_fluid.py +293 -267
- warp/examples/core/example_graph_capture.py +144 -129
- warp/examples/core/example_marching_cubes.py +188 -176
- warp/examples/core/example_mesh.py +174 -154
- warp/examples/core/example_mesh_intersect.py +205 -193
- warp/examples/core/example_nvdb.py +176 -169
- warp/examples/core/example_raycast.py +105 -89
- warp/examples/core/example_raymarch.py +199 -178
- warp/examples/core/example_render_opengl.py +185 -141
- warp/examples/core/example_sph.py +405 -389
- warp/examples/core/example_torch.py +222 -181
- warp/examples/core/example_wave.py +263 -249
- warp/examples/fem/bsr_utils.py +378 -380
- warp/examples/fem/example_apic_fluid.py +407 -391
- warp/examples/fem/example_convection_diffusion.py +182 -168
- warp/examples/fem/example_convection_diffusion_dg.py +219 -209
- warp/examples/fem/example_convection_diffusion_dg0.py +204 -194
- warp/examples/fem/example_deformed_geometry.py +177 -159
- warp/examples/fem/example_diffusion.py +201 -173
- warp/examples/fem/example_diffusion_3d.py +177 -152
- warp/examples/fem/example_diffusion_mgpu.py +221 -214
- warp/examples/fem/example_mixed_elasticity.py +244 -222
- warp/examples/fem/example_navier_stokes.py +259 -243
- warp/examples/fem/example_stokes.py +220 -192
- warp/examples/fem/example_stokes_transfer.py +265 -249
- warp/examples/fem/mesh_utils.py +133 -109
- warp/examples/fem/plot_utils.py +292 -287
- warp/examples/optim/example_bounce.py +260 -248
- warp/examples/optim/example_cloth_throw.py +222 -210
- warp/examples/optim/example_diffray.py +566 -535
- warp/examples/optim/example_drone.py +864 -835
- warp/examples/optim/example_inverse_kinematics.py +176 -169
- warp/examples/optim/example_inverse_kinematics_torch.py +185 -170
- warp/examples/optim/example_spring_cage.py +239 -234
- warp/examples/optim/example_trajectory.py +223 -201
- warp/examples/optim/example_walker.py +306 -292
- warp/examples/sim/example_cartpole.py +139 -128
- warp/examples/sim/example_cloth.py +196 -184
- warp/examples/sim/example_granular.py +124 -113
- warp/examples/sim/example_granular_collision_sdf.py +197 -185
- warp/examples/sim/example_jacobian_ik.py +236 -213
- warp/examples/sim/example_particle_chain.py +118 -106
- warp/examples/sim/example_quadruped.py +193 -179
- warp/examples/sim/example_rigid_chain.py +197 -189
- warp/examples/sim/example_rigid_contact.py +189 -176
- warp/examples/sim/example_rigid_force.py +127 -126
- warp/examples/sim/example_rigid_gyroscopic.py +109 -97
- warp/examples/sim/example_rigid_soft_contact.py +134 -124
- warp/examples/sim/example_soft_body.py +190 -178
- warp/fabric.py +337 -335
- warp/fem/__init__.py +60 -27
- warp/fem/cache.py +401 -388
- warp/fem/dirichlet.py +178 -179
- warp/fem/domain.py +262 -263
- warp/fem/field/__init__.py +100 -101
- warp/fem/field/field.py +148 -149
- warp/fem/field/nodal_field.py +298 -299
- warp/fem/field/restriction.py +22 -21
- warp/fem/field/test.py +180 -181
- warp/fem/field/trial.py +183 -183
- warp/fem/geometry/__init__.py +15 -19
- warp/fem/geometry/closest_point.py +69 -70
- warp/fem/geometry/deformed_geometry.py +270 -271
- warp/fem/geometry/element.py +744 -744
- warp/fem/geometry/geometry.py +184 -186
- warp/fem/geometry/grid_2d.py +380 -373
- warp/fem/geometry/grid_3d.py +441 -435
- warp/fem/geometry/hexmesh.py +953 -953
- warp/fem/geometry/partition.py +374 -376
- warp/fem/geometry/quadmesh_2d.py +532 -532
- warp/fem/geometry/tetmesh.py +840 -840
- warp/fem/geometry/trimesh_2d.py +577 -577
- warp/fem/integrate.py +1630 -1615
- warp/fem/operator.py +190 -191
- warp/fem/polynomial.py +214 -213
- warp/fem/quadrature/__init__.py +2 -2
- warp/fem/quadrature/pic_quadrature.py +243 -245
- warp/fem/quadrature/quadrature.py +295 -294
- warp/fem/space/__init__.py +294 -292
- warp/fem/space/basis_space.py +488 -489
- warp/fem/space/collocated_function_space.py +100 -105
- warp/fem/space/dof_mapper.py +236 -236
- warp/fem/space/function_space.py +148 -145
- warp/fem/space/grid_2d_function_space.py +267 -267
- warp/fem/space/grid_3d_function_space.py +305 -306
- warp/fem/space/hexmesh_function_space.py +350 -352
- warp/fem/space/partition.py +350 -350
- warp/fem/space/quadmesh_2d_function_space.py +368 -369
- warp/fem/space/restriction.py +158 -160
- warp/fem/space/shape/__init__.py +13 -15
- warp/fem/space/shape/cube_shape_function.py +738 -738
- warp/fem/space/shape/shape_function.py +102 -103
- warp/fem/space/shape/square_shape_function.py +611 -611
- warp/fem/space/shape/tet_shape_function.py +565 -567
- warp/fem/space/shape/triangle_shape_function.py +429 -429
- warp/fem/space/tetmesh_function_space.py +294 -292
- warp/fem/space/topology.py +297 -295
- warp/fem/space/trimesh_2d_function_space.py +223 -221
- warp/fem/types.py +77 -77
- warp/fem/utils.py +495 -495
- warp/jax.py +166 -141
- warp/jax_experimental.py +341 -339
- warp/native/array.h +1072 -1025
- warp/native/builtin.h +1560 -1560
- warp/native/bvh.cpp +398 -398
- warp/native/bvh.cu +525 -525
- warp/native/bvh.h +429 -429
- warp/native/clang/clang.cpp +495 -464
- warp/native/crt.cpp +31 -31
- warp/native/crt.h +334 -334
- warp/native/cuda_crt.h +1049 -1049
- warp/native/cuda_util.cpp +549 -540
- warp/native/cuda_util.h +288 -203
- warp/native/cutlass_gemm.cpp +34 -34
- warp/native/cutlass_gemm.cu +372 -372
- warp/native/error.cpp +66 -66
- warp/native/error.h +27 -27
- warp/native/fabric.h +228 -228
- warp/native/hashgrid.cpp +301 -278
- warp/native/hashgrid.cu +78 -77
- warp/native/hashgrid.h +227 -227
- warp/native/initializer_array.h +32 -32
- warp/native/intersect.h +1204 -1204
- warp/native/intersect_adj.h +365 -365
- warp/native/intersect_tri.h +322 -322
- warp/native/marching.cpp +2 -2
- warp/native/marching.cu +497 -497
- warp/native/marching.h +2 -2
- warp/native/mat.h +1498 -1498
- warp/native/matnn.h +333 -333
- warp/native/mesh.cpp +203 -203
- warp/native/mesh.cu +293 -293
- warp/native/mesh.h +1887 -1887
- warp/native/nanovdb/NanoVDB.h +4782 -4782
- warp/native/nanovdb/PNanoVDB.h +2553 -2553
- warp/native/nanovdb/PNanoVDBWrite.h +294 -294
- warp/native/noise.h +850 -850
- warp/native/quat.h +1084 -1084
- warp/native/rand.h +299 -299
- warp/native/range.h +108 -108
- warp/native/reduce.cpp +156 -156
- warp/native/reduce.cu +348 -348
- warp/native/runlength_encode.cpp +61 -61
- warp/native/runlength_encode.cu +46 -46
- warp/native/scan.cpp +30 -30
- warp/native/scan.cu +36 -36
- warp/native/scan.h +7 -7
- warp/native/solid_angle.h +442 -442
- warp/native/sort.cpp +94 -94
- warp/native/sort.cu +97 -97
- warp/native/sort.h +14 -14
- warp/native/sparse.cpp +337 -337
- warp/native/sparse.cu +544 -544
- warp/native/spatial.h +630 -630
- warp/native/svd.h +562 -562
- warp/native/temp_buffer.h +30 -30
- warp/native/vec.h +1132 -1132
- warp/native/volume.cpp +297 -297
- warp/native/volume.cu +32 -32
- warp/native/volume.h +538 -538
- warp/native/volume_builder.cu +425 -425
- warp/native/volume_builder.h +19 -19
- warp/native/warp.cpp +1057 -1052
- warp/native/warp.cu +2943 -2828
- warp/native/warp.h +313 -305
- warp/optim/__init__.py +9 -9
- warp/optim/adam.py +120 -120
- warp/optim/linear.py +1104 -939
- warp/optim/sgd.py +104 -92
- warp/render/__init__.py +10 -10
- warp/render/render_opengl.py +3217 -3204
- warp/render/render_usd.py +768 -749
- warp/render/utils.py +152 -150
- warp/sim/__init__.py +52 -59
- warp/sim/articulation.py +685 -685
- warp/sim/collide.py +1594 -1590
- warp/sim/import_mjcf.py +489 -481
- warp/sim/import_snu.py +220 -221
- warp/sim/import_urdf.py +536 -516
- warp/sim/import_usd.py +887 -881
- warp/sim/inertia.py +316 -317
- warp/sim/integrator.py +234 -233
- warp/sim/integrator_euler.py +1956 -1956
- warp/sim/integrator_featherstone.py +1910 -1991
- warp/sim/integrator_xpbd.py +3294 -3312
- warp/sim/model.py +4473 -4314
- warp/sim/particles.py +113 -112
- warp/sim/render.py +417 -403
- warp/sim/utils.py +413 -410
- warp/sparse.py +1227 -1227
- warp/stubs.py +2109 -2469
- warp/tape.py +1162 -225
- warp/tests/__init__.py +1 -1
- warp/tests/__main__.py +4 -4
- warp/tests/assets/torus.usda +105 -105
- warp/tests/aux_test_class_kernel.py +26 -26
- warp/tests/aux_test_compile_consts_dummy.py +10 -10
- warp/tests/aux_test_conditional_unequal_types_kernels.py +21 -21
- warp/tests/aux_test_dependent.py +22 -22
- warp/tests/aux_test_grad_customs.py +23 -23
- warp/tests/aux_test_reference.py +11 -11
- warp/tests/aux_test_reference_reference.py +10 -10
- warp/tests/aux_test_square.py +17 -17
- warp/tests/aux_test_unresolved_func.py +14 -14
- warp/tests/aux_test_unresolved_symbol.py +14 -14
- warp/tests/disabled_kinematics.py +239 -239
- warp/tests/run_coverage_serial.py +31 -31
- warp/tests/test_adam.py +157 -157
- warp/tests/test_arithmetic.py +1124 -1124
- warp/tests/test_array.py +2417 -2326
- warp/tests/test_array_reduce.py +150 -150
- warp/tests/test_async.py +668 -656
- warp/tests/test_atomic.py +141 -141
- warp/tests/test_bool.py +204 -149
- warp/tests/test_builtins_resolution.py +1292 -1292
- warp/tests/test_bvh.py +164 -171
- warp/tests/test_closest_point_edge_edge.py +228 -228
- warp/tests/test_codegen.py +566 -553
- warp/tests/test_compile_consts.py +97 -101
- warp/tests/test_conditional.py +246 -246
- warp/tests/test_copy.py +232 -215
- warp/tests/test_ctypes.py +632 -632
- warp/tests/test_dense.py +67 -67
- warp/tests/test_devices.py +91 -98
- warp/tests/test_dlpack.py +530 -529
- warp/tests/test_examples.py +400 -378
- warp/tests/test_fabricarray.py +955 -955
- warp/tests/test_fast_math.py +62 -54
- warp/tests/test_fem.py +1277 -1278
- warp/tests/test_fp16.py +130 -130
- warp/tests/test_func.py +338 -337
- warp/tests/test_generics.py +571 -571
- warp/tests/test_grad.py +746 -640
- warp/tests/test_grad_customs.py +333 -336
- warp/tests/test_hash_grid.py +210 -164
- warp/tests/test_import.py +39 -39
- warp/tests/test_indexedarray.py +1134 -1134
- warp/tests/test_intersect.py +67 -67
- warp/tests/test_jax.py +307 -307
- warp/tests/test_large.py +167 -164
- warp/tests/test_launch.py +354 -354
- warp/tests/test_lerp.py +261 -261
- warp/tests/test_linear_solvers.py +191 -171
- warp/tests/test_lvalue.py +421 -493
- warp/tests/test_marching_cubes.py +65 -65
- warp/tests/test_mat.py +1801 -1827
- warp/tests/test_mat_lite.py +115 -115
- warp/tests/test_mat_scalar_ops.py +2907 -2889
- warp/tests/test_math.py +126 -193
- warp/tests/test_matmul.py +500 -499
- warp/tests/test_matmul_lite.py +410 -410
- warp/tests/test_mempool.py +188 -190
- warp/tests/test_mesh.py +284 -324
- warp/tests/test_mesh_query_aabb.py +228 -241
- warp/tests/test_mesh_query_point.py +692 -702
- warp/tests/test_mesh_query_ray.py +292 -303
- warp/tests/test_mlp.py +276 -276
- warp/tests/test_model.py +110 -110
- warp/tests/test_modules_lite.py +39 -39
- warp/tests/test_multigpu.py +163 -163
- warp/tests/test_noise.py +248 -248
- warp/tests/test_operators.py +250 -250
- warp/tests/test_options.py +123 -125
- warp/tests/test_peer.py +133 -137
- warp/tests/test_pinned.py +78 -78
- warp/tests/test_print.py +54 -54
- warp/tests/test_quat.py +2086 -2086
- warp/tests/test_rand.py +288 -288
- warp/tests/test_reload.py +217 -217
- warp/tests/test_rounding.py +179 -179
- warp/tests/test_runlength_encode.py +190 -190
- warp/tests/test_sim_grad.py +243 -0
- warp/tests/test_sim_kinematics.py +91 -97
- warp/tests/test_smoothstep.py +168 -168
- warp/tests/test_snippet.py +305 -266
- warp/tests/test_sparse.py +468 -460
- warp/tests/test_spatial.py +2148 -2148
- warp/tests/test_streams.py +486 -473
- warp/tests/test_struct.py +710 -675
- warp/tests/test_tape.py +173 -148
- warp/tests/test_torch.py +743 -743
- warp/tests/test_transient_module.py +87 -87
- warp/tests/test_types.py +556 -659
- warp/tests/test_utils.py +490 -499
- warp/tests/test_vec.py +1264 -1268
- warp/tests/test_vec_lite.py +73 -73
- warp/tests/test_vec_scalar_ops.py +2099 -2099
- warp/tests/test_verify_fp.py +94 -94
- warp/tests/test_volume.py +737 -736
- warp/tests/test_volume_write.py +255 -265
- warp/tests/unittest_serial.py +37 -37
- warp/tests/unittest_suites.py +363 -359
- warp/tests/unittest_utils.py +603 -578
- warp/tests/unused_test_misc.py +71 -71
- warp/tests/walkthrough_debug.py +85 -85
- warp/thirdparty/appdirs.py +598 -598
- warp/thirdparty/dlpack.py +143 -143
- warp/thirdparty/unittest_parallel.py +566 -561
- warp/torch.py +321 -295
- warp/types.py +4504 -4450
- warp/utils.py +1008 -821
- {warp_lang-1.0.1.dist-info → warp_lang-1.1.0.dist-info}/LICENSE.md +126 -126
- {warp_lang-1.0.1.dist-info → warp_lang-1.1.0.dist-info}/METADATA +338 -400
- warp_lang-1.1.0.dist-info/RECORD +352 -0
- warp/examples/assets/cube.usda +0 -42
- warp/examples/assets/sphere.usda +0 -56
- warp/examples/assets/torus.usda +0 -105
- warp_lang-1.0.1.dist-info/RECORD +0 -352
- {warp_lang-1.0.1.dist-info → warp_lang-1.1.0.dist-info}/WHEEL +0 -0
- {warp_lang-1.0.1.dist-info → warp_lang-1.1.0.dist-info}/top_level.txt +0 -0
warp/tests/test_volume.py
CHANGED
|
@@ -1,736 +1,737 @@
|
|
|
1
|
-
# Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved.
|
|
2
|
-
# NVIDIA CORPORATION and its licensors retain all intellectual property
|
|
3
|
-
# and proprietary rights in and to this software, related documentation
|
|
4
|
-
# and any modifications thereto. Any use, reproduction, disclosure or
|
|
5
|
-
# distribution of this software and related documentation without an express
|
|
6
|
-
# license agreement from NVIDIA CORPORATION is strictly prohibited.
|
|
7
|
-
|
|
8
|
-
import unittest
|
|
9
|
-
|
|
10
|
-
import numpy as np
|
|
11
|
-
|
|
12
|
-
import warp as wp
|
|
13
|
-
from warp.tests.unittest_utils import *
|
|
14
|
-
|
|
15
|
-
wp.init()
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
# float volume tests
|
|
19
|
-
@wp.kernel
|
|
20
|
-
def test_volume_lookup_f(volume: wp.uint64, points: wp.array(dtype=wp.vec3)):
|
|
21
|
-
tid = wp.tid()
|
|
22
|
-
|
|
23
|
-
p = points[tid]
|
|
24
|
-
expected = p[0] * p[1] * p[2]
|
|
25
|
-
if abs(p[0]) > 10.0 or abs(p[1]) > 10.0 or abs(p[2]) > 10.0:
|
|
26
|
-
expected = 10.0
|
|
27
|
-
|
|
28
|
-
i = int(p[0])
|
|
29
|
-
j = int(p[1])
|
|
30
|
-
k = int(p[2])
|
|
31
|
-
|
|
32
|
-
expect_eq(wp.volume_lookup_f(volume, i, j, k), expected)
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
@wp.kernel
|
|
36
|
-
def test_volume_sample_closest_f(volume: wp.uint64, points: wp.array(dtype=wp.vec3)):
|
|
37
|
-
tid = wp.tid()
|
|
38
|
-
|
|
39
|
-
p = points[tid]
|
|
40
|
-
i = round(p[0])
|
|
41
|
-
j = round(p[1])
|
|
42
|
-
k = round(p[2])
|
|
43
|
-
expected = i * j * k
|
|
44
|
-
if abs(i) > 10.0 or abs(j) > 10.0 or abs(k) > 10.0:
|
|
45
|
-
expected = 10.0
|
|
46
|
-
|
|
47
|
-
expect_eq(wp.volume_sample_f(volume, p, wp.Volume.CLOSEST), expected)
|
|
48
|
-
|
|
49
|
-
q = wp.volume_index_to_world(volume, p)
|
|
50
|
-
q_inv = wp.volume_world_to_index(volume, q)
|
|
51
|
-
expect_eq(p, q_inv)
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
@wp.kernel
|
|
55
|
-
def test_volume_sample_linear_f(volume: wp.uint64, points: wp.array(dtype=wp.vec3)):
|
|
56
|
-
tid = wp.tid()
|
|
57
|
-
|
|
58
|
-
p = points[tid]
|
|
59
|
-
|
|
60
|
-
expected = p[0] * p[1] * p[2]
|
|
61
|
-
if abs(p[0]) > 10.0 or abs(p[1]) > 10.0 or abs(p[2]) > 10.0:
|
|
62
|
-
return # not testing against background values
|
|
63
|
-
|
|
64
|
-
expect_near(wp.volume_sample_f(volume, p, wp.Volume.LINEAR), expected, 2.0e-4)
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
@wp.kernel
|
|
68
|
-
def test_volume_sample_grad_linear_f(volume: wp.uint64, points: wp.array(dtype=wp.vec3)):
|
|
69
|
-
tid = wp.tid()
|
|
70
|
-
|
|
71
|
-
p = points[tid]
|
|
72
|
-
|
|
73
|
-
expected_val = p[0] * p[1] * p[2]
|
|
74
|
-
expected_gx = p[1] * p[2]
|
|
75
|
-
expected_gy = p[0] * p[2]
|
|
76
|
-
expected_gz = p[0] * p[1]
|
|
77
|
-
|
|
78
|
-
if abs(p[0]) > 10.0 or abs(p[1]) > 10.0 or abs(p[2]) > 10.0:
|
|
79
|
-
return # not testing against background values
|
|
80
|
-
|
|
81
|
-
grad = wp.vec3(0.0, 0.0, 0.0)
|
|
82
|
-
val = wp.volume_sample_grad_f(volume, p, wp.Volume.LINEAR, grad)
|
|
83
|
-
|
|
84
|
-
expect_near(val, expected_val, 2.0e-4)
|
|
85
|
-
expect_near(grad[0], expected_gx, 2.0e-4)
|
|
86
|
-
expect_near(grad[1], expected_gy, 2.0e-4)
|
|
87
|
-
expect_near(grad[2], expected_gz, 2.0e-4)
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
@wp.kernel
|
|
91
|
-
def test_volume_sample_local_f_linear_values(
|
|
92
|
-
volume: wp.uint64, points: wp.array(dtype=wp.vec3), values: wp.array(dtype=wp.float32)
|
|
93
|
-
):
|
|
94
|
-
tid = wp.tid()
|
|
95
|
-
p = points[tid]
|
|
96
|
-
values[tid] = wp.volume_sample_f(volume, p, wp.Volume.LINEAR)
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
@wp.kernel
|
|
100
|
-
def test_volume_sample_grad_local_f_linear_values(
|
|
101
|
-
volume: wp.uint64, points: wp.array(dtype=wp.vec3), values: wp.array(dtype=wp.float32), case_num: int
|
|
102
|
-
):
|
|
103
|
-
tid = wp.tid()
|
|
104
|
-
p = points[tid]
|
|
105
|
-
|
|
106
|
-
grad = wp.vec3(0.0, 0.0, 0.0)
|
|
107
|
-
val = wp.volume_sample_grad_f(volume, p, wp.Volume.LINEAR, grad)
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
@wp.kernel
|
|
119
|
-
def test_volume_sample_world_f_linear_values(
|
|
120
|
-
volume: wp.uint64, points: wp.array(dtype=wp.vec3), values: wp.array(dtype=wp.float32)
|
|
121
|
-
):
|
|
122
|
-
tid = wp.tid()
|
|
123
|
-
q = points[tid]
|
|
124
|
-
p = wp.volume_world_to_index(volume, q)
|
|
125
|
-
values[tid] = wp.volume_sample_f(volume, p, wp.Volume.LINEAR)
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
@wp.kernel
|
|
129
|
-
def test_volume_sample_grad_world_f_linear_values(
|
|
130
|
-
volume: wp.uint64, points: wp.array(dtype=wp.vec3), values: wp.array(dtype=wp.float32), case_num: int
|
|
131
|
-
):
|
|
132
|
-
tid = wp.tid()
|
|
133
|
-
q = points[tid]
|
|
134
|
-
p = wp.volume_world_to_index(volume, q)
|
|
135
|
-
|
|
136
|
-
grad = wp.vec3(0.0, 0.0, 0.0)
|
|
137
|
-
val = wp.volume_sample_grad_f(volume, p, wp.Volume.LINEAR, grad)
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
)
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
)
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
)
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
)
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
)
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
)
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
#
|
|
337
|
-
#
|
|
338
|
-
#
|
|
339
|
-
#
|
|
340
|
-
#
|
|
341
|
-
#
|
|
342
|
-
#
|
|
343
|
-
#
|
|
344
|
-
#
|
|
345
|
-
#
|
|
346
|
-
#
|
|
347
|
-
#
|
|
348
|
-
#
|
|
349
|
-
# [0
|
|
350
|
-
# [0, 0, 0
|
|
351
|
-
# [
|
|
352
|
-
#
|
|
353
|
-
#
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
"
|
|
357
|
-
"
|
|
358
|
-
"
|
|
359
|
-
"
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
tape
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
grad_computed =
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
tape
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
grad_computed =
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
tape
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
tape
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
tape
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
grad_computed =
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
tape
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
grad_computed =
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
tape
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
grad_expected =
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
grad_expected =
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
values_res
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
values_res
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
values_res
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
values_res
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
np.testing.assert_equal(
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
sphere_vdb_array
|
|
629
|
-
test.
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
)
|
|
646
|
-
add_function_test(TestVolume, "
|
|
647
|
-
add_function_test(
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
)
|
|
657
|
-
add_function_test(
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
1
|
+
# Copyright (c) 2022 NVIDIA CORPORATION. All rights reserved.
|
|
2
|
+
# NVIDIA CORPORATION and its licensors retain all intellectual property
|
|
3
|
+
# and proprietary rights in and to this software, related documentation
|
|
4
|
+
# and any modifications thereto. Any use, reproduction, disclosure or
|
|
5
|
+
# distribution of this software and related documentation without an express
|
|
6
|
+
# license agreement from NVIDIA CORPORATION is strictly prohibited.
|
|
7
|
+
|
|
8
|
+
import unittest
|
|
9
|
+
|
|
10
|
+
import numpy as np
|
|
11
|
+
|
|
12
|
+
import warp as wp
|
|
13
|
+
from warp.tests.unittest_utils import *
|
|
14
|
+
|
|
15
|
+
wp.init()
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
# float volume tests
|
|
19
|
+
@wp.kernel
|
|
20
|
+
def test_volume_lookup_f(volume: wp.uint64, points: wp.array(dtype=wp.vec3)):
|
|
21
|
+
tid = wp.tid()
|
|
22
|
+
|
|
23
|
+
p = points[tid]
|
|
24
|
+
expected = p[0] * p[1] * p[2]
|
|
25
|
+
if abs(p[0]) > 10.0 or abs(p[1]) > 10.0 or abs(p[2]) > 10.0:
|
|
26
|
+
expected = 10.0
|
|
27
|
+
|
|
28
|
+
i = int(p[0])
|
|
29
|
+
j = int(p[1])
|
|
30
|
+
k = int(p[2])
|
|
31
|
+
|
|
32
|
+
expect_eq(wp.volume_lookup_f(volume, i, j, k), expected)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@wp.kernel
|
|
36
|
+
def test_volume_sample_closest_f(volume: wp.uint64, points: wp.array(dtype=wp.vec3)):
|
|
37
|
+
tid = wp.tid()
|
|
38
|
+
|
|
39
|
+
p = points[tid]
|
|
40
|
+
i = round(p[0])
|
|
41
|
+
j = round(p[1])
|
|
42
|
+
k = round(p[2])
|
|
43
|
+
expected = i * j * k
|
|
44
|
+
if abs(i) > 10.0 or abs(j) > 10.0 or abs(k) > 10.0:
|
|
45
|
+
expected = 10.0
|
|
46
|
+
|
|
47
|
+
expect_eq(wp.volume_sample_f(volume, p, wp.Volume.CLOSEST), expected)
|
|
48
|
+
|
|
49
|
+
q = wp.volume_index_to_world(volume, p)
|
|
50
|
+
q_inv = wp.volume_world_to_index(volume, q)
|
|
51
|
+
expect_eq(p, q_inv)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
@wp.kernel
|
|
55
|
+
def test_volume_sample_linear_f(volume: wp.uint64, points: wp.array(dtype=wp.vec3)):
|
|
56
|
+
tid = wp.tid()
|
|
57
|
+
|
|
58
|
+
p = points[tid]
|
|
59
|
+
|
|
60
|
+
expected = p[0] * p[1] * p[2]
|
|
61
|
+
if abs(p[0]) > 10.0 or abs(p[1]) > 10.0 or abs(p[2]) > 10.0:
|
|
62
|
+
return # not testing against background values
|
|
63
|
+
|
|
64
|
+
expect_near(wp.volume_sample_f(volume, p, wp.Volume.LINEAR), expected, 2.0e-4)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
@wp.kernel
|
|
68
|
+
def test_volume_sample_grad_linear_f(volume: wp.uint64, points: wp.array(dtype=wp.vec3)):
|
|
69
|
+
tid = wp.tid()
|
|
70
|
+
|
|
71
|
+
p = points[tid]
|
|
72
|
+
|
|
73
|
+
expected_val = p[0] * p[1] * p[2]
|
|
74
|
+
expected_gx = p[1] * p[2]
|
|
75
|
+
expected_gy = p[0] * p[2]
|
|
76
|
+
expected_gz = p[0] * p[1]
|
|
77
|
+
|
|
78
|
+
if abs(p[0]) > 10.0 or abs(p[1]) > 10.0 or abs(p[2]) > 10.0:
|
|
79
|
+
return # not testing against background values
|
|
80
|
+
|
|
81
|
+
grad = wp.vec3(0.0, 0.0, 0.0)
|
|
82
|
+
val = wp.volume_sample_grad_f(volume, p, wp.Volume.LINEAR, grad)
|
|
83
|
+
|
|
84
|
+
expect_near(val, expected_val, 2.0e-4)
|
|
85
|
+
expect_near(grad[0], expected_gx, 2.0e-4)
|
|
86
|
+
expect_near(grad[1], expected_gy, 2.0e-4)
|
|
87
|
+
expect_near(grad[2], expected_gz, 2.0e-4)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
@wp.kernel
|
|
91
|
+
def test_volume_sample_local_f_linear_values(
|
|
92
|
+
volume: wp.uint64, points: wp.array(dtype=wp.vec3), values: wp.array(dtype=wp.float32)
|
|
93
|
+
):
|
|
94
|
+
tid = wp.tid()
|
|
95
|
+
p = points[tid]
|
|
96
|
+
values[tid] = wp.volume_sample_f(volume, p, wp.Volume.LINEAR)
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
@wp.kernel
|
|
100
|
+
def test_volume_sample_grad_local_f_linear_values(
|
|
101
|
+
volume: wp.uint64, points: wp.array(dtype=wp.vec3), values: wp.array(dtype=wp.float32), case_num: int
|
|
102
|
+
):
|
|
103
|
+
tid = wp.tid()
|
|
104
|
+
p = points[tid]
|
|
105
|
+
|
|
106
|
+
grad = wp.vec3(0.0, 0.0, 0.0)
|
|
107
|
+
val = wp.volume_sample_grad_f(volume, p, wp.Volume.LINEAR, grad)
|
|
108
|
+
if case_num == 0:
|
|
109
|
+
values[tid] = val
|
|
110
|
+
elif case_num == 1:
|
|
111
|
+
values[tid] = grad[0]
|
|
112
|
+
elif case_num == 2:
|
|
113
|
+
values[tid] = grad[1]
|
|
114
|
+
elif case_num == 3:
|
|
115
|
+
values[tid] = grad[2]
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
@wp.kernel
|
|
119
|
+
def test_volume_sample_world_f_linear_values(
|
|
120
|
+
volume: wp.uint64, points: wp.array(dtype=wp.vec3), values: wp.array(dtype=wp.float32)
|
|
121
|
+
):
|
|
122
|
+
tid = wp.tid()
|
|
123
|
+
q = points[tid]
|
|
124
|
+
p = wp.volume_world_to_index(volume, q)
|
|
125
|
+
values[tid] = wp.volume_sample_f(volume, p, wp.Volume.LINEAR)
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
@wp.kernel
|
|
129
|
+
def test_volume_sample_grad_world_f_linear_values(
|
|
130
|
+
volume: wp.uint64, points: wp.array(dtype=wp.vec3), values: wp.array(dtype=wp.float32), case_num: int
|
|
131
|
+
):
|
|
132
|
+
tid = wp.tid()
|
|
133
|
+
q = points[tid]
|
|
134
|
+
p = wp.volume_world_to_index(volume, q)
|
|
135
|
+
|
|
136
|
+
grad = wp.vec3(0.0, 0.0, 0.0)
|
|
137
|
+
val = wp.volume_sample_grad_f(volume, p, wp.Volume.LINEAR, grad)
|
|
138
|
+
if case_num == 0:
|
|
139
|
+
values[tid] = val
|
|
140
|
+
elif case_num == 1:
|
|
141
|
+
values[tid] = grad[0]
|
|
142
|
+
elif case_num == 2:
|
|
143
|
+
values[tid] = grad[1]
|
|
144
|
+
elif case_num == 3:
|
|
145
|
+
values[tid] = grad[2]
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
# vec3f volume tests
|
|
149
|
+
@wp.kernel
|
|
150
|
+
def test_volume_lookup_v(volume: wp.uint64, points: wp.array(dtype=wp.vec3)):
|
|
151
|
+
tid = wp.tid()
|
|
152
|
+
|
|
153
|
+
p = points[tid]
|
|
154
|
+
expected = wp.vec3(
|
|
155
|
+
p[0] + 2.0 * p[1] + 3.0 * p[2], 4.0 * p[0] + 5.0 * p[1] + 6.0 * p[2], 7.0 * p[0] + 8.0 * p[1] + 9.0 * p[2]
|
|
156
|
+
)
|
|
157
|
+
if abs(p[0]) > 10.0 or abs(p[1]) > 10.0 or abs(p[2]) > 10.0:
|
|
158
|
+
expected = wp.vec3(10.8, -4.13, 10.26)
|
|
159
|
+
|
|
160
|
+
i = int(p[0])
|
|
161
|
+
j = int(p[1])
|
|
162
|
+
k = int(p[2])
|
|
163
|
+
|
|
164
|
+
expect_eq(wp.volume_lookup_v(volume, i, j, k), expected)
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
@wp.kernel
|
|
168
|
+
def test_volume_sample_closest_v(volume: wp.uint64, points: wp.array(dtype=wp.vec3)):
|
|
169
|
+
tid = wp.tid()
|
|
170
|
+
|
|
171
|
+
p = points[tid]
|
|
172
|
+
i = round(p[0])
|
|
173
|
+
j = round(p[1])
|
|
174
|
+
k = round(p[2])
|
|
175
|
+
expected = wp.vec3(i + 2.0 * j + 3.0 * k, 4.0 * i + 5.0 * j + 6.0 * k, 7.0 * i + 8.0 * j + 9.0 * k)
|
|
176
|
+
if abs(i) > 10.0 or abs(j) > 10.0 or abs(k) > 10.0:
|
|
177
|
+
expected = wp.vec3(10.8, -4.13, 10.26)
|
|
178
|
+
|
|
179
|
+
expect_eq(wp.volume_sample_v(volume, p, wp.Volume.CLOSEST), expected)
|
|
180
|
+
|
|
181
|
+
q = wp.volume_index_to_world(volume, p)
|
|
182
|
+
q_inv = wp.volume_world_to_index(volume, q)
|
|
183
|
+
expect_eq(p, q_inv)
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
@wp.kernel
|
|
187
|
+
def test_volume_sample_linear_v(volume: wp.uint64, points: wp.array(dtype=wp.vec3)):
|
|
188
|
+
tid = wp.tid()
|
|
189
|
+
|
|
190
|
+
p = points[tid]
|
|
191
|
+
|
|
192
|
+
expected = wp.vec3(
|
|
193
|
+
p[0] + 2.0 * p[1] + 3.0 * p[2], 4.0 * p[0] + 5.0 * p[1] + 6.0 * p[2], 7.0 * p[0] + 8.0 * p[1] + 9.0 * p[2]
|
|
194
|
+
)
|
|
195
|
+
if abs(p[0]) > 10.0 or abs(p[1]) > 10.0 or abs(p[2]) > 10.0:
|
|
196
|
+
return # not testing against background values
|
|
197
|
+
|
|
198
|
+
expect_near(wp.volume_sample_v(volume, p, wp.Volume.LINEAR), expected, 2.0e-4)
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
@wp.kernel
|
|
202
|
+
def test_volume_sample_local_v_linear_values(
|
|
203
|
+
volume: wp.uint64, points: wp.array(dtype=wp.vec3), values: wp.array(dtype=wp.float32)
|
|
204
|
+
):
|
|
205
|
+
tid = wp.tid()
|
|
206
|
+
p = points[tid]
|
|
207
|
+
ones = wp.vec3(1.0, 1.0, 1.0)
|
|
208
|
+
values[tid] = wp.dot(wp.volume_sample_v(volume, p, wp.Volume.LINEAR), ones)
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
@wp.kernel
|
|
212
|
+
def test_volume_sample_world_v_linear_values(
|
|
213
|
+
volume: wp.uint64, points: wp.array(dtype=wp.vec3), values: wp.array(dtype=wp.float32)
|
|
214
|
+
):
|
|
215
|
+
tid = wp.tid()
|
|
216
|
+
q = points[tid]
|
|
217
|
+
p = wp.volume_world_to_index(volume, q)
|
|
218
|
+
ones = wp.vec3(1.0, 1.0, 1.0)
|
|
219
|
+
values[tid] = wp.dot(wp.volume_sample_v(volume, p, wp.Volume.LINEAR), ones)
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
# int32 volume tests
|
|
223
|
+
@wp.kernel
|
|
224
|
+
def test_volume_lookup_i(volume: wp.uint64, points: wp.array(dtype=wp.vec3)):
|
|
225
|
+
tid = wp.tid()
|
|
226
|
+
|
|
227
|
+
p = points[tid]
|
|
228
|
+
i = int(p[0])
|
|
229
|
+
j = int(p[1])
|
|
230
|
+
k = int(p[2])
|
|
231
|
+
expected = i * j * k
|
|
232
|
+
if abs(i) > 10 or abs(j) > 10 or abs(k) > 10:
|
|
233
|
+
expected = 10
|
|
234
|
+
|
|
235
|
+
expect_eq(wp.volume_lookup_i(volume, i, j, k), expected)
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
@wp.kernel
|
|
239
|
+
def test_volume_sample_i(volume: wp.uint64, points: wp.array(dtype=wp.vec3)):
|
|
240
|
+
tid = wp.tid()
|
|
241
|
+
|
|
242
|
+
p = points[tid]
|
|
243
|
+
i = round(p[0])
|
|
244
|
+
j = round(p[1])
|
|
245
|
+
k = round(p[2])
|
|
246
|
+
expected = int(i * j * k)
|
|
247
|
+
if abs(i) > 10.0 or abs(j) > 10.0 or abs(k) > 10.0:
|
|
248
|
+
expected = 10
|
|
249
|
+
|
|
250
|
+
expect_eq(wp.volume_sample_i(volume, p), expected)
|
|
251
|
+
|
|
252
|
+
q = wp.volume_index_to_world(volume, p)
|
|
253
|
+
q_inv = wp.volume_world_to_index(volume, q)
|
|
254
|
+
expect_eq(p, q_inv)
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
# Index/world transformation tests
|
|
258
|
+
@wp.kernel
|
|
259
|
+
def test_volume_index_to_world(
|
|
260
|
+
volume: wp.uint64,
|
|
261
|
+
points: wp.array(dtype=wp.vec3),
|
|
262
|
+
values: wp.array(dtype=wp.float32),
|
|
263
|
+
grad_values: wp.array(dtype=wp.vec3),
|
|
264
|
+
):
|
|
265
|
+
tid = wp.tid()
|
|
266
|
+
p = points[tid]
|
|
267
|
+
ones = wp.vec3(1.0, 1.0, 1.0)
|
|
268
|
+
values[tid] = wp.dot(wp.volume_index_to_world(volume, p), ones)
|
|
269
|
+
grad_values[tid] = wp.volume_index_to_world_dir(volume, ones)
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
@wp.kernel
|
|
273
|
+
def test_volume_world_to_index(
|
|
274
|
+
volume: wp.uint64,
|
|
275
|
+
points: wp.array(dtype=wp.vec3),
|
|
276
|
+
values: wp.array(dtype=wp.float32),
|
|
277
|
+
grad_values: wp.array(dtype=wp.vec3),
|
|
278
|
+
):
|
|
279
|
+
tid = wp.tid()
|
|
280
|
+
p = points[tid]
|
|
281
|
+
ones = wp.vec3(1.0, 1.0, 1.0)
|
|
282
|
+
values[tid] = wp.dot(wp.volume_world_to_index(volume, p), ones)
|
|
283
|
+
grad_values[tid] = wp.volume_world_to_index_dir(volume, ones)
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
# Volume write tests
|
|
287
|
+
@wp.kernel
|
|
288
|
+
def test_volume_store_f(volume: wp.uint64, points: wp.array(dtype=wp.vec3), values: wp.array(dtype=wp.float32)):
|
|
289
|
+
tid = wp.tid()
|
|
290
|
+
|
|
291
|
+
p = points[tid]
|
|
292
|
+
i = int(p[0])
|
|
293
|
+
j = int(p[1])
|
|
294
|
+
k = int(p[2])
|
|
295
|
+
|
|
296
|
+
# NB: Writing outside the allocated domain overwrites the background value of the Volume
|
|
297
|
+
if abs(i) <= 11 and abs(j) <= 11 and abs(k) <= 11:
|
|
298
|
+
wp.volume_store_f(volume, i, j, k, float(i + 100 * j + 10000 * k))
|
|
299
|
+
values[tid] = wp.volume_lookup_f(volume, i, j, k)
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
@wp.kernel
|
|
303
|
+
def test_volume_store_v(volume: wp.uint64, points: wp.array(dtype=wp.vec3), values: wp.array(dtype=wp.vec3)):
|
|
304
|
+
tid = wp.tid()
|
|
305
|
+
|
|
306
|
+
p = points[tid]
|
|
307
|
+
i = int(p[0])
|
|
308
|
+
j = int(p[1])
|
|
309
|
+
k = int(p[2])
|
|
310
|
+
|
|
311
|
+
# NB: Writing outside the allocated domain overwrites the background value of the Volume
|
|
312
|
+
if abs(i) <= 11 and abs(j) <= 11 and abs(k) <= 11:
|
|
313
|
+
wp.volume_store_v(volume, i, j, k, p)
|
|
314
|
+
values[tid] = wp.volume_lookup_v(volume, i, j, k)
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
@wp.kernel
|
|
318
|
+
def test_volume_store_i(volume: wp.uint64, points: wp.array(dtype=wp.vec3), values: wp.array(dtype=wp.int32)):
|
|
319
|
+
tid = wp.tid()
|
|
320
|
+
|
|
321
|
+
p = points[tid]
|
|
322
|
+
i = int(p[0])
|
|
323
|
+
j = int(p[1])
|
|
324
|
+
k = int(p[2])
|
|
325
|
+
|
|
326
|
+
# NB: Writing outside the allocated domain overwrites the background value of the Volume
|
|
327
|
+
if abs(i) <= 11 and abs(j) <= 11 and abs(k) <= 11:
|
|
328
|
+
wp.volume_store_i(volume, i, j, k, i + 100 * j + 10000 * k)
|
|
329
|
+
values[tid] = wp.volume_lookup_i(volume, i, j, k)
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
devices = get_test_devices()
|
|
333
|
+
rng = np.random.default_rng(101215)
|
|
334
|
+
|
|
335
|
+
# Note about the test grids:
|
|
336
|
+
# test_grid and test_int32_grid
|
|
337
|
+
# active region: [-10,10]^3
|
|
338
|
+
# values: v[i,j,k] = i * j * k
|
|
339
|
+
# voxel size: 0.25
|
|
340
|
+
#
|
|
341
|
+
# test_vec_grid
|
|
342
|
+
# active region: [-10,10]^3
|
|
343
|
+
# values: v[i,j,k] = (i + 2*j + 3*k, 4*i + 5*j + 6*k, 7*i + 8*j + 9*k)
|
|
344
|
+
# voxel size: 0.25
|
|
345
|
+
#
|
|
346
|
+
# torus
|
|
347
|
+
# index to world transformation:
|
|
348
|
+
# [0.1, 0, 0, 0]
|
|
349
|
+
# [0, 0, 0.1, 0]
|
|
350
|
+
# [0, 0.1, 0, 0]
|
|
351
|
+
# [1, 2, 3, 1]
|
|
352
|
+
# (-90 degrees rotation along X)
|
|
353
|
+
# voxel size: 0.1
|
|
354
|
+
volume_paths = {
|
|
355
|
+
"float": os.path.abspath(os.path.join(os.path.dirname(__file__), "assets/test_grid.nvdb")),
|
|
356
|
+
"int32": os.path.abspath(os.path.join(os.path.dirname(__file__), "assets/test_int32_grid.nvdb")),
|
|
357
|
+
"vec3f": os.path.abspath(os.path.join(os.path.dirname(__file__), "assets/test_vec_grid.nvdb")),
|
|
358
|
+
"torus": os.path.abspath(os.path.join(os.path.dirname(__file__), "assets/torus.nvdb")),
|
|
359
|
+
"float_write": os.path.abspath(os.path.join(os.path.dirname(__file__), "assets/test_grid.nvdb")),
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
test_volume_tiles = (
|
|
363
|
+
np.array([[i, j, k] for i in range(-2, 2) for j in range(-2, 2) for k in range(-2, 2)], dtype=np.int32) * 8
|
|
364
|
+
)
|
|
365
|
+
|
|
366
|
+
volumes = {}
|
|
367
|
+
for value_type, path in volume_paths.items():
|
|
368
|
+
volumes[value_type] = {}
|
|
369
|
+
volume_data = open(path, "rb").read()
|
|
370
|
+
for device in devices:
|
|
371
|
+
try:
|
|
372
|
+
volume = wp.Volume.load_from_nvdb(volume_data, device)
|
|
373
|
+
except RuntimeError as e:
|
|
374
|
+
raise RuntimeError(f'Failed to load volume from "{path}" to {device} memory:\n{e}') from e
|
|
375
|
+
|
|
376
|
+
volumes[value_type][device.alias] = volume
|
|
377
|
+
|
|
378
|
+
axis = np.linspace(-1, 1, 3)
|
|
379
|
+
point_grid = np.array([[x, y, z] for x in axis for y in axis for z in axis], dtype=np.float32)
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
def test_volume_sample_linear_f_gradient(test, device):
|
|
383
|
+
points = rng.uniform(-10.0, 10.0, size=(100, 3))
|
|
384
|
+
values = wp.array(np.zeros(1), dtype=wp.float32, device=device, requires_grad=True)
|
|
385
|
+
for test_case in points:
|
|
386
|
+
uvws = wp.array(test_case, dtype=wp.vec3, device=device, requires_grad=True)
|
|
387
|
+
xyzs = wp.array(test_case * 0.25, dtype=wp.vec3, device=device, requires_grad=True)
|
|
388
|
+
|
|
389
|
+
tape = wp.Tape()
|
|
390
|
+
with tape:
|
|
391
|
+
wp.launch(
|
|
392
|
+
test_volume_sample_local_f_linear_values,
|
|
393
|
+
dim=1,
|
|
394
|
+
inputs=[volumes["float"][device.alias].id, uvws, values],
|
|
395
|
+
device=device,
|
|
396
|
+
)
|
|
397
|
+
tape.backward(values)
|
|
398
|
+
|
|
399
|
+
x, y, z = test_case
|
|
400
|
+
grad_expected = np.array([y * z, x * z, x * y])
|
|
401
|
+
grad_computed = tape.gradients[uvws].numpy()[0]
|
|
402
|
+
np.testing.assert_allclose(grad_computed, grad_expected, rtol=1e-4)
|
|
403
|
+
|
|
404
|
+
tape = wp.Tape()
|
|
405
|
+
with tape:
|
|
406
|
+
wp.launch(
|
|
407
|
+
test_volume_sample_world_f_linear_values,
|
|
408
|
+
dim=1,
|
|
409
|
+
inputs=[volumes["float"][device.alias].id, xyzs, values],
|
|
410
|
+
device=device,
|
|
411
|
+
)
|
|
412
|
+
tape.backward(values)
|
|
413
|
+
|
|
414
|
+
x, y, z = test_case
|
|
415
|
+
grad_expected = np.array([y * z, x * z, x * y]) / 0.25
|
|
416
|
+
grad_computed = tape.gradients[xyzs].numpy()[0]
|
|
417
|
+
np.testing.assert_allclose(grad_computed, grad_expected, rtol=1e-4)
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
def test_volume_sample_grad_linear_f_gradient(test, device):
|
|
421
|
+
points = rng.uniform(-10.0, 10.0, size=(100, 3))
|
|
422
|
+
values = wp.array(np.zeros(1), dtype=wp.float32, device=device, requires_grad=True)
|
|
423
|
+
for test_case in points:
|
|
424
|
+
uvws = wp.array(test_case, dtype=wp.vec3, device=device, requires_grad=True)
|
|
425
|
+
xyzs = wp.array(test_case * 0.25, dtype=wp.vec3, device=device, requires_grad=True)
|
|
426
|
+
|
|
427
|
+
for case_num in range(4):
|
|
428
|
+
tape = wp.Tape()
|
|
429
|
+
with tape:
|
|
430
|
+
wp.launch(
|
|
431
|
+
test_volume_sample_grad_local_f_linear_values,
|
|
432
|
+
dim=1,
|
|
433
|
+
inputs=[volumes["float"][device.alias].id, uvws, values, case_num],
|
|
434
|
+
device=device,
|
|
435
|
+
)
|
|
436
|
+
tape.backward(values)
|
|
437
|
+
|
|
438
|
+
x, y, z = test_case
|
|
439
|
+
grad_computed = tape.gradients[uvws].numpy()[0]
|
|
440
|
+
if case_num == 0:
|
|
441
|
+
grad_expected = np.array([y * z, x * z, x * y])
|
|
442
|
+
elif case_num == 1:
|
|
443
|
+
grad_expected = np.array([0.0, z, y])
|
|
444
|
+
elif case_num == 2:
|
|
445
|
+
grad_expected = np.array([z, 0.0, x])
|
|
446
|
+
elif case_num == 3:
|
|
447
|
+
grad_expected = np.array([y, x, 0.0])
|
|
448
|
+
|
|
449
|
+
np.testing.assert_allclose(grad_computed, grad_expected, rtol=1e-4)
|
|
450
|
+
tape.zero()
|
|
451
|
+
|
|
452
|
+
for case_num in range(4):
|
|
453
|
+
tape = wp.Tape()
|
|
454
|
+
with tape:
|
|
455
|
+
wp.launch(
|
|
456
|
+
test_volume_sample_grad_world_f_linear_values,
|
|
457
|
+
dim=1,
|
|
458
|
+
inputs=[volumes["float"][device.alias].id, xyzs, values, case_num],
|
|
459
|
+
device=device,
|
|
460
|
+
)
|
|
461
|
+
tape.backward(values)
|
|
462
|
+
|
|
463
|
+
x, y, z = test_case
|
|
464
|
+
grad_computed = tape.gradients[xyzs].numpy()[0]
|
|
465
|
+
if case_num == 0:
|
|
466
|
+
grad_expected = np.array([y * z, x * z, x * y]) / 0.25
|
|
467
|
+
elif case_num == 1:
|
|
468
|
+
grad_expected = np.array([0.0, z, y]) / 0.25
|
|
469
|
+
elif case_num == 2:
|
|
470
|
+
grad_expected = np.array([z, 0.0, x]) / 0.25
|
|
471
|
+
elif case_num == 3:
|
|
472
|
+
grad_expected = np.array([y, x, 0.0]) / 0.25
|
|
473
|
+
|
|
474
|
+
np.testing.assert_allclose(grad_computed, grad_expected, rtol=1e-4)
|
|
475
|
+
tape.zero()
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
def test_volume_sample_linear_v_gradient(test, device):
|
|
479
|
+
points = rng.uniform(-10.0, 10.0, size=(100, 3))
|
|
480
|
+
values = wp.zeros(1, dtype=wp.float32, device=device, requires_grad=True)
|
|
481
|
+
for test_case in points:
|
|
482
|
+
uvws = wp.array(test_case, dtype=wp.vec3, device=device, requires_grad=True)
|
|
483
|
+
xyzs = wp.array(test_case * 0.25, dtype=wp.vec3, device=device, requires_grad=True)
|
|
484
|
+
|
|
485
|
+
tape = wp.Tape()
|
|
486
|
+
with tape:
|
|
487
|
+
wp.launch(
|
|
488
|
+
test_volume_sample_local_v_linear_values,
|
|
489
|
+
dim=1,
|
|
490
|
+
inputs=[volumes["vec3f"][device.alias].id, uvws, values],
|
|
491
|
+
device=device,
|
|
492
|
+
)
|
|
493
|
+
tape.backward(values)
|
|
494
|
+
|
|
495
|
+
grad_expected = np.array([6.0, 15.0, 24.0])
|
|
496
|
+
grad_computed = tape.gradients[uvws].numpy()[0]
|
|
497
|
+
np.testing.assert_allclose(grad_computed, grad_expected, rtol=1e-4)
|
|
498
|
+
|
|
499
|
+
tape = wp.Tape()
|
|
500
|
+
with tape:
|
|
501
|
+
wp.launch(
|
|
502
|
+
test_volume_sample_world_v_linear_values,
|
|
503
|
+
dim=1,
|
|
504
|
+
inputs=[volumes["vec3f"][device.alias].id, xyzs, values],
|
|
505
|
+
device=device,
|
|
506
|
+
)
|
|
507
|
+
tape.backward(values)
|
|
508
|
+
|
|
509
|
+
grad_expected = np.array([6.0, 15.0, 24.0]) / 0.25
|
|
510
|
+
grad_computed = tape.gradients[xyzs].numpy()[0]
|
|
511
|
+
np.testing.assert_allclose(grad_computed, grad_expected, rtol=1e-4)
|
|
512
|
+
|
|
513
|
+
|
|
514
|
+
def test_volume_transform_gradient(test, device):
|
|
515
|
+
values = wp.zeros(1, dtype=wp.float32, device=device, requires_grad=True)
|
|
516
|
+
grad_values = wp.zeros(1, dtype=wp.vec3, device=device)
|
|
517
|
+
test_points = rng.uniform(-10.0, 10.0, size=(10, 3))
|
|
518
|
+
for test_case in test_points:
|
|
519
|
+
points = wp.array(test_case, dtype=wp.vec3, device=device, requires_grad=True)
|
|
520
|
+
tape = wp.Tape()
|
|
521
|
+
with tape:
|
|
522
|
+
wp.launch(
|
|
523
|
+
test_volume_index_to_world,
|
|
524
|
+
dim=1,
|
|
525
|
+
inputs=[volumes["torus"][device.alias].id, points, values, grad_values],
|
|
526
|
+
device=device,
|
|
527
|
+
)
|
|
528
|
+
tape.backward(values)
|
|
529
|
+
|
|
530
|
+
grad_computed = tape.gradients[points].numpy()
|
|
531
|
+
grad_expected = grad_values.numpy()
|
|
532
|
+
np.testing.assert_allclose(grad_computed, grad_expected, rtol=1e-4)
|
|
533
|
+
|
|
534
|
+
grad_computed = tape.gradients[points].numpy()
|
|
535
|
+
grad_expected = grad_values.numpy()
|
|
536
|
+
np.testing.assert_allclose(grad_computed, grad_expected, rtol=1e-4)
|
|
537
|
+
|
|
538
|
+
|
|
539
|
+
def test_volume_store(test, device):
|
|
540
|
+
values_ref = np.array([x + 100 * y + 10000 * z for x, y, z in point_grid])
|
|
541
|
+
points = wp.array(point_grid, dtype=wp.vec3, device=device)
|
|
542
|
+
values = wp.empty(len(point_grid), dtype=wp.float32, device=device)
|
|
543
|
+
wp.launch(
|
|
544
|
+
test_volume_store_f,
|
|
545
|
+
dim=len(point_grid),
|
|
546
|
+
inputs=[volumes["float_write"][device.alias].id, points, values],
|
|
547
|
+
device=device,
|
|
548
|
+
)
|
|
549
|
+
|
|
550
|
+
values_res = values.numpy()
|
|
551
|
+
np.testing.assert_equal(values_res, values_ref)
|
|
552
|
+
|
|
553
|
+
|
|
554
|
+
def test_volume_allocation_f(test, device):
|
|
555
|
+
bg_value = -123.0
|
|
556
|
+
points_np = np.append(point_grid, [[8096, 8096, 8096]], axis=0)
|
|
557
|
+
values_ref = np.append(np.array([x + 100 * y + 10000 * z for x, y, z in point_grid]), bg_value)
|
|
558
|
+
|
|
559
|
+
volume = wp.Volume.allocate(min=[-11, -11, -11], max=[11, 11, 11], voxel_size=0.1, bg_value=bg_value, device=device)
|
|
560
|
+
points = wp.array(points_np, dtype=wp.vec3, device=device)
|
|
561
|
+
values = wp.empty(len(points_np), dtype=wp.float32, device=device)
|
|
562
|
+
wp.launch(test_volume_store_f, dim=len(points_np), inputs=[volume.id, points, values], device=device)
|
|
563
|
+
|
|
564
|
+
values_res = values.numpy()
|
|
565
|
+
np.testing.assert_equal(values_res, values_ref)
|
|
566
|
+
|
|
567
|
+
|
|
568
|
+
def test_volume_allocation_v(test, device):
|
|
569
|
+
bg_value = (-1, 2.0, -3)
|
|
570
|
+
points_np = np.append(point_grid, [[8096, 8096, 8096]], axis=0)
|
|
571
|
+
values_ref = np.append(point_grid, [bg_value], axis=0)
|
|
572
|
+
|
|
573
|
+
volume = wp.Volume.allocate(min=[-11, -11, -11], max=[11, 11, 11], voxel_size=0.1, bg_value=bg_value, device=device)
|
|
574
|
+
points = wp.array(points_np, dtype=wp.vec3, device=device)
|
|
575
|
+
values = wp.empty(len(points_np), dtype=wp.vec3, device=device)
|
|
576
|
+
wp.launch(test_volume_store_v, dim=len(points_np), inputs=[volume.id, points, values], device=device)
|
|
577
|
+
|
|
578
|
+
values_res = values.numpy()
|
|
579
|
+
np.testing.assert_equal(values_res, values_ref)
|
|
580
|
+
|
|
581
|
+
|
|
582
|
+
def test_volume_allocation_i(test, device):
|
|
583
|
+
bg_value = -123
|
|
584
|
+
points_np = np.append(point_grid, [[8096, 8096, 8096]], axis=0)
|
|
585
|
+
values_ref = np.append(np.array([x + 100 * y + 10000 * z for x, y, z in point_grid], dtype=np.int32), bg_value)
|
|
586
|
+
|
|
587
|
+
volume = wp.Volume.allocate(min=[-11, -11, -11], max=[11, 11, 11], voxel_size=0.1, bg_value=bg_value, device=device)
|
|
588
|
+
points = wp.array(points_np, dtype=wp.vec3, device=device)
|
|
589
|
+
values = wp.empty(len(points_np), dtype=wp.int32, device=device)
|
|
590
|
+
wp.launch(test_volume_store_i, dim=len(points_np), inputs=[volume.id, points, values], device=device)
|
|
591
|
+
|
|
592
|
+
values_res = values.numpy()
|
|
593
|
+
np.testing.assert_equal(values_res, values_ref)
|
|
594
|
+
|
|
595
|
+
|
|
596
|
+
def test_volume_introspection(test, device):
|
|
597
|
+
for volume_names in ("float", "vec3f"):
|
|
598
|
+
with test.subTest(volume_names=volume_names):
|
|
599
|
+
volume = volumes[volume_names][device.alias]
|
|
600
|
+
tiles_actual = volume.get_tiles().numpy()
|
|
601
|
+
tiles_sorted = tiles_actual[np.lexsort(tiles_actual.T[::-1])]
|
|
602
|
+
voxel_size = np.array(volume.get_voxel_size())
|
|
603
|
+
|
|
604
|
+
np.testing.assert_equal(test_volume_tiles, tiles_sorted)
|
|
605
|
+
np.testing.assert_equal([0.25] * 3, voxel_size)
|
|
606
|
+
|
|
607
|
+
|
|
608
|
+
def test_volume_from_numpy(test, device):
|
|
609
|
+
# Volume.allocate_from_tiles() is only available with CUDA
|
|
610
|
+
mins = np.array([-3.0, -3.0, -3.0])
|
|
611
|
+
voxel_size = 0.2
|
|
612
|
+
maxs = np.array([3.0, 3.0, 3.0])
|
|
613
|
+
nums = np.ceil((maxs - mins) / (voxel_size)).astype(dtype=int)
|
|
614
|
+
center = np.array([0.0, 0.0, 0.0])
|
|
615
|
+
rad = 2.5
|
|
616
|
+
sphere_sdf_np = np.zeros(tuple(nums))
|
|
617
|
+
for x in range(nums[0]):
|
|
618
|
+
for y in range(nums[1]):
|
|
619
|
+
for z in range(nums[2]):
|
|
620
|
+
pos = mins + voxel_size * np.array([x, y, z])
|
|
621
|
+
dis = np.linalg.norm(pos - center)
|
|
622
|
+
sphere_sdf_np[x, y, z] = dis - rad
|
|
623
|
+
sphere_vdb = wp.Volume.load_from_numpy(sphere_sdf_np, mins, voxel_size, rad + 3.0 * voxel_size, device=device)
|
|
624
|
+
|
|
625
|
+
test.assertNotEqual(sphere_vdb.id, 0)
|
|
626
|
+
|
|
627
|
+
sphere_vdb_array = sphere_vdb.array()
|
|
628
|
+
test.assertEqual(sphere_vdb_array.dtype, wp.uint8)
|
|
629
|
+
test.assertIsNone(sphere_vdb_array.deleter)
|
|
630
|
+
|
|
631
|
+
|
|
632
|
+
class TestVolume(unittest.TestCase):
|
|
633
|
+
pass
|
|
634
|
+
|
|
635
|
+
|
|
636
|
+
add_function_test(
|
|
637
|
+
TestVolume, "test_volume_sample_linear_f_gradient", test_volume_sample_linear_f_gradient, devices=devices
|
|
638
|
+
)
|
|
639
|
+
add_function_test(
|
|
640
|
+
TestVolume, "test_volume_sample_grad_linear_f_gradient", test_volume_sample_grad_linear_f_gradient, devices=devices
|
|
641
|
+
)
|
|
642
|
+
add_function_test(
|
|
643
|
+
TestVolume, "test_volume_sample_linear_v_gradient", test_volume_sample_linear_v_gradient, devices=devices
|
|
644
|
+
)
|
|
645
|
+
add_function_test(TestVolume, "test_volume_transform_gradient", test_volume_transform_gradient, devices=devices)
|
|
646
|
+
add_function_test(TestVolume, "test_volume_store", test_volume_store, devices=devices)
|
|
647
|
+
add_function_test(
|
|
648
|
+
TestVolume, "test_volume_allocation_f", test_volume_allocation_f, devices=get_selected_cuda_test_devices()
|
|
649
|
+
)
|
|
650
|
+
add_function_test(
|
|
651
|
+
TestVolume, "test_volume_allocation_v", test_volume_allocation_v, devices=get_selected_cuda_test_devices()
|
|
652
|
+
)
|
|
653
|
+
add_function_test(
|
|
654
|
+
TestVolume, "test_volume_allocation_i", test_volume_allocation_i, devices=get_selected_cuda_test_devices()
|
|
655
|
+
)
|
|
656
|
+
add_function_test(TestVolume, "test_volume_introspection", test_volume_introspection, devices=devices)
|
|
657
|
+
add_function_test(
|
|
658
|
+
TestVolume, "test_volume_from_numpy", test_volume_from_numpy, devices=get_selected_cuda_test_devices()
|
|
659
|
+
)
|
|
660
|
+
|
|
661
|
+
points = {}
|
|
662
|
+
points_jittered = {}
|
|
663
|
+
for device in devices:
|
|
664
|
+
points_jittered_np = point_grid + rng.uniform(-0.5, 0.5, size=point_grid.shape)
|
|
665
|
+
points[device.alias] = wp.array(point_grid, dtype=wp.vec3, device=device)
|
|
666
|
+
points_jittered[device.alias] = wp.array(points_jittered_np, dtype=wp.vec3, device=device)
|
|
667
|
+
|
|
668
|
+
add_kernel_test(
|
|
669
|
+
TestVolume,
|
|
670
|
+
test_volume_lookup_f,
|
|
671
|
+
dim=len(point_grid),
|
|
672
|
+
inputs=[volumes["float"][device.alias].id, points[device.alias]],
|
|
673
|
+
devices=[device],
|
|
674
|
+
)
|
|
675
|
+
add_kernel_test(
|
|
676
|
+
TestVolume,
|
|
677
|
+
test_volume_sample_closest_f,
|
|
678
|
+
dim=len(point_grid),
|
|
679
|
+
inputs=[volumes["float"][device.alias].id, points_jittered[device.alias]],
|
|
680
|
+
devices=[device.alias],
|
|
681
|
+
)
|
|
682
|
+
add_kernel_test(
|
|
683
|
+
TestVolume,
|
|
684
|
+
test_volume_sample_linear_f,
|
|
685
|
+
dim=len(point_grid),
|
|
686
|
+
inputs=[volumes["float"][device.alias].id, points_jittered[device.alias]],
|
|
687
|
+
devices=[device.alias],
|
|
688
|
+
)
|
|
689
|
+
add_kernel_test(
|
|
690
|
+
TestVolume,
|
|
691
|
+
test_volume_sample_grad_linear_f,
|
|
692
|
+
dim=len(point_grid),
|
|
693
|
+
inputs=[volumes["float"][device.alias].id, points_jittered[device.alias]],
|
|
694
|
+
devices=[device.alias],
|
|
695
|
+
)
|
|
696
|
+
|
|
697
|
+
add_kernel_test(
|
|
698
|
+
TestVolume,
|
|
699
|
+
test_volume_lookup_v,
|
|
700
|
+
dim=len(point_grid),
|
|
701
|
+
inputs=[volumes["vec3f"][device.alias].id, points[device.alias]],
|
|
702
|
+
devices=[device.alias],
|
|
703
|
+
)
|
|
704
|
+
add_kernel_test(
|
|
705
|
+
TestVolume,
|
|
706
|
+
test_volume_sample_closest_v,
|
|
707
|
+
dim=len(point_grid),
|
|
708
|
+
inputs=[volumes["vec3f"][device.alias].id, points_jittered[device.alias]],
|
|
709
|
+
devices=[device.alias],
|
|
710
|
+
)
|
|
711
|
+
add_kernel_test(
|
|
712
|
+
TestVolume,
|
|
713
|
+
test_volume_sample_linear_v,
|
|
714
|
+
dim=len(point_grid),
|
|
715
|
+
inputs=[volumes["vec3f"][device.alias].id, points_jittered[device.alias]],
|
|
716
|
+
devices=[device.alias],
|
|
717
|
+
)
|
|
718
|
+
|
|
719
|
+
add_kernel_test(
|
|
720
|
+
TestVolume,
|
|
721
|
+
test_volume_lookup_i,
|
|
722
|
+
dim=len(point_grid),
|
|
723
|
+
inputs=[volumes["int32"][device.alias].id, points[device.alias]],
|
|
724
|
+
devices=[device.alias],
|
|
725
|
+
)
|
|
726
|
+
add_kernel_test(
|
|
727
|
+
TestVolume,
|
|
728
|
+
test_volume_sample_i,
|
|
729
|
+
dim=len(point_grid),
|
|
730
|
+
inputs=[volumes["int32"][device.alias].id, points_jittered[device.alias]],
|
|
731
|
+
devices=[device.alias],
|
|
732
|
+
)
|
|
733
|
+
|
|
734
|
+
|
|
735
|
+
if __name__ == "__main__":
|
|
736
|
+
wp.build.clear_kernel_cache()
|
|
737
|
+
unittest.main(verbosity=2)
|