warp-lang 1.0.0b2__py3-none-win_amd64.whl → 1.0.0b6__py3-none-win_amd64.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.

Files changed (271) 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.dll +0 -0
  57. warp/bin/warp.dll +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/bin/warp-clang.so +0 -0
  257. warp/bin/warp.so +0 -0
  258. warp/fem/field/discrete_field.py +0 -80
  259. warp/fem/space/nodal_function_space.py +0 -233
  260. warp/tests/test_all.py +0 -223
  261. warp/tests/test_array_scan.py +0 -60
  262. warp/tests/test_base.py +0 -208
  263. warp/tests/test_unresolved_func.py +0 -7
  264. warp/tests/test_unresolved_symbol.py +0 -7
  265. warp_lang-1.0.0b2.dist-info/METADATA +0 -26
  266. warp_lang-1.0.0b2.dist-info/RECORD +0 -380
  267. /warp/tests/{test_compile_consts_dummy.py → aux_test_compile_consts_dummy.py} +0 -0
  268. /warp/tests/{test_reference_reference.py → aux_test_reference_reference.py} +0 -0
  269. /warp/tests/{test_square.py → aux_test_square.py} +0 -0
  270. {warp_lang-1.0.0b2.dist-info → warp_lang-1.0.0b6.dist-info}/LICENSE.md +0 -0
  271. {warp_lang-1.0.0b2.dist-info → warp_lang-1.0.0b6.dist-info}/top_level.txt +0 -0
@@ -5,9 +5,12 @@
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 unittest
9
+
8
10
  import numpy as np
11
+
9
12
  import warp as wp
10
- from warp.tests.test_base import *
13
+ from warp.tests.unittest_utils import *
11
14
 
12
15
  wp.init()
13
16
 
@@ -34,22 +37,21 @@ np_float_types = [np.float16, np.float32, np.float64]
34
37
  np_scalar_types = np_int_types + np_float_types
35
38
 
36
39
 
37
- def randvals(shape, dtype):
40
+ def randvals(rng, shape, dtype):
38
41
  if dtype in np_float_types:
39
- return np.random.randn(*shape).astype(dtype)
42
+ return rng.standard_normal(size=shape).astype(dtype)
40
43
  elif dtype in [np.int8, np.uint8, np.byte, np.ubyte]:
41
- return np.random.randint(1, 3, size=shape, dtype=dtype)
42
- return np.random.randint(1, 5, size=shape, dtype=dtype)
44
+ return rng.integers(1, high=3, size=shape, dtype=dtype)
45
+ return rng.integers(1, high=5, size=shape, dtype=dtype)
43
46
 
44
47
 
45
48
  kernel_cache = dict()
46
49
 
47
50
 
48
51
  def getkernel(func, suffix=""):
49
- module = wp.get_module(func.__module__)
50
52
  key = func.__name__ + "_" + suffix
51
53
  if key not in kernel_cache:
52
- kernel_cache[key] = wp.Kernel(func=func, key=key, module=module)
54
+ kernel_cache[key] = wp.Kernel(func=func, key=key)
53
55
  return kernel_cache[key]
54
56
 
55
57
 
@@ -77,7 +79,7 @@ def get_select_kernel2(dtype):
77
79
 
78
80
 
79
81
  def test_arrays(test, device, dtype):
80
- np.random.seed(123)
82
+ rng = np.random.default_rng(123)
81
83
 
82
84
  tol = {
83
85
  np.float16: 1.0e-3,
@@ -86,14 +88,14 @@ def test_arrays(test, device, dtype):
86
88
  }.get(dtype, 0)
87
89
 
88
90
  wptype = wp.types.np_dtype_to_warp_type[np.dtype(dtype)]
89
- arr_np = randvals((10, 5), dtype)
91
+ arr_np = randvals(rng, (10, 5), dtype)
90
92
  arr = wp.array(arr_np, dtype=wptype, requires_grad=True, device=device)
91
93
 
92
94
  assert_np_equal(arr.numpy(), arr_np, tol=tol)
93
95
 
94
96
 
95
97
  def test_unary_ops(test, device, dtype, register_kernels=False):
96
- np.random.seed(123)
98
+ rng = np.random.default_rng(123)
97
99
 
