warp-lang 1.0.0b2__py3-none-manylinux2014_x86_64.whl → 1.0.0b6__py3-none-manylinux2014_x86_64.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.
Files changed (269) hide show
  1. docs/conf.py +17 -5
  2. examples/env/env_ant.py +1 -1
  3. examples/env/env_cartpole.py +1 -1
  4. examples/env/env_humanoid.py +1 -1
  5. examples/env/env_usd.py +4 -1
  6. examples/env/environment.py +8 -9
  7. examples/example_dem.py +34 -33
  8. examples/example_diffray.py +364 -337
  9. examples/example_fluid.py +32 -23
  10. examples/example_jacobian_ik.py +97 -93
  11. examples/example_marching_cubes.py +6 -16
  12. examples/example_mesh.py +6 -16
  13. examples/example_mesh_intersect.py +16 -14
  14. examples/example_nvdb.py +14 -16
  15. examples/example_raycast.py +14 -13
  16. examples/example_raymarch.py +16 -23
  17. examples/example_render_opengl.py +19 -10
  18. examples/example_sim_cartpole.py +82 -78
  19. examples/example_sim_cloth.py +45 -48
  20. examples/example_sim_fk_grad.py +51 -44
  21. examples/example_sim_fk_grad_torch.py +47 -40
  22. examples/example_sim_grad_bounce.py +108 -133
  23. examples/example_sim_grad_cloth.py +99 -113
  24. examples/example_sim_granular.py +5 -6
  25. examples/{example_sim_sdf_shape.py → example_sim_granular_collision_sdf.py} +37 -26
  26. examples/example_sim_neo_hookean.py +51 -55
  27. examples/example_sim_particle_chain.py +4 -4
  28. examples/example_sim_quadruped.py +126 -81
  29. examples/example_sim_rigid_chain.py +54 -61
  30. examples/example_sim_rigid_contact.py +66 -70
  31. examples/example_sim_rigid_fem.py +3 -3
  32. examples/example_sim_rigid_force.py +1 -1
  33. examples/example_sim_rigid_gyroscopic.py +3 -4
  34. examples/example_sim_rigid_kinematics.py +28 -39
  35. examples/example_sim_trajopt.py +112 -110
  36. examples/example_sph.py +9 -8
  37. examples/example_wave.py +7 -7
  38. examples/fem/bsr_utils.py +30 -17
  39. examples/fem/example_apic_fluid.py +85 -69
  40. examples/fem/example_convection_diffusion.py +97 -93
  41. examples/fem/example_convection_diffusion_dg.py +142 -149
  42. examples/fem/example_convection_diffusion_dg0.py +141 -136
  43. examples/fem/example_deformed_geometry.py +146 -0
  44. examples/fem/example_diffusion.py +115 -84
  45. examples/fem/example_diffusion_3d.py +116 -86
  46. examples/fem/example_diffusion_mgpu.py +102 -79
  47. examples/fem/example_mixed_elasticity.py +139 -100
  48. examples/fem/example_navier_stokes.py +175 -162
  49. examples/fem/example_stokes.py +143 -111
  50. examples/fem/example_stokes_transfer.py +186 -157
  51. examples/fem/mesh_utils.py +59 -97
  52. examples/fem/plot_utils.py +138 -17
  53. tools/ci/publishing/build_nodes_info.py +54 -0
  54. warp/__init__.py +4 -3
  55. warp/__init__.pyi +1 -0
  56. warp/bin/warp-clang.so +0 -0
  57. warp/bin/warp.so +0 -0
  58. warp/build.py +5 -3
  59. warp/build_dll.py +29 -9
  60. warp/builtins.py +836 -492
  61. warp/codegen.py +864 -553
  62. warp/config.py +3 -1
  63. warp/context.py +389 -172
  64. warp/fem/__init__.py +24 -6
  65. warp/fem/cache.py +318 -25
  66. warp/fem/dirichlet.py +7 -3
  67. warp/fem/domain.py +14 -0
  68. warp/fem/field/__init__.py +30 -38
  69. warp/fem/field/field.py +149 -0
  70. warp/fem/field/nodal_field.py +244 -138
  71. warp/fem/field/restriction.py +8 -6
  72. warp/fem/field/test.py +127 -59
  73. warp/fem/field/trial.py +117 -60
  74. warp/fem/geometry/__init__.py +5 -1
  75. warp/fem/geometry/deformed_geometry.py +271 -0
  76. warp/fem/geometry/element.py +24 -1
  77. warp/fem/geometry/geometry.py +86 -14
  78. warp/fem/geometry/grid_2d.py +112 -54
  79. warp/fem/geometry/grid_3d.py +134 -65
  80. warp/fem/geometry/hexmesh.py +953 -0
  81. warp/fem/geometry/partition.py +85 -33
  82. warp/fem/geometry/quadmesh_2d.py +532 -0
  83. warp/fem/geometry/tetmesh.py +451 -115
  84. warp/fem/geometry/trimesh_2d.py +197 -92
  85. warp/fem/integrate.py +534 -268
  86. warp/fem/operator.py +58 -31
  87. warp/fem/polynomial.py +11 -0
  88. warp/fem/quadrature/__init__.py +1 -1
  89. warp/fem/quadrature/pic_quadrature.py +150 -58
  90. warp/fem/quadrature/quadrature.py +209 -57
  91. warp/fem/space/__init__.py +230 -53
  92. warp/fem/space/basis_space.py +489 -0
  93. warp/fem/space/collocated_function_space.py +105 -0
  94. warp/fem/space/dof_mapper.py +49 -2
  95. warp/fem/space/function_space.py +90 -39
  96. warp/fem/space/grid_2d_function_space.py +149 -496
  97. warp/fem/space/grid_3d_function_space.py +173 -538
  98. warp/fem/space/hexmesh_function_space.py +352 -0
  99. warp/fem/space/partition.py +129 -76
  100. warp/fem/space/quadmesh_2d_function_space.py +369 -0
  101. warp/fem/space/restriction.py +46 -34
  102. warp/fem/space/shape/__init__.py +15 -0
  103. warp/fem/space/shape/cube_shape_function.py +738 -0
  104. warp/fem/space/shape/shape_function.py +103 -0
  105. warp/fem/space/shape/square_shape_function.py +611 -0
  106. warp/fem/space/shape/tet_shape_function.py +567 -0
  107. warp/fem/space/shape/triangle_shape_function.py +429 -0
  108. warp/fem/space/tetmesh_function_space.py +132 -1039
  109. warp/fem/space/topology.py +295 -0
  110. warp/fem/space/trimesh_2d_function_space.py +104 -742
  111. warp/fem/types.py +13 -11
  112. warp/fem/utils.py +335 -60
  113. warp/native/array.h +120 -34
  114. warp/native/builtin.h +101 -72
  115. warp/native/bvh.cpp +73 -325
  116. warp/native/bvh.cu +406 -23
  117. warp/native/bvh.h +22 -40
  118. warp/native/clang/clang.cpp +1 -0
  119. warp/native/crt.h +2 -0
  120. warp/native/cuda_util.cpp +8 -3
  121. warp/native/cuda_util.h +1 -0
  122. warp/native/exports.h +1522 -1243
  123. warp/native/intersect.h +19 -4
  124. warp/native/intersect_adj.h +8 -8
  125. warp/native/mat.h +76 -17
  126. warp/native/mesh.cpp +33 -108
  127. warp/native/mesh.cu +114 -18
  128. warp/native/mesh.h +395 -40
  129. warp/native/noise.h +272 -329
  130. warp/native/quat.h +51 -8
  131. warp/native/rand.h +44 -34
  132. warp/native/reduce.cpp +1 -1
  133. warp/native/sparse.cpp +4 -4
  134. warp/native/sparse.cu +163 -155
  135. warp/native/spatial.h +2 -2
  136. warp/native/temp_buffer.h +18 -14
  137. warp/native/vec.h +103 -21
  138. warp/native/warp.cpp +2 -1
  139. warp/native/warp.cu +28 -3
  140. warp/native/warp.h +4 -3
  141. warp/render/render_opengl.py +261 -109
  142. warp/sim/__init__.py +1 -2
  143. warp/sim/articulation.py +385 -185
  144. warp/sim/import_mjcf.py +59 -48
  145. warp/sim/import_urdf.py +15 -15
  146. warp/sim/import_usd.py +174 -102
  147. warp/sim/inertia.py +17 -18
  148. warp/sim/integrator_xpbd.py +4 -3
  149. warp/sim/model.py +330 -250
  150. warp/sim/render.py +1 -1
  151. warp/sparse.py +625 -152
  152. warp/stubs.py +341 -309
  153. warp/tape.py +9 -6
  154. warp/tests/__main__.py +3 -6
  155. warp/tests/assets/curlnoise_golden.npy +0 -0
  156. warp/tests/assets/pnoise_golden.npy +0 -0
  157. warp/tests/{test_class_kernel.py → aux_test_class_kernel.py} +9 -1
  158. warp/tests/aux_test_conditional_unequal_types_kernels.py +21 -0
  159. warp/tests/{test_dependent.py → aux_test_dependent.py} +2 -2
  160. warp/tests/{test_reference.py → aux_test_reference.py} +1 -1
  161. warp/tests/aux_test_unresolved_func.py +14 -0
  162. warp/tests/aux_test_unresolved_symbol.py +14 -0
  163. warp/tests/disabled_kinematics.py +239 -0
  164. warp/tests/run_coverage_serial.py +31 -0
  165. warp/tests/test_adam.py +103 -106
  166. warp/tests/test_arithmetic.py +94 -74
  167. warp/tests/test_array.py +82 -101
  168. warp/tests/test_array_reduce.py +57 -23
  169. warp/tests/test_atomic.py +64 -28
  170. warp/tests/test_bool.py +22 -12
  171. warp/tests/test_builtins_resolution.py +1292 -0
  172. warp/tests/test_bvh.py +18 -18
  173. warp/tests/test_closest_point_edge_edge.py +54 -57
  174. warp/tests/test_codegen.py +165 -134
  175. warp/tests/test_compile_consts.py +28 -20
  176. warp/tests/test_conditional.py +108 -24
  177. warp/tests/test_copy.py +10 -12
  178. warp/tests/test_ctypes.py +112 -88
  179. warp/tests/test_dense.py +21 -14
  180. warp/tests/test_devices.py +98 -0
  181. warp/tests/test_dlpack.py +75 -75
  182. warp/tests/test_examples.py +237 -0
  183. warp/tests/test_fabricarray.py +22 -24
  184. warp/tests/test_fast_math.py +15 -11
  185. warp/tests/test_fem.py +1034 -124
  186. warp/tests/test_fp16.py +23 -16
  187. warp/tests/test_func.py +187 -86
  188. warp/tests/test_generics.py +194 -49
  189. warp/tests/test_grad.py +123 -181
  190. warp/tests/test_grad_customs.py +176 -0
  191. warp/tests/test_hash_grid.py +35 -34
  192. warp/tests/test_import.py +10 -23
  193. warp/tests/test_indexedarray.py +24 -25
  194. warp/tests/test_intersect.py +18 -9
  195. warp/tests/test_large.py +141 -0
  196. warp/tests/test_launch.py +14 -41
  197. warp/tests/test_lerp.py +64 -65
  198. warp/tests/test_lvalue.py +493 -0
  199. warp/tests/test_marching_cubes.py +12 -13
  200. warp/tests/test_mat.py +517 -2898
  201. warp/tests/test_mat_lite.py +115 -0
  202. warp/tests/test_mat_scalar_ops.py +2889 -0
  203. warp/tests/test_math.py +103 -9
  204. warp/tests/test_matmul.py +304 -69
  205. warp/tests/test_matmul_lite.py +410 -0
  206. warp/tests/test_mesh.py +60 -22
  207. warp/tests/test_mesh_query_aabb.py +21 -25
  208. warp/tests/test_mesh_query_point.py +111 -22
  209. warp/tests/test_mesh_query_ray.py +12 -24
  210. warp/tests/test_mlp.py +30 -22
  211. warp/tests/test_model.py +92 -89
  212. warp/tests/test_modules_lite.py +39 -0
  213. warp/tests/test_multigpu.py +88 -114
  214. warp/tests/test_noise.py +12 -11
  215. warp/tests/test_operators.py +16 -20
  216. warp/tests/test_options.py +11 -11
  217. warp/tests/test_pinned.py +17 -18
  218. warp/tests/test_print.py +32 -11
  219. warp/tests/test_quat.py +275 -129
  220. warp/tests/test_rand.py +18 -16
  221. warp/tests/test_reload.py +38 -34
  222. warp/tests/test_rounding.py +50 -43
  223. warp/tests/test_runlength_encode.py +168 -20
  224. warp/tests/test_smoothstep.py +9 -11
  225. warp/tests/test_snippet.py +143 -0
  226. warp/tests/test_sparse.py +261 -63
  227. warp/tests/test_spatial.py +276 -243
  228. warp/tests/test_streams.py +110 -85
  229. warp/tests/test_struct.py +268 -63
  230. warp/tests/test_tape.py +39 -21
  231. warp/tests/test_torch.py +90 -86
  232. warp/tests/test_transient_module.py +10 -12
  233. warp/tests/test_types.py +363 -0
  234. warp/tests/test_utils.py +451 -0
  235. warp/tests/test_vec.py +354 -2050
  236. warp/tests/test_vec_lite.py +73 -0
  237. warp/tests/test_vec_scalar_ops.py +2099 -0
  238. warp/tests/test_volume.py +418 -376
  239. warp/tests/test_volume_write.py +124 -134
  240. warp/tests/unittest_serial.py +35 -0
  241. warp/tests/unittest_suites.py +291 -0
  242. warp/tests/unittest_utils.py +342 -0
  243. warp/tests/{test_misc.py → unused_test_misc.py} +13 -5
  244. warp/tests/{test_debug.py → walkthough_debug.py} +3 -17
  245. warp/thirdparty/appdirs.py +36 -45
  246. warp/thirdparty/unittest_parallel.py +589 -0
  247. warp/types.py +622 -211
  248. warp/utils.py +54 -393
  249. warp_lang-1.0.0b6.dist-info/METADATA +238 -0
  250. warp_lang-1.0.0b6.dist-info/RECORD +409 -0
  251. {warp_lang-1.0.0b2.dist-info → warp_lang-1.0.0b6.dist-info}/WHEEL +1 -1
  252. examples/example_cache_management.py +0 -40
  253. examples/example_multigpu.py +0 -54
  254. examples/example_struct.py +0 -65
  255. examples/fem/example_stokes_transfer_3d.py +0 -210
  256. warp/fem/field/discrete_field.py +0 -80
  257. warp/fem/space/nodal_function_space.py +0 -233
  258. warp/tests/test_all.py +0 -223
  259. warp/tests/test_array_scan.py +0 -60
  260. warp/tests/test_base.py +0 -208
  261. warp/tests/test_unresolved_func.py +0 -7
  262. warp/tests/test_unresolved_symbol.py +0 -7
  263. warp_lang-1.0.0b2.dist-info/METADATA +0 -26
  264. warp_lang-1.0.0b2.dist-info/RECORD +0 -378
  265. /warp/tests/{test_compile_consts_dummy.py → aux_test_compile_consts_dummy.py} +0 -0
  266. /warp/tests/{test_reference_reference.py → aux_test_reference_reference.py} +0 -0
  267. /warp/tests/{test_square.py → aux_test_square.py} +0 -0
  268. {warp_lang-1.0.0b2.dist-info → warp_lang-1.0.0b6.dist-info}/LICENSE.md +0 -0
  269. {warp_lang-1.0.0b2.dist-info → warp_lang-1.0.0b6.dist-info}/top_level.txt +0 -0