98
100
  tol = {
99
101
  np.float16: 5.0e-3,
@@ -128,10 +130,12 @@ def test_unary_ops(test, device, dtype, register_kernels=False):
128
130
  return
129
131
 
130
132
  if dtype in np_float_types:
131
- inputs = wp.array(np.random.randn(5, 10).astype(dtype), dtype=wptype, requires_grad=True, device=device)
133
+ inputs = wp.array(
134
+ rng.standard_normal(size=(5, 10)).astype(dtype), dtype=wptype, requires_grad=True, device=device
135
+ )
132
136
  else:
133
137
  inputs = wp.array(
134
- np.random.randint(-2, 3, size=(5, 10), dtype=dtype), dtype=wptype, requires_grad=True, device=device
138
+ rng.integers(-2, high=3, size=(5, 10), dtype=dtype), dtype=wptype, requires_grad=True, device=device
135
139
  )
136
140
  outputs = wp.zeros_like(inputs)
137
141
 
@@ -207,7 +211,7 @@ def test_unary_ops(test, device, dtype, register_kernels=False):
207
211
 
208
212
 
209
213
  def test_nonzero(test, device, dtype, register_kernels=False):
210
- np.random.seed(123)
214
+ rng = np.random.default_rng(123)
211
215
 
212
216
  tol = {
213
217
  np.float16: 5.0e-3,
@@ -231,7 +235,7 @@ def test_nonzero(test, device, dtype, register_kernels=False):
231
235
  if register_kernels:
232
236
  return
233
237
 
234
- inputs = wp.array(np.random.randint(-2, 3, size=10).astype(dtype), dtype=wptype, requires_grad=True, device=device)
238
+ inputs = wp.array(rng.integers(-2, high=3, size=10).astype(dtype), dtype=wptype, requires_grad=True, device=device)
235
239
  outputs = wp.zeros_like(inputs)
236
240
 
237
241
  wp.launch(kernel, dim=1, inputs=[inputs], outputs=[outputs], device=device)
@@ -253,10 +257,10 @@ def test_nonzero(test, device, dtype, register_kernels=False):
253
257
 
254
258
 
255
259
  def test_binary_ops(test, device, dtype, register_kernels=False):
256
- np.random.seed(123)
260
+ rng = np.random.default_rng(123)
257
261
 
258
262
  tol = {
259
- np.float16: 1.0e-2,
263
+ np.float16: 5.0e-2,
260
264
  np.float32: 1.0e-6,
261
265
  np.float64: 1.0e-8,
262
266
  }.get(dtype, 0)
@@ -302,11 +306,11 @@ def test_binary_ops(test, device, dtype, register_kernels=False):
302
306
  if register_kernels:
303
307
  return
304
308
 
305
- vals1 = randvals([8, 10], dtype)
309
+ vals1 = randvals(rng, [8, 10], dtype)
306
310
  if dtype in [np_unsigned_int_types]:
307
- vals2 = vals1 + randvals([8, 10], dtype)
311
+ vals2 = vals1 + randvals(rng, [8, 10], dtype)
308
312
  else:
309
- vals2 = np.abs(randvals([8, 10], dtype))
313
+ vals2 = np.abs(randvals(rng, [8, 10], dtype))
310
314
 
311
315
  in1 = wp.array(vals1, dtype=wptype, requires_grad=True, device=device)
312
316
  in2 = wp.array(vals2, dtype=wptype, requires_grad=True, device=device)
@@ -458,7 +462,7 @@ def test_binary_ops(test, device, dtype, register_kernels=False):
458
462
 
459
463
 
460
464
  def test_special_funcs(test, device, dtype, register_kernels=False):
461
- np.random.seed(123)
465
+ rng = np.random.default_rng(123)
462
466
 
463
467
  tol = {
464
468
  np.float16: 1.0e-2,
@@ -488,6 +492,7 @@ def test_special_funcs(test, device, dtype, register_kernels=False):
488
492
  outputs[11, i] = wptype(2) * wp.tanh(inputs[11, i])
489
493
  outputs[12, i] = wptype(2) * wp.acos(inputs[12, i])
490
494
  outputs[13, i] = wptype(2) * wp.asin(inputs[13, i])
495
+ outputs[14, i] = wptype(2) * wp.cbrt(inputs[14, i])
491
496
 
492
497
  kernel = getkernel(check_special_funcs, suffix=dtype.__name__)
493
498
  output_select_kernel = get_select_kernel2(wptype)
@@ -495,8 +500,8 @@ def test_special_funcs(test, device, dtype, register_kernels=False):
495
500
  if register_kernels:
496
501
  return
497
502
 
498
- invals = np.random.randn(14, 10).astype(dtype)
499
- invals[[0, 1, 2, 7]] = 0.1 + np.abs(invals[[0, 1, 2, 7]])
503
+ invals = rng.normal(size=(15, 10)).astype(dtype)
504
+ invals[[0, 1, 2, 7, 14]] = 0.1 + np.abs(invals[[0, 1, 2, 7, 14]])
500
505
  invals[12] = np.clip(invals[12], -0.9, 0.9)
501
506
  invals[13] = np.clip(invals[13], -0.9, 0.9)
502
507
  inputs = wp.array(invals, dtype=wptype, requires_grad=True, device=device)
@@ -518,6 +523,7 @@ def test_special_funcs(test, device, dtype, register_kernels=False):
518
523
  assert_np_equal(outputs.numpy()[11], 2 * np.tanh(inputs.numpy()[11]), tol=tol)
519
524
  assert_np_equal(outputs.numpy()[12], 2 * np.arccos(inputs.numpy()[12]), tol=tol)
520
525
  assert_np_equal(outputs.numpy()[13], 2 * np.arcsin(inputs.numpy()[13]), tol=tol)
526
+ assert_np_equal(outputs.numpy()[14], 2 * np.cbrt(inputs.numpy()[14]), tol=tol)
521
527
 
522
528
  out = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
523
529
  if dtype in np_float_types:
@@ -694,9 +700,22 @@ def test_special_funcs(test, device, dtype, register_kernels=False):
694
700
  assert_np_equal(tape.gradients[inputs].numpy(), expected, tol=6 * tol)
695
701
  tape.zero()
696
702
 
703
+ # cbrt:
704
+ tape = wp.Tape()
705
+ with tape:
706
+ wp.launch(kernel, dim=1, inputs=[inputs], outputs=[outputs], device=device)
707
+ wp.launch(output_select_kernel, dim=1, inputs=[outputs, 14, i], outputs=[out], device=device)
708
+
709
+ tape.backward(loss=out)
710
+ expected = np.zeros_like(inputs.numpy())
711
+ cbrt = np.cbrt(inputs.numpy()[14, i], dtype=np.dtype(dtype))
712
+ expected[14, i] = (2.0 / 3.0) * (1.0 / (cbrt * cbrt))
713
+ assert_np_equal(tape.gradients[inputs].numpy(), expected, tol=tol)
714
+ tape.zero()
715
+
697
716
 
698
717
  def test_special_funcs_2arg(test, device, dtype, register_kernels=False):
699
- np.random.seed(123)
718
+ rng = np.random.default_rng(123)
700
719
 
701
720
  tol = {
702
721
  np.float16: 1.0e-2,
@@ -722,8 +741,8 @@ def test_special_funcs_2arg(test, device, dtype, register_kernels=False):
722
741
  if register_kernels:
723
742
  return
724
743
 
725
- in1 = wp.array(np.abs(randvals([2, 10], dtype)), dtype=wptype, requires_grad=True, device=device)
726
- in2 = wp.array(randvals([2, 10], dtype), dtype=wptype, requires_grad=True, device=device)
744
+ in1 = wp.array(np.abs(randvals(rng, [2, 10], dtype)), dtype=wptype, requires_grad=True, device=device)
745
+ in2 = wp.array(randvals(rng, [2, 10], dtype), dtype=wptype, requires_grad=True, device=device)
727
746
  outputs = wp.zeros_like(in1)
728
747
 
729
748
  wp.launch(kernel, dim=1, inputs=[in1, in2], outputs=[outputs], device=device)
@@ -763,7 +782,7 @@ def test_special_funcs_2arg(test, device, dtype, register_kernels=False):
763
782
 
764
783
 
765
784
  def test_float_to_int(test, device, dtype, register_kernels=False):
766
- np.random.seed(123)
785
+ rng = np.random.default_rng(123)
767
786
 
768
787
  tol = {
769
788
  np.float16: 5.0e-3,
@@ -783,6 +802,7 @@ def test_float_to_int(test, device, dtype, register_kernels=False):
783
802
  outputs[2, i] = wp.trunc(inputs[2, i])
784
803
  outputs[3, i] = wp.floor(inputs[3, i])
785
804
  outputs[4, i] = wp.ceil(inputs[4, i])
805
+ outputs[5, i] = wp.frac(inputs[5, i])
786
806
 
787
807
  kernel = getkernel(check_float_to_int, suffix=dtype.__name__)
788
808
  output_select_kernel = get_select_kernel2(wptype)
@@ -790,7 +810,7 @@ def test_float_to_int(test, device, dtype, register_kernels=False):
790
810
  if register_kernels:
791
811
  return
792
812
 
793
- inputs = wp.array(np.random.randn(5, 10).astype(dtype), dtype=wptype, requires_grad=True, device=device)
813
+ inputs = wp.array(rng.standard_normal(size=(6, 10)).astype(dtype), dtype=wptype, requires_grad=True, device=device)
794
814
  outputs = wp.zeros_like(inputs)
795
815
 
796
816
  wp.launch(kernel, dim=1, inputs=[inputs], outputs=[outputs], device=device)
@@ -800,6 +820,7 @@ def test_float_to_int(test, device, dtype, register_kernels=False):
800
820
  assert_np_equal(outputs.numpy()[2], np.trunc(inputs.numpy()[2]))
801
821
  assert_np_equal(outputs.numpy()[3], np.floor(inputs.numpy()[3]))
802
822
  assert_np_equal(outputs.numpy()[4], np.ceil(inputs.numpy()[4]))
823
+ assert_np_equal(outputs.numpy()[5], np.modf(inputs.numpy()[5])[0])
803
824
 
804
825
  # all the gradients should be zero as these functions are piecewise constant:
805
826
 
@@ -817,7 +838,7 @@ def test_float_to_int(test, device, dtype, register_kernels=False):
817
838
 
818
839
 
819
840
  def test_interp(test, device, dtype, register_kernels=False):
820
- np.random.seed(123)
841
+ rng = np.random.default_rng(123)
821
842
 
822
843
  tol = {
823
844
  np.float16: 1.0e-2,
@@ -844,11 +865,11 @@ def test_interp(test, device, dtype, register_kernels=False):
844
865
  if register_kernels:
845
866
  return
846
867
 
847
- e0 = randvals([2, 10], dtype)
848
- e1 = e0 + randvals([2, 10], dtype) + 0.1
868
+ e0 = randvals(rng, [2, 10], dtype)
869
+ e1 = e0 + randvals(rng, [2, 10], dtype) + 0.1
849
870
  in1 = wp.array(e0, dtype=wptype, requires_grad=True, device=device)
850
871
  in2 = wp.array(e1, dtype=wptype, requires_grad=True, device=device)
851
- in3 = wp.array(randvals([2, 10], dtype), dtype=wptype, requires_grad=True, device=device)
872
+ in3 = wp.array(randvals(rng, [2, 10], dtype), dtype=wptype, requires_grad=True, device=device)
852
873
 
853
874
  outputs = wp.zeros_like(in1)
854
875
 
@@ -948,7 +969,7 @@ def test_interp(test, device, dtype, register_kernels=False):
948
969
 
949
970
 
950
971
  def test_clamp(test, device, dtype, register_kernels=False):
951
- np.random.seed(123)
972
+ rng = np.random.default_rng(123)
952
973
 
953
974
  tol = {
954
975
  np.float16: 5.0e-3,
@@ -974,9 +995,9 @@ def test_clamp(test, device, dtype, register_kernels=False):
974
995
  if register_kernels:
975
996
  return
976
997
 
977
- in1 = wp.array(randvals([100], dtype), dtype=wptype, requires_grad=True, device=device)
978
- starts = randvals([100], dtype)
979
- diffs = np.abs(randvals([100], dtype))
998
+ in1 = wp.array(randvals(rng, [100], dtype), dtype=wptype, requires_grad=True, device=device)
999
+ starts = randvals(rng, [100], dtype)
1000
+ diffs = np.abs(randvals(rng, [100], dtype))
980
1001
  in2 = wp.array(starts, dtype=wptype, requires_grad=True, device=device)
981
1002
  in3 = wp.array(starts + diffs, dtype=wptype, requires_grad=True, device=device)
982
1003
  outputs = wp.zeros_like(in1)
@@ -1020,51 +1041,50 @@ def test_clamp(test, device, dtype, register_kernels=False):
1020
1041
  tape.zero()
1021
1042
 
1022
1043
 
1023
- def register(parent):
1024
- devices = get_test_devices()
1044
+ devices = get_test_devices()
1025
1045
 
1026
- class TestArithmetic(parent):
1027
- pass
1028
1046
 
1029
- # these unary ops only make sense for signed values:
1030
- for dtype in np_signed_int_types + np_float_types:
1031
- add_function_test_register_kernel(
1032
- TestArithmetic, f"test_unary_ops_{dtype.__name__}", test_unary_ops, devices=devices, dtype=dtype
1033
- )
1047
+ class TestArithmetic(unittest.TestCase):
1048
+ pass
1034
1049
 
1035
- for dtype in np_float_types:
1036
- add_function_test_register_kernel(
1037
- TestArithmetic, f"test_special_funcs_{dtype.__name__}", test_special_funcs, devices=devices, dtype=dtype
1038
- )
1039
- add_function_test_register_kernel(
1040
- TestArithmetic,
1041
- f"test_special_funcs_2arg_{dtype.__name__}",
1042
- test_special_funcs_2arg,
1043
- devices=devices,
1044
- dtype=dtype,
1045
- )
1046
- add_function_test_register_kernel(
1047
- TestArithmetic, f"test_interp_{dtype.__name__}", test_interp, devices=devices, dtype=dtype
1048
- )
1049
- add_function_test_register_kernel(
1050
- TestArithmetic, f"test_float_to_int_{dtype.__name__}", test_float_to_int, devices=devices, dtype=dtype
1051
- )
1052
1050
 
1053
- for dtype in np_scalar_types:
1054
- add_function_test_register_kernel(
1055
- TestArithmetic, f"test_clamp_{dtype.__name__}", test_clamp, devices=devices, dtype=dtype
1056
- )
1057
- add_function_test_register_kernel(
1058
- TestArithmetic, f"test_nonzero_{dtype.__name__}", test_nonzero, devices=devices, dtype=dtype
1059
- )
1060
- add_function_test(TestArithmetic, f"test_arrays_{dtype.__name__}", test_arrays, devices=devices, dtype=dtype)
1061
- add_function_test_register_kernel(
1062
- TestArithmetic, f"test_binary_ops_{dtype.__name__}", test_binary_ops, devices=devices, dtype=dtype
1063
- )
1051
+ # these unary ops only make sense for signed values:
1052
+ for dtype in np_signed_int_types + np_float_types:
1053
+ add_function_test_register_kernel(
1054
+ TestArithmetic, f"test_unary_ops_{dtype.__name__}", test_unary_ops, devices=devices, dtype=dtype
1055
+ )
1064
1056
 
1065
- return TestArithmetic
1057
+ for dtype in np_float_types:
1058
+ add_function_test_register_kernel(
1059
+ TestArithmetic, f"test_special_funcs_{dtype.__name__}", test_special_funcs, devices=devices, dtype=dtype
1060
+ )
1061
+ add_function_test_register_kernel(
1062
+ TestArithmetic,
1063
+ f"test_special_funcs_2arg_{dtype.__name__}",
1064
+ test_special_funcs_2arg,
1065
+ devices=devices,
1066
+ dtype=dtype,
1067
+ )
1068
+ add_function_test_register_kernel(
1069
+ TestArithmetic, f"test_interp_{dtype.__name__}", test_interp, devices=devices, dtype=dtype
1070
+ )
1071
+ add_function_test_register_kernel(
1072
+ TestArithmetic, f"test_float_to_int_{dtype.__name__}", test_float_to_int, devices=devices, dtype=dtype
1073
+ )
1074
+
1075
+ for dtype in np_scalar_types:
1076
+ add_function_test_register_kernel(
1077
+ TestArithmetic, f"test_clamp_{dtype.__name__}", test_clamp, devices=devices, dtype=dtype
1078
+ )
1079
+ add_function_test_register_kernel(
1080
+ TestArithmetic, f"test_nonzero_{dtype.__name__}", test_nonzero, devices=devices, dtype=dtype
1081
+ )
1082
+ add_function_test(TestArithmetic, f"test_arrays_{dtype.__name__}", test_arrays, devices=devices, dtype=dtype)
1083
+ add_function_test_register_kernel(
1084
+ TestArithmetic, f"test_binary_ops_{dtype.__name__}", test_binary_ops, devices=devices, dtype=dtype
1085
+ )
1066
1086
 
1067
1087
 
1068
1088
  if __name__ == "__main__":
1069
- c = register(unittest.TestCase)
1089
+ wp.build.clear_kernel_cache()
1070
1090
  unittest.main(verbosity=2, failfast=False)
warp/tests/test_array.py CHANGED
@@ -5,14 +5,12 @@
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 math
9
8
  import unittest
10
9
 
11
- # include parent path
12
10
  import numpy as np
13
11
 
14
12
  import warp as wp
15
- from warp.tests.test_base import *
13
+ from warp.tests.unittest_utils import *
16
14
 
17
15
  wp.init()
18
16
 
@@ -1454,16 +1452,17 @@ def test_full_struct(test, device):
1454
1452
 
1455
1453
 
1456
1454
  def test_round_trip(test, device):
1455
+ rng = np.random.default_rng(123)
1457
1456
  dim_x = 4
1458
1457
 
1459
1458
  for nptype, wptype in wp.types.np_dtype_to_warp_type.items():
1460
- a_np = np.random.randn(dim_x).astype(nptype)
1459
+ a_np = rng.standard_normal(size=dim_x).astype(nptype)
1461
1460
  a = wp.array(a_np, device=device)
1462
1461
  test.assertEqual(a.dtype, wptype)
1463
1462
 
1464
1463
  assert_np_equal(a.numpy(), a_np)
1465
1464
 
1466
- v_np = np.random.randn(dim_x, 3).astype(nptype)
1465
+ v_np = rng.standard_normal(size=(dim_x, 3)).astype(nptype)
1467
1466
  v = wp.array(v_np, dtype=wp.types.vector(3, wptype), device=device)
1468
1467
 
1469
1468
  assert_np_equal(v.numpy(), v_np)
@@ -1750,46 +1749,6 @@ def test_to_list_struct(test, device):
1750
1749
  test.assertEqual(l[i].a3.ndim, s.a3.ndim)
1751
1750
 
1752
1751
 
1753
- def test_large_arrays_slow(test, device):
1754
- # The goal of this test is to use arrays just large enough to know
1755
- # if there's a flaw in handling arrays with more than 2**31-1 elements
1756
- # Unfortunately, it takes a long time to run so it won't be run automatically
1757
- # without changes to support how frequently a test may be run
1758
- total_elements = 2**31 + 8
1759
-
1760
- # 1-D to 4-D arrays: test zero_, fill_, then zero_ for scalar data types:
1761
- for total_dims in range(1, 5):
1762
- dim_x = math.ceil(total_elements ** (1 / total_dims))
1763
- shape_tuple = tuple([dim_x] * total_dims)
1764
-
1765
- for nptype, wptype in wp.types.np_dtype_to_warp_type.items():
1766
- a1 = wp.zeros(shape_tuple, dtype=wptype, device=device)
1767
- assert_np_equal(a1.numpy(), np.zeros_like(a1.numpy()))
1768
-
1769
- a1.fill_(127)
1770
- assert_np_equal(a1.numpy(), 127 * np.ones_like(a1.numpy()))
1771
-
1772
- a1.zero_()
1773
- assert_np_equal(a1.numpy(), np.zeros_like(a1.numpy()))
1774
-
1775
-
1776
- def test_large_arrays_fast(test, device):
1777
- # A truncated version of test_large_arrays_slow meant to catch basic errors
1778
- total_elements = 2**31 + 8
1779
-
1780
- nptype = np.dtype(np.int8)
1781
- wptype = wp.types.np_dtype_to_warp_type[nptype]
1782
-
1783
- a1 = wp.zeros((total_elements,), dtype=wptype, device=device)
1784
- assert_np_equal(a1.numpy(), np.zeros_like(a1.numpy()))
1785
-
1786
- a1.fill_(127)
1787
- assert_np_equal(a1.numpy(), 127 * np.ones_like(a1.numpy()))
1788
-
1789
- a1.zero_()
1790
- assert_np_equal(a1.numpy(), np.zeros_like(a1.numpy()))
1791
-
1792
-
1793
1752
  @wp.kernel
1794
1753
  def kernel_array_to_bool(array_null: wp.array(dtype=float), array_valid: wp.array(dtype=float)):
1795
1754
  if not array_null:
@@ -2087,14 +2046,38 @@ def test_array_from_numpy(test, device):
2087
2046
  result = wp.from_numpy(arr, dtype=wp.float32, shape=(32,))
2088
2047
  expected = wp.array(
2089
2048
  (
2090
- 1.0, 2.0, 3.0, 4.0,
2091
- 2.0, 3.0, 4.0, 5.0,
2092
- 3.0, 4.0, 5.0, 6.0,
2093
- 4.0, 5.0, 6.0, 7.0,
2094
- 2.0, 3.0, 4.0, 5.0,
2095
- 3.0, 4.0, 5.0, 6.0,
2096
- 4.0, 5.0, 6.0, 7.0,
2097
- 5.0, 6.0, 7.0, 8.0,
2049
+ 1.0,
2050
+ 2.0,
2051
+ 3.0,
2052
+ 4.0,
2053
+ 2.0,
2054
+ 3.0,
2055
+ 4.0,
2056
+ 5.0,
2057
+ 3.0,
2058
+ 4.0,
2059
+ 5.0,
2060
+ 6.0,
2061
+ 4.0,
2062
+ 5.0,
2063
+ 6.0,
2064
+ 7.0,
2065
+ 2.0,
2066
+ 3.0,
2067
+ 4.0,
2068
+ 5.0,
2069
+ 3.0,
2070
+ 4.0,
2071
+ 5.0,
2072
+ 6.0,
2073
+ 4.0,
2074
+ 5.0,
2075
+ 6.0,
2076
+ 7.0,
2077
+ 5.0,
2078
+ 6.0,
2079
+ 7.0,
2080
+ 8.0,
2098
2081
  ),
2099
2082
  dtype=wp.float32,
2100
2083
  shape=(32,),
@@ -2102,55 +2085,53 @@ def test_array_from_numpy(test, device):
2102
2085
  assert_np_equal(result.numpy(), expected.numpy())
2103
2086
 
2104
2087
 
2105
- def register(parent):
2106
- devices = get_test_devices()
2107
-
2108
- class TestArray(parent):
2109
- pass
2110
-
2111
- add_function_test(TestArray, "test_shape", test_shape, devices=devices)
2112
- add_function_test(TestArray, "test_flatten", test_flatten, devices=devices)
2113
- add_function_test(TestArray, "test_reshape", test_reshape, devices=devices)
2114
- add_function_test(TestArray, "test_slicing", test_slicing, devices=devices)
2115
- add_function_test(TestArray, "test_transpose", test_transpose, devices=devices)
2116
- add_function_test(TestArray, "test_view", test_view, devices=devices)
2117
-
2118
- add_function_test(TestArray, "test_1d_array", test_1d, devices=devices)
2119
- add_function_test(TestArray, "test_2d_array", test_2d, devices=devices)
2120
- add_function_test(TestArray, "test_3d_array", test_3d, devices=devices)
2121
- add_function_test(TestArray, "test_4d_array", test_4d, devices=devices)
2122
- add_function_test(TestArray, "test_4d_array_transposed", test_4d_transposed, devices=devices)
2123
-
2124
- add_function_test(TestArray, "test_fill_scalar", test_fill_scalar, devices=devices)
2125
- add_function_test(TestArray, "test_fill_vector", test_fill_vector, devices=devices)
2126
- add_function_test(TestArray, "test_fill_matrix", test_fill_matrix, devices=devices)
2127
- add_function_test(TestArray, "test_fill_struct", test_fill_struct, devices=devices)
2128
- add_function_test(TestArray, "test_fill_slices", test_fill_slices, devices=devices)
2129
- add_function_test(TestArray, "test_full_scalar", test_full_scalar, devices=devices)
2130
- add_function_test(TestArray, "test_full_vector", test_full_vector, devices=devices)
2131
- add_function_test(TestArray, "test_full_matrix", test_full_matrix, devices=devices)
2132
- add_function_test(TestArray, "test_full_struct", test_full_struct, devices=devices)
2133
- add_function_test(TestArray, "test_empty_array", test_empty_array, devices=devices)
2134
- add_function_test(TestArray, "test_empty_from_numpy", test_empty_from_numpy, devices=devices)
2135
- add_function_test(TestArray, "test_empty_from_list", test_empty_from_list, devices=devices)
2136
- add_function_test(TestArray, "test_to_list_scalar", test_to_list_scalar, devices=devices)
2137
- add_function_test(TestArray, "test_to_list_vector", test_to_list_vector, devices=devices)
2138
- add_function_test(TestArray, "test_to_list_matrix", test_to_list_matrix, devices=devices)
2139
- add_function_test(TestArray, "test_to_list_struct", test_to_list_struct, devices=devices)
2140
-
2141
- add_function_test(TestArray, "test_lower_bound", test_lower_bound, devices=devices)
2142
- add_function_test(TestArray, "test_round_trip", test_round_trip, devices=devices)
2143
- add_function_test(TestArray, "test_large_arrays_fast", test_large_arrays_fast, devices=devices)
2144
- add_function_test(TestArray, "test_array_to_bool", test_array_to_bool, devices=devices)
2145
- add_function_test(TestArray, "test_array_of_structs", test_array_of_structs, devices=devices)
2146
- add_function_test(TestArray, "test_array_of_structs_grad", test_array_of_structs_grad, devices=devices)
2147
- add_function_test(TestArray, "test_array_of_structs_from_numpy", test_array_of_structs_from_numpy, devices=devices)
2148
- add_function_test(TestArray, "test_array_of_structs_roundtrip", test_array_of_structs_roundtrip, devices=devices)
2149
- add_function_test(TestArray, "test_array_from_numpy", test_array_from_numpy, devices=devices)
2150
-
2151
- return TestArray
2088
+ devices = get_test_devices()
2089
+
2090
+
2091
+ class TestArray(unittest.TestCase):
2092
+ pass
2093
+
2094
+
2095
+ add_function_test(TestArray, "test_shape", test_shape, devices=devices)
2096
+ add_function_test(TestArray, "test_flatten", test_flatten, devices=devices)
2097
+ add_function_test(TestArray, "test_reshape", test_reshape, devices=devices)
2098
+ add_function_test(TestArray, "test_slicing", test_slicing, devices=devices)
2099
+ add_function_test(TestArray, "test_transpose", test_transpose, devices=devices)
2100
+ add_function_test(TestArray, "test_view", test_view, devices=devices)
2101
+
2102
+ add_function_test(TestArray, "test_1d_array", test_1d, devices=devices)
2103
+ add_function_test(TestArray, "test_2d_array", test_2d, devices=devices)
2104
+ add_function_test(TestArray, "test_3d_array", test_3d, devices=devices)
2105
+ add_function_test(TestArray, "test_4d_array", test_4d, devices=devices)
2106
+ add_function_test(TestArray, "test_4d_array_transposed", test_4d_transposed, devices=devices)
2107
+
2108
+ add_function_test(TestArray, "test_fill_scalar", test_fill_scalar, devices=devices)
2109
+ add_function_test(TestArray, "test_fill_vector", test_fill_vector, devices=devices)
2110
+ add_function_test(TestArray, "test_fill_matrix", test_fill_matrix, devices=devices)
2111
+ add_function_test(TestArray, "test_fill_struct", test_fill_struct, devices=devices)
2112
+ add_function_test(TestArray, "test_fill_slices", test_fill_slices, devices=devices)
2113
+ add_function_test(TestArray, "test_full_scalar", test_full_scalar, devices=devices)
2114
+ add_function_test(TestArray, "test_full_vector", test_full_vector, devices=devices)
2115
+ add_function_test(TestArray, "test_full_matrix", test_full_matrix, devices=devices)
2116
+ add_function_test(TestArray, "test_full_struct", test_full_struct, devices=devices)
2117
+ add_function_test(TestArray, "test_empty_array", test_empty_array, devices=devices)
2118
+ add_function_test(TestArray, "test_empty_from_numpy", test_empty_from_numpy, devices=devices)
2119
+ add_function_test(TestArray, "test_empty_from_list", test_empty_from_list, devices=devices)
2120
+ add_function_test(TestArray, "test_to_list_scalar", test_to_list_scalar, devices=devices)
2121
+ add_function_test(TestArray, "test_to_list_vector", test_to_list_vector, devices=devices)
2122
+ add_function_test(TestArray, "test_to_list_matrix", test_to_list_matrix, devices=devices)
2123
+ add_function_test(TestArray, "test_to_list_struct", test_to_list_struct, devices=devices)
2124
+
2125
+ add_function_test(TestArray, "test_lower_bound", test_lower_bound, devices=devices)
2126
+ add_function_test(TestArray, "test_round_trip", test_round_trip, devices=devices)
2127
+ add_function_test(TestArray, "test_array_to_bool", test_array_to_bool, devices=devices)
2128
+ add_function_test(TestArray, "test_array_of_structs", test_array_of_structs, devices=devices)
2129
+ add_function_test(TestArray, "test_array_of_structs_grad", test_array_of_structs_grad, devices=devices)
2130
+ add_function_test(TestArray, "test_array_of_structs_from_numpy", test_array_of_structs_from_numpy, devices=devices)
2131
+ add_function_test(TestArray, "test_array_of_structs_roundtrip", test_array_of_structs_roundtrip, devices=devices)
2132
+ add_function_test(TestArray, "test_array_from_numpy", test_array_from_numpy, devices=devices)
2152
2133
 
2153
2134
 
2154
2135
  if __name__ == "__main__":
2155
- c = register(unittest.TestCase)
2136
+ wp.build.clear_kernel_cache()
2156
2137
  unittest.main(verbosity=2)