warp/tests/test_volume.py CHANGED
@@ -5,11 +5,13 @@
5
5
  # distribution of this software and related documentation without an express
6
6
  # license agreement from NVIDIA CORPORATION is strictly prohibited.
7
7
 
8
- import warp as wp
9
- from warp.tests.test_base import *
8
+ import unittest
10
9
 
11
10
  import numpy as np
12
11
 
12
+ import warp as wp
13
+ from warp.tests.unittest_utils import *
14
+
13
15
  wp.init()
14
16
 
15
17
 
@@ -61,6 +63,7 @@ def test_volume_sample_linear_f(volume: wp.uint64, points: wp.array(dtype=wp.vec
61
63
 
62
64
  expect_near(wp.volume_sample_f(volume, p, wp.Volume.LINEAR), expected, 2.0e-4)
63
65
 
66
+
64
67
  @wp.kernel
65
68
  def test_volume_sample_grad_linear_f(volume: wp.uint64, points: wp.array(dtype=wp.vec3)):
66
69
  tid = wp.tid()
@@ -74,15 +77,16 @@ def test_volume_sample_grad_linear_f(volume: wp.uint64, points: wp.array(dtype=w
74
77
 
75
78
  if abs(p[0]) > 10.0 or abs(p[1]) > 10.0 or abs(p[2]) > 10.0:
76
79
  return # not testing against background values
77
-
80
+
78
81
  grad = wp.vec3(0.0, 0.0, 0.0)
79
82
  val = wp.volume_sample_grad_f(volume, p, wp.Volume.LINEAR, grad)
80
-
83
+
81
84
  expect_near(val, expected_val, 2.0e-4)
82
85
  expect_near(grad[0], expected_gx, 2.0e-4)
83
86
  expect_near(grad[1], expected_gy, 2.0e-4)
84
87
  expect_near(grad[2], expected_gz, 2.0e-4)
85
88
 
89
+
86
90
  @wp.kernel
87
91
  def test_volume_sample_local_f_linear_values(
88
92
  volume: wp.uint64, points: wp.array(dtype=wp.vec3), values: wp.array(dtype=wp.float32)
@@ -91,23 +95,25 @@ def test_volume_sample_local_f_linear_values(
91
95
  p = points[tid]
92
96
  values[tid] = wp.volume_sample_f(volume, p, wp.Volume.LINEAR)
93
97
 
98
+
94
99
  @wp.kernel
95
100
  def test_volume_sample_grad_local_f_linear_values(
96
- volume: wp.uint64, points: wp.array(dtype=wp.vec3), values: wp.array(dtype=wp.float32), case_num:int
101
+ volume: wp.uint64, points: wp.array(dtype=wp.vec3), values: wp.array(dtype=wp.float32), case_num: int
97
102
  ):
98
103
  tid = wp.tid()
99
104
  p = points[tid]
100
105
 
101
- grad = wp.vec3(0.0, 0.0, 0.0)
106
+ grad = wp.vec3(0.0, 0.0, 0.0)
102
107
  val = wp.volume_sample_grad_f(volume, p, wp.Volume.LINEAR, grad)
103
- if case_num == 0:
104
- values[tid] = val
105
- elif case_num == 1:
106
- values[tid] = grad[0]
108
+
109
+ if case_num == 1:
110
+ val = grad[0]
107
111
  elif case_num == 2:
108
- values[tid] = grad[1]
112
+ val = grad[1]
109
113
  elif case_num == 3:
110
- values[tid] = grad[2]
114
+ val = grad[2]
115
+ values[tid] = val
116
+
111
117
 
112
118
  @wp.kernel
113
119
  def test_volume_sample_world_f_linear_values(
@@ -121,22 +127,24 @@ def test_volume_sample_world_f_linear_values(
121
127
 
122
128
  @wp.kernel
123
129
  def test_volume_sample_grad_world_f_linear_values(
124
- volume: wp.uint64, points: wp.array(dtype=wp.vec3), values: wp.array(dtype=wp.float32), case_num:int
130
+ volume: wp.uint64, points: wp.array(dtype=wp.vec3), values: wp.array(dtype=wp.float32), case_num: int
125
131
  ):
126
132
  tid = wp.tid()
127
133
  q = points[tid]
128
134
  p = wp.volume_world_to_index(volume, q)
129
135
 
130
- grad = wp.vec3(0.0, 0.0, 0.0)
136
+ grad = wp.vec3(0.0, 0.0, 0.0)
131
137
  val = wp.volume_sample_grad_f(volume, p, wp.Volume.LINEAR, grad)
132
- if case_num == 0:
133
- values[tid] = val
134
- elif case_num == 1:
135
- values[tid] = grad[0]
138
+
139
+ if case_num == 1:
140
+ val = grad[0]
136
141
  elif case_num == 2:
137
- values[tid] = grad[1]
142
+ val = grad[1]
138
143
  elif case_num == 3:
139
- values[tid] = grad[2]
144
+ val = grad[2]
145
+
146
+ values[tid] = val
147
+
140
148
 
141
149
  # vec3f volume tests
142
150
  @wp.kernel
@@ -322,373 +330,407 @@ def test_volume_store_i(volume: wp.uint64, points: wp.array(dtype=wp.vec3), valu
322
330
  values[tid] = wp.volume_lookup_i(volume, i, j, k)
323
331
 
324
332
 
325
- def register(parent):
326
- devices = get_test_devices()
327
- rng = np.random.default_rng(101215)
328
-
329
- # Note about the test grids:
330
- # test_grid and test_int32_grid
331
- # active region: [-10,10]^3
332
- # values: v[i,j,k] = i * j * k
333
- # voxel size: 0.25
334
- #
335
- # test_vec_grid
336
- # active region: [-10,10]^3
337
- # values: v[i,j,k] = (i + 2*j + 3*k, 4*i + 5*j + 6*k, 7*i + 8*j + 9*k)
338
- # voxel size: 0.25
339
- #
340
- # torus
341
- # index to world transformation:
342
- # [0.1, 0, 0, 0]
343
- # [0, 0, 0.1, 0]
344
- # [0, 0.1, 0, 0]
345
- # [1, 2, 3, 1]
346
- # (-90 degrees rotation along X)
347
- # voxel size: 0.1
348
- volume_paths = {
349
- "float": os.path.abspath(os.path.join(os.path.dirname(__file__), "assets/test_grid.nvdb")),
350
- "int32": os.path.abspath(os.path.join(os.path.dirname(__file__), "assets/test_int32_grid.nvdb")),
351
- "vec3f": os.path.abspath(os.path.join(os.path.dirname(__file__), "assets/test_vec_grid.nvdb")),
352
- "torus": os.path.abspath(os.path.join(os.path.dirname(__file__), "assets/torus.nvdb")),
353
- "float_write": os.path.abspath(os.path.join(os.path.dirname(__file__), "assets/test_grid.nvdb")),
354
- }
355
-
356
- test_volume_tiles = (
357
- 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
358
- )
333
+ devices = get_test_devices()
334
+ rng = np.random.default_rng(101215)
335
+
336
+ # Note about the test grids:
337
+ # test_grid and test_int32_grid
338
+ # active region: [-10,10]^3
339
+ # values: v[i,j,k] = i * j * k
340
+ # voxel size: 0.25
341
+ #
342
+ # test_vec_grid
343
+ # active region: [-10,10]^3
344
+ # values: v[i,j,k] = (i + 2*j + 3*k, 4*i + 5*j + 6*k, 7*i + 8*j + 9*k)
345
+ # voxel size: 0.25
346
+ #
347
+ # torus
348
+ # index to world transformation:
349
+ # [0.1, 0, 0, 0]
350
+ # [0, 0, 0.1, 0]
351
+ # [0, 0.1, 0, 0]
352
+ # [1, 2, 3, 1]
353
+ # (-90 degrees rotation along X)
354
+ # voxel size: 0.1
355
+ volume_paths = {
356
+ "float": os.path.abspath(os.path.join(os.path.dirname(__file__), "assets/test_grid.nvdb")),
357
+ "int32": os.path.abspath(os.path.join(os.path.dirname(__file__), "assets/test_int32_grid.nvdb")),
358
+ "vec3f": os.path.abspath(os.path.join(os.path.dirname(__file__), "assets/test_vec_grid.nvdb")),
359
+ "torus": os.path.abspath(os.path.join(os.path.dirname(__file__), "assets/torus.nvdb")),
360
+ "float_write": os.path.abspath(os.path.join(os.path.dirname(__file__), "assets/test_grid.nvdb")),
361
+ }
362
+
363
+ test_volume_tiles = (
364
+ 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
365
+ )
366
+
367
+ volumes = {}
368
+ for value_type, path in volume_paths.items():
369
+ volumes[value_type] = {}
370
+ volume_data = open(path, "rb").read()
371
+ for device in devices:
372
+ try:
373
+ volume = wp.Volume.load_from_nvdb(volume_data, device)
374
+ except RuntimeError as e:
375
+ raise RuntimeError(f'Failed to load volume from "{path}" to {device} memory:\n{e}')
376
+
377
+ volumes[value_type][device.alias] = volume
378
+
379
+ axis = np.linspace(-1, 1, 3)
380
+ point_grid = np.array([[x, y, z] for x in axis for y in axis for z in axis], dtype=np.float32)
381
+
382
+
383
+ def test_volume_sample_linear_f_gradient(test, device):
384
+ points = rng.uniform(-10.0, 10.0, size=(100, 3))
385
+ values = wp.array(np.zeros(1), dtype=wp.float32, device=device, requires_grad=True)
386
+ for test_case in points:
387
+ uvws = wp.array(test_case, dtype=wp.vec3, device=device, requires_grad=True)
388
+ xyzs = wp.array(test_case * 0.25, dtype=wp.vec3, device=device, requires_grad=True)
389
+
390
+ tape = wp.Tape()
391
+ with tape:
392
+ wp.launch(
393
+ test_volume_sample_local_f_linear_values,
394
+ dim=1,
395
+ inputs=[volumes["float"][device.alias].id, uvws, values],
396
+ device=device,
397
+ )
398
+ tape.backward(values)
399
+
400
+ x, y, z = test_case
401
+ grad_expected = np.array([y * z, x * z, x * y])
402
+ grad_computed = tape.gradients[uvws].numpy()[0]
403
+ np.testing.assert_allclose(grad_computed, grad_expected, rtol=1e-4)
404
+
405
+ tape = wp.Tape()
406
+ with tape:
407
+ wp.launch(
408
+ test_volume_sample_world_f_linear_values,
409
+ dim=1,
410
+ inputs=[volumes["float"][device.alias].id, xyzs, values],
411
+ device=device,
412
+ )
413
+ tape.backward(values)
359
414
 
360
- volumes = {}
361
- points = {}
362
- points_jittered = {}
363
- for value_type, path in volume_paths.items():
364
- volumes[value_type] = {}
365
- volume_data = open(path, "rb").read()
366
- for device in devices:
367
- try:
368
- volume = wp.Volume.load_from_nvdb(volume_data, device)
369
- except RuntimeError as e:
370
- raise RuntimeError(f'Failed to load volume from "{path}" to {device} memory:\n{e}')
371
-
372
- volumes[value_type][device.alias] = volume
373
-
374
- axis = np.linspace(-1, 1, 3)
375
- point_grid = np.array([[x, y, z] for x in axis for y in axis for z in axis], dtype=np.float32)
376
-
377
- class TestVolumes(parent):
378
- def test_volume_sample_linear_f_gradient(self):
379
- for device in devices:
380
- points = rng.uniform(-10.0, 10.0, size=(100, 3))
381
- values = wp.array(np.zeros(1), dtype=wp.float32, device=device, requires_grad=True)
382
- for case in points:
383
- uvws = wp.array(case, dtype=wp.vec3, device=device, requires_grad=True)
384
- xyzs = wp.array(case * 0.25, dtype=wp.vec3, device=device, requires_grad=True)
385
-
386
- tape = wp.Tape()
387
- with tape:
388
- wp.launch(
389
- test_volume_sample_local_f_linear_values,
390
- dim=1,
391
- inputs=[volumes["float"][device.alias].id, uvws, values],
392
- device=device,
393
- )
394
- tape.backward(values)
395
-
396
- x, y, z = case
397
- grad_expected = np.array([y * z, x * z, x * y])
398
- grad_computed = tape.gradients[uvws].numpy()[0]
399
- np.testing.assert_allclose(grad_computed, grad_expected, rtol=1e-4)
400
-
401
- tape = wp.Tape()
402
- with tape:
403
- wp.launch(
404
- test_volume_sample_world_f_linear_values,
405
- dim=1,
406
- inputs=[volumes["float"][device.alias].id, xyzs, values],
407
- device=device,
408
- )
409
- tape.backward(values)
410
-
411
- x, y, z = case
412
- grad_expected = np.array([y * z, x * z, x * y]) / 0.25
413
- grad_computed = tape.gradients[xyzs].numpy()[0]
414
- np.testing.assert_allclose(grad_computed, grad_expected, rtol=1e-4)
415
-
416
- def test_volume_sample_grad_linear_f_gradient(self):
417
- for device in devices:
418
- points = rng.uniform(-10.0, 10.0, size=(100, 3))
419
- values = wp.array(np.zeros(1), dtype=wp.float32, device=device, requires_grad=True)
420
- for case in points:
421
- uvws = wp.array(case, dtype=wp.vec3, device=device, requires_grad=True)
422
- xyzs = wp.array(case * 0.25, dtype=wp.vec3, device=device, requires_grad=True)
423
-
424
- for case_num in range(4):
425
- tape = wp.Tape()
426
- with tape:
427
- wp.launch(
428
- test_volume_sample_grad_local_f_linear_values,
429
- dim=1,
430
- inputs=[volumes["float"][device.alias].id, uvws, values, case_num],
431
- device=device,
432
- )
433
- tape.backward(values)
434
-
435
- x, y, z = case
436
- grad_computed = tape.gradients[uvws].numpy()[0]
437
- if case_num == 0:
438
- grad_expected = np.array([y * z, x * z, x * y])
439
- elif case_num == 1:
440
- grad_expected = np.array([0.0, z, y])
441
- elif case_num == 2:
442
- grad_expected = np.array([z, 0.0, x])
443
- elif case_num == 3:
444
- grad_expected = np.array([y, x, 0.0])
445
-
446
- np.testing.assert_allclose(grad_computed, grad_expected, rtol=1e-4)
447
- tape.zero()
448
-
449
- for case_num in range(4):
450
- tape = wp.Tape()
451
- with tape:
452
- wp.launch(
453
- test_volume_sample_grad_world_f_linear_values,
454
- dim=1,
455
- inputs=[volumes["float"][device.alias].id, xyzs, values, case_num],
456
- device=device,
457
- )
458
- tape.backward(values)
459
-
460
- x, y, z = case
461
- grad_computed = tape.gradients[xyzs].numpy()[0]
462
- if case_num == 0:
463
- grad_expected = np.array([y * z, x * z, x * y]) / 0.25
464
- elif case_num == 1:
465
- grad_expected = np.array([0.0, z, y]) / 0.25
466
- elif case_num == 2:
467
- grad_expected = np.array([z, 0.0, x]) / 0.25
468
- elif case_num == 3:
469
- grad_expected = np.array([y, x, 0.0]) / 0.25
470
-
471
- np.testing.assert_allclose(grad_computed, grad_expected, rtol=1e-4)
472
- tape.zero()
473
-
474
- def test_volume_sample_linear_v_gradient(self):
475
- for device in devices:
476
- points = rng.uniform(-10.0, 10.0, size=(100, 3))
477
- values = wp.zeros(1, dtype=wp.float32, device=device, requires_grad=True)
478
- for case in points:
479
- uvws = wp.array(case, dtype=wp.vec3, device=device, requires_grad=True)
480
- xyzs = wp.array(case * 0.25, dtype=wp.vec3, device=device, requires_grad=True)
481
-
482
- tape = wp.Tape()
483
- with tape:
484
- wp.launch(
485
- test_volume_sample_local_v_linear_values,
486
- dim=1,
487
- inputs=[volumes["vec3f"][device.alias].id, uvws, values],
488
- device=device,
489
- )
490
- tape.backward(values)
491
-
492
- grad_expected = np.array([6.0, 15.0, 24.0])
493
- grad_computed = tape.gradients[uvws].numpy()[0]
494
- np.testing.assert_allclose(grad_computed, grad_expected, rtol=1e-4)
495
-
496
- tape = wp.Tape()
497
- with tape:
498
- wp.launch(
499
- test_volume_sample_world_v_linear_values,
500
- dim=1,
501
- inputs=[volumes["vec3f"][device.alias].id, xyzs, values],
502
- device=device,
503
- )
504
- tape.backward(values)
505
-
506
- grad_expected = np.array([6.0, 15.0, 24.0]) / 0.25
507
- grad_computed = tape.gradients[xyzs].numpy()[0]
508
- np.testing.assert_allclose(grad_computed, grad_expected, rtol=1e-4)
509
-
510
- def test_volume_transform_gradient(self):
511
- for device in devices:
512
- values = wp.zeros(1, dtype=wp.float32, device=device, requires_grad=True)
513
- grad_values = wp.zeros(1, dtype=wp.vec3, device=device)
514
- points = rng.uniform(-10.0, 10.0, size=(10, 3))
515
- for case in points:
516
- points = wp.array(case, dtype=wp.vec3, device=device, requires_grad=True)
517
- tape = wp.Tape()
518
- with tape:
519
- wp.launch(
520
- test_volume_index_to_world,
521
- dim=1,
522
- inputs=[volumes["torus"][device.alias].id, points, values, grad_values],
523
- device=device,
524
- )
525
- tape.backward(values)
526
-
527
- grad_computed = tape.gradients[points].numpy()
528
- grad_expected = grad_values.numpy()
529
- np.testing.assert_allclose(grad_computed, grad_expected, rtol=1e-4)
530
-
531
- grad_computed = tape.gradients[points].numpy()
532
- grad_expected = grad_values.numpy()
533
- np.testing.assert_allclose(grad_computed, grad_expected, rtol=1e-4)
534
-
535
- def test_volume_store(self):
536
- values_ref = np.array([x + 100 * y + 10000 * z for x, y, z in point_grid])
537
- for device in devices:
538
- points = wp.array(point_grid, dtype=wp.vec3, device=device)
539
- values = wp.empty(len(point_grid), dtype=wp.float32, device=device)
540
- wp.launch(
541
- test_volume_store_f,
542
- dim=len(point_grid),
543
- inputs=[volumes["float_write"][device.alias].id, points, values],
544
- device=device,
545
- )
415
+ x, y, z = test_case
416
+ grad_expected = np.array([y * z, x * z, x * y]) / 0.25
417
+ grad_computed = tape.gradients[xyzs].numpy()[0]
418
+ np.testing.assert_allclose(grad_computed, grad_expected, rtol=1e-4)
546
419
 
547
- values_res = values.numpy()
548
- np.testing.assert_equal(values_res, values_ref)
549
420
 
550
- def test_volume_allocation_f(self):
551
- bg_value = -123.0
552
- points_np = np.append(point_grid, [[8096, 8096, 8096]], axis=0)
553
- values_ref = np.append(np.array([x + 100 * y + 10000 * z for x, y, z in point_grid]), bg_value)
554
- for device in devices:
555
- if device.is_cpu:
556
- continue
421
+ def test_volume_sample_grad_linear_f_gradient(test, device):
422
+ points = rng.uniform(-10.0, 10.0, size=(100, 3))
423
+ values = wp.array(np.zeros(1), dtype=wp.float32, device=device, requires_grad=True)
424
+ for test_case in points:
425
+ uvws = wp.array(test_case, dtype=wp.vec3, device=device, requires_grad=True)
426
+ xyzs = wp.array(test_case * 0.25, dtype=wp.vec3, device=device, requires_grad=True)
557
427
 
558
- volume = wp.Volume.allocate(
559
- min=[-11, -11, -11], max=[11, 11, 11], voxel_size=0.1, bg_value=bg_value, device=device
428
+ for case_num in range(4):
429
+ tape = wp.Tape()
430
+ with tape:
431
+ wp.launch(
432
+ test_volume_sample_grad_local_f_linear_values,
433
+ dim=1,
434
+ inputs=[volumes["float"][device.alias].id, uvws, values, case_num],
435
+ device=device,
560
436
  )
561
- points = wp.array(points_np, dtype=wp.vec3, device=device)
562
- values = wp.empty(len(points_np), dtype=wp.float32, device=device)
563
- wp.launch(test_volume_store_f, dim=len(points_np), inputs=[volume.id, points, values], device=device)
564
-
565
- values_res = values.numpy()
566
- np.testing.assert_equal(values_res, values_ref)
567
-
568
- def test_volume_allocation_v(self):
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
- for device in devices:
573
- if device.is_cpu:
574
- continue
575
-
576
- volume = wp.Volume.allocate(
577
- min=[-11, -11, -11], max=[11, 11, 11], voxel_size=0.1, bg_value=bg_value, device=device
437
+ tape.backward(values)
438
+
439
+ x, y, z = test_case
440
+ grad_computed = tape.gradients[uvws].numpy()[0]
441
+ if case_num == 0:
442
+ grad_expected = np.array([y * z, x * z, x * y])
443
+ elif case_num == 1:
444
+ grad_expected = np.array([0.0, z, y])
445
+ elif case_num == 2:
446
+ grad_expected = np.array([z, 0.0, x])
447
+ elif case_num == 3:
448
+ grad_expected = np.array([y, x, 0.0])
449
+
450
+ np.testing.assert_allclose(grad_computed, grad_expected, rtol=1e-4)
451
+ tape.zero()
452
+
453
+ for case_num in range(4):
454
+ tape = wp.Tape()
455
+ with tape:
456
+ wp.launch(
457
+ test_volume_sample_grad_world_f_linear_values,
458
+ dim=1,
459
+ inputs=[volumes["float"][device.alias].id, xyzs, values, case_num],
460
+ device=device,
578
461
  )
579
- points = wp.array(points_np, dtype=wp.vec3, device=device)
580
- values = wp.empty(len(points_np), dtype=wp.vec3, device=device)
581
- wp.launch(test_volume_store_v, dim=len(points_np), inputs=[volume.id, points, values], device=device)
582
-
583
- values_res = values.numpy()
584
- np.testing.assert_equal(values_res, values_ref)
585
-
586
- def test_volume_allocation_i(self):
587
- bg_value = -123
588
- points_np = np.append(point_grid, [[8096, 8096, 8096]], axis=0)
589
- values_ref = np.append(
590
- np.array([x + 100 * y + 10000 * z for x, y, z in point_grid], dtype=np.int32), bg_value
462
+ tape.backward(values)
463
+
464
+ x, y, z = test_case
465
+ grad_computed = tape.gradients[xyzs].numpy()[0]
466
+ if case_num == 0:
467
+ grad_expected = np.array([y * z, x * z, x * y]) / 0.25
468
+ elif case_num == 1:
469
+ grad_expected = np.array([0.0, z, y]) / 0.25
470
+ elif case_num == 2:
471
+ grad_expected = np.array([z, 0.0, x]) / 0.25
472
+ elif case_num == 3:
473
+ grad_expected = np.array([y, x, 0.0]) / 0.25
474
+
475
+ np.testing.assert_allclose(grad_computed, grad_expected, rtol=1e-4)
476
+ tape.zero()
477
+
478
+
479
+ def test_volume_sample_linear_v_gradient(test, device):
480
+ points = rng.uniform(-10.0, 10.0, size=(100, 3))
481
+ values = wp.zeros(1, dtype=wp.float32, device=device, requires_grad=True)
482
+ for test_case in points:
483
+ uvws = wp.array(test_case, dtype=wp.vec3, device=device, requires_grad=True)
484
+ xyzs = wp.array(test_case * 0.25, dtype=wp.vec3, device=device, requires_grad=True)
485
+
486
+ tape = wp.Tape()
487
+ with tape:
488
+ wp.launch(
489
+ test_volume_sample_local_v_linear_values,
490
+ dim=1,
491
+ inputs=[volumes["vec3f"][device.alias].id, uvws, values],
492
+ device=device,
591
493
  )
592
- for device in devices:
593
- if device.is_cpu:
594
- continue
595
-
596
- volume = wp.Volume.allocate(
597
- min=[-11, -11, -11], max=[11, 11, 11], voxel_size=0.1, bg_value=bg_value, device=device
598
- )
599
- points = wp.array(points_np, dtype=wp.vec3, device=device)
600
- values = wp.empty(len(points_np), dtype=wp.int32, device=device)
601
- wp.launch(test_volume_store_i, dim=len(points_np), inputs=[volume.id, points, values], device=device)
602
-
603
- values_res = values.numpy()
604
- np.testing.assert_equal(values_res, values_ref)
494
+ tape.backward(values)
495
+
496
+ grad_expected = np.array([6.0, 15.0, 24.0])
497
+ grad_computed = tape.gradients[uvws].numpy()[0]
498
+ np.testing.assert_allclose(grad_computed, grad_expected, rtol=1e-4)
499
+
500
+ tape = wp.Tape()
501
+ with tape:
502
+ wp.launch(
503
+ test_volume_sample_world_v_linear_values,
504
+ dim=1,
505
+ inputs=[volumes["vec3f"][device.alias].id, xyzs, values],
506
+ device=device,
507
+ )
508
+ tape.backward(values)
509
+
510
+ grad_expected = np.array([6.0, 15.0, 24.0]) / 0.25
511
+ grad_computed = tape.gradients[xyzs].numpy()[0]
512
+ np.testing.assert_allclose(grad_computed, grad_expected, rtol=1e-4)
513
+
514
+
515
+ def test_volume_transform_gradient(test, device):
516
+ values = wp.zeros(1, dtype=wp.float32, device=device, requires_grad=True)
517
+ grad_values = wp.zeros(1, dtype=wp.vec3, device=device)
518
+ test_points = rng.uniform(-10.0, 10.0, size=(10, 3))
519
+ for test_case in test_points:
520
+ points = wp.array(test_case, dtype=wp.vec3, device=device, requires_grad=True)
521
+ tape = wp.Tape()
522
+ with tape:
523
+ wp.launch(
524
+ test_volume_index_to_world,
525
+ dim=1,
526
+ inputs=[volumes["torus"][device.alias].id, points, values, grad_values],
527
+ device=device,
528
+ )
529
+ tape.backward(values)
530
+
531
+ grad_computed = tape.gradients[points].numpy()
532
+ grad_expected = grad_values.numpy()
533
+ np.testing.assert_allclose(grad_computed, grad_expected, rtol=1e-4)
534
+
535
+ grad_computed = tape.gradients[points].numpy()
536
+ grad_expected = grad_values.numpy()
537
+ np.testing.assert_allclose(grad_computed, grad_expected, rtol=1e-4)
538
+
539
+
540
+ def test_volume_store(test, device):
541
+ values_ref = np.array([x + 100 * y + 10000 * z for x, y, z in point_grid])
542
+ points = wp.array(point_grid, dtype=wp.vec3, device=device)
543
+ values = wp.empty(len(point_grid), dtype=wp.float32, device=device)
544
+ wp.launch(
545
+ test_volume_store_f,
546
+ dim=len(point_grid),
547
+ inputs=[volumes["float_write"][device.alias].id, points, values],
548
+ device=device,
549
+ )
605
550
 
606
- def test_volume_introspection(self):
607
- for volume_names in ("float", "vec3f"):
608
- for device in devices:
609
- volume = volumes[volume_names][device.alias]
610
- tiles_actual = volume.get_tiles().numpy()
611
- tiles_sorted = tiles_actual[np.lexsort(tiles_actual.T[::-1])]
612
- voxel_size = np.array(volume.get_voxel_size())
551
+ values_res = values.numpy()
552
+ np.testing.assert_equal(values_res, values_ref)
553
+
554
+
555
+ def test_volume_allocation_f(test, device):
556
+ bg_value = -123.0
557
+ points_np = np.append(point_grid, [[8096, 8096, 8096]], axis=0)
558
+ values_ref = np.append(np.array([x + 100 * y + 10000 * z for x, y, z in point_grid]), bg_value)
559
+
560
+ volume = wp.Volume.allocate(min=[-11, -11, -11], max=[11, 11, 11], voxel_size=0.1, bg_value=bg_value, device=device)
561
+ points = wp.array(points_np, dtype=wp.vec3, device=device)
562
+ values = wp.empty(len(points_np), dtype=wp.float32, device=device)
563
+ wp.launch(test_volume_store_f, dim=len(points_np), inputs=[volume.id, points, values], device=device)
564
+
565
+ values_res = values.numpy()
566
+ np.testing.assert_equal(values_res, values_ref)
567
+
568
+
569
+ def test_volume_allocation_v(test, device):
570
+ bg_value = (-1, 2.0, -3)
571
+ points_np = np.append(point_grid, [[8096, 8096, 8096]], axis=0)
572
+ values_ref = np.append(point_grid, [bg_value], axis=0)
573
+
574
+ volume = wp.Volume.allocate(min=[-11, -11, -11], max=[11, 11, 11], voxel_size=0.1, bg_value=bg_value, device=device)
575
+ points = wp.array(points_np, dtype=wp.vec3, device=device)
576
+ values = wp.empty(len(points_np), dtype=wp.vec3, device=device)
577
+ wp.launch(test_volume_store_v, dim=len(points_np), inputs=[volume.id, points, values], device=device)
578
+
579
+ values_res = values.numpy()
580
+ np.testing.assert_equal(values_res, values_ref)
581
+
582
+
583
+ def test_volume_allocation_i(test, device):
584
+ bg_value = -123
585
+ points_np = np.append(point_grid, [[8096, 8096, 8096]], axis=0)
586
+ values_ref = np.append(np.array([x + 100 * y + 10000 * z for x, y, z in point_grid], dtype=np.int32), bg_value)
587
+
588
+ volume = wp.Volume.allocate(min=[-11, -11, -11], max=[11, 11, 11], voxel_size=0.1, bg_value=bg_value, device=device)
589
+ points = wp.array(points_np, dtype=wp.vec3, device=device)
590
+ values = wp.empty(len(points_np), dtype=wp.int32, device=device)
591
+ wp.launch(test_volume_store_i, dim=len(points_np), inputs=[volume.id, points, values], device=device)
592
+
593
+ values_res = values.numpy()
594
+ np.testing.assert_equal(values_res, values_ref)
595
+
596
+
597
+ def test_volume_introspection(test, device):
598
+ for volume_names in ("float", "vec3f"):
599
+ with test.subTest(volume_names=volume_names):
600
+ volume = volumes[volume_names][device.alias]
601
+ tiles_actual = volume.get_tiles().numpy()
602
+ tiles_sorted = tiles_actual[np.lexsort(tiles_actual.T[::-1])]
603
+ voxel_size = np.array(volume.get_voxel_size())
604
+
605
+ np.testing.assert_equal(test_volume_tiles, tiles_sorted)
606
+ np.testing.assert_equal([0.25] * 3, voxel_size)
607
+
608
+
609
+ def test_volume_from_numpy(test, device):
610
+ # Volume.allocate_from_tiles() is only available with CUDA
611
+ mins = np.array([-3.0, -3.0, -3.0])
612
+ voxel_size = 0.2
613
+ maxs = np.array([3.0, 3.0, 3.0])
614
+ nums = np.ceil((maxs - mins) / (voxel_size)).astype(dtype=int)
615
+ center = np.array([0.0, 0.0, 0.0])
616
+ rad = 2.5
617
+ sphere_sdf_np = np.zeros(tuple(nums))
618
+ for x in range(nums[0]):
619
+ for y in range(nums[1]):
620
+ for z in range(nums[2]):
621
+ pos = mins + voxel_size * np.array([x, y, z])
622
+ dis = np.linalg.norm(pos - center)
623
+ sphere_sdf_np[x, y, z] = dis - rad
624
+ sphere_vdb = wp.Volume.load_from_numpy(sphere_sdf_np, mins, voxel_size, rad + 3.0 * voxel_size, device=device)
625
+
626
+ test.assertNotEqual(sphere_vdb.id, 0)
627
+
628
+ sphere_vdb_array = sphere_vdb.array()
629
+ test.assertEqual(sphere_vdb_array.dtype, wp.uint8)
630
+ test.assertFalse(sphere_vdb_array.owner)
631
+
632
+
633
+ class TestVolume(unittest.TestCase):
634
+ pass
635
+
636
+
637
+ add_function_test(
638
+ TestVolume, "test_volume_sample_linear_f_gradient", test_volume_sample_linear_f_gradient, devices=devices
639
+ )
640
+ add_function_test(
641
+ TestVolume, "test_volume_sample_grad_linear_f_gradient", test_volume_sample_grad_linear_f_gradient, devices=devices
642
+ )
643
+ add_function_test(
644
+ TestVolume, "test_volume_sample_linear_v_gradient", test_volume_sample_linear_v_gradient, devices=devices
645
+ )
646
+ add_function_test(TestVolume, "test_volume_transform_gradient", test_volume_transform_gradient, devices=devices)
647
+ add_function_test(TestVolume, "test_volume_store", test_volume_store, devices=devices)
648
+ add_function_test(
649
+ TestVolume, "test_volume_allocation_f", test_volume_allocation_f, devices=get_unique_cuda_test_devices()
650
+ )
651
+ add_function_test(
652
+ TestVolume, "test_volume_allocation_v", test_volume_allocation_v, devices=get_unique_cuda_test_devices()
653
+ )
654
+ add_function_test(
655
+ TestVolume, "test_volume_allocation_i", test_volume_allocation_i, devices=get_unique_cuda_test_devices()
656
+ )
657
+ add_function_test(TestVolume, "test_volume_introspection", test_volume_introspection, devices=devices)
658
+ add_function_test(TestVolume, "test_volume_from_numpy", test_volume_from_numpy, devices=get_unique_cuda_test_devices())
659
+
660
+ points = {}
661
+ points_jittered = {}
662
+ for device in devices:
663
+ points_jittered_np = point_grid + rng.uniform(-0.5, 0.5, size=point_grid.shape)
664
+ points[device.alias] = wp.array(point_grid, dtype=wp.vec3, device=device)
665
+ points_jittered[device.alias] = wp.array(points_jittered_np, dtype=wp.vec3, device=device)
666
+
667
+ add_kernel_test(
668
+ TestVolume,
669
+ test_volume_lookup_f,
670
+ dim=len(point_grid),
671
+ inputs=[volumes["float"][device.alias].id, points[device.alias]],
672
+ devices=[device],
673
+ )
674
+ add_kernel_test(
675
+ TestVolume,
676
+ test_volume_sample_closest_f,
677
+ dim=len(point_grid),
678
+ inputs=[volumes["float"][device.alias].id, points_jittered[device.alias]],
679
+ devices=[device.alias],
680
+ )
681
+ add_kernel_test(
682
+ TestVolume,
683
+ test_volume_sample_linear_f,
684
+ dim=len(point_grid),
685
+ inputs=[volumes["float"][device.alias].id, points_jittered[device.alias]],
686
+ devices=[device.alias],
687
+ )
688
+ add_kernel_test(
689
+ TestVolume,
690
+ test_volume_sample_grad_linear_f,
691
+ dim=len(point_grid),
692
+ inputs=[volumes["float"][device.alias].id, points_jittered[device.alias]],
693
+ devices=[device.alias],
694
+ )
613
695
 
614
- np.testing.assert_equal(test_volume_tiles, tiles_sorted)
615
- np.testing.assert_equal([0.25] * 3, voxel_size)
696
+ add_kernel_test(
697
+ TestVolume,
698
+ test_volume_lookup_v,
699
+ dim=len(point_grid),
700
+ inputs=[volumes["vec3f"][device.alias].id, points[device.alias]],
701
+ devices=[device.alias],
702
+ )
703
+ add_kernel_test(
704
+ TestVolume,
705
+ test_volume_sample_closest_v,
706
+ dim=len(point_grid),
707
+ inputs=[volumes["vec3f"][device.alias].id, points_jittered[device.alias]],
708
+ devices=[device.alias],
709
+ )
710
+ add_kernel_test(
711
+ TestVolume,
712
+ test_volume_sample_linear_v,
713
+ dim=len(point_grid),
714
+ inputs=[volumes["vec3f"][device.alias].id, points_jittered[device.alias]],
715
+ devices=[device.alias],
716
+ )
616
717
 
617
- for device in devices:
618
- points_jittered_np = point_grid + rng.uniform(-0.5, 0.5, size=point_grid.shape)
619
- points[device.alias] = wp.array(point_grid, dtype=wp.vec3, device=device)
620
- points_jittered[device.alias] = wp.array(points_jittered_np, dtype=wp.vec3, device=device)
621
-
622
- add_kernel_test(
623
- TestVolumes,
624
- test_volume_lookup_f,
625
- dim=len(point_grid),
626
- inputs=[volumes["float"][device.alias].id, points[device.alias]],
627
- devices=[device],
628
- )
629
- add_kernel_test(
630
- TestVolumes,
631
- test_volume_sample_closest_f,
632
- dim=len(point_grid),
633
- inputs=[volumes["float"][device.alias].id, points_jittered[device.alias]],
634
- devices=[device.alias],
635
- )
636
- add_kernel_test(
637
- TestVolumes,
638
- test_volume_sample_linear_f,
639
- dim=len(point_grid),
640
- inputs=[volumes["float"][device.alias].id, points_jittered[device.alias]],
641
- devices=[device.alias],
642
- )
643
- add_kernel_test(
644
- TestVolumes,
645
- test_volume_sample_grad_linear_f,
646
- dim=len(point_grid),
647
- inputs=[volumes["float"][device.alias].id, points_jittered[device.alias]],
648
- devices=[device.alias],
649
- )
650
-
651
- add_kernel_test(
652
- TestVolumes,
653
- test_volume_lookup_v,
654
- dim=len(point_grid),
655
- inputs=[volumes["vec3f"][device.alias].id, points[device.alias]],
656
- devices=[device.alias],
657
- )
658
- add_kernel_test(
659
- TestVolumes,
660
- test_volume_sample_closest_v,
661
- dim=len(point_grid),
662
- inputs=[volumes["vec3f"][device.alias].id, points_jittered[device.alias]],
663
- devices=[device.alias],
664
- )
665
- add_kernel_test(
666
- TestVolumes,
667
- test_volume_sample_linear_v,
668
- dim=len(point_grid),
669
- inputs=[volumes["vec3f"][device.alias].id, points_jittered[device.alias]],
670
- devices=[device.alias],
671
- )
672
-
673
- add_kernel_test(
674
- TestVolumes,
675
- test_volume_lookup_i,
676
- dim=len(point_grid),
677
- inputs=[volumes["int32"][device.alias].id, points[device.alias]],
678
- devices=[device.alias],
679
- )
680
- add_kernel_test(
681
- TestVolumes,
682
- test_volume_sample_i,
683
- dim=len(point_grid),
684
- inputs=[volumes["int32"][device.alias].id, points_jittered[device.alias]],
685
- devices=[device.alias],
686
- )
687
-
688
- return TestVolumes
718
+ add_kernel_test(
719
+ TestVolume,
720
+ test_volume_lookup_i,
721
+ dim=len(point_grid),
722
+ inputs=[volumes["int32"][device.alias].id, points[device.alias]],
723
+ devices=[device.alias],
724
+ )
725
+ add_kernel_test(
726
+ TestVolume,
727
+ test_volume_sample_i,
728
+ dim=len(point_grid),
729
+ inputs=[volumes["int32"][device.alias].id, points_jittered[device.alias]],
730
+ devices=[device.alias],
731
+ )
689
732
 
690
733
 
691
734
  if __name__ == "__main__":
692
- wp.force_load()
693
- c = register(unittest.TestCase)
735
+ wp.build.clear_kernel_cache()
694
736
  unittest.main(verbosity=2)