warp-lang 1.0.0b5__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 (187) hide show
  1. docs/conf.py +3 -4
  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/example_dem.py +28 -26
  6. examples/example_diffray.py +37 -30
  7. examples/example_fluid.py +7 -3
  8. examples/example_jacobian_ik.py +1 -1
  9. examples/example_mesh_intersect.py +10 -7
  10. examples/example_nvdb.py +3 -3
  11. examples/example_render_opengl.py +19 -10
  12. examples/example_sim_cartpole.py +9 -5
  13. examples/example_sim_cloth.py +29 -25
  14. examples/example_sim_fk_grad.py +2 -2
  15. examples/example_sim_fk_grad_torch.py +3 -3
  16. examples/example_sim_grad_bounce.py +11 -8
  17. examples/example_sim_grad_cloth.py +12 -9
  18. examples/example_sim_granular.py +2 -2
  19. examples/example_sim_granular_collision_sdf.py +13 -13
  20. examples/example_sim_neo_hookean.py +3 -3
  21. examples/example_sim_particle_chain.py +2 -2
  22. examples/example_sim_quadruped.py +8 -5
  23. examples/example_sim_rigid_chain.py +8 -5
  24. examples/example_sim_rigid_contact.py +13 -10
  25. examples/example_sim_rigid_fem.py +2 -2
  26. examples/example_sim_rigid_gyroscopic.py +2 -2
  27. examples/example_sim_rigid_kinematics.py +1 -1
  28. examples/example_sim_trajopt.py +3 -2
  29. examples/fem/example_apic_fluid.py +5 -7
  30. examples/fem/example_diffusion_mgpu.py +18 -16
  31. warp/__init__.py +3 -2
  32. warp/bin/warp.so +0 -0
  33. warp/build_dll.py +29 -9
  34. warp/builtins.py +206 -7
  35. warp/codegen.py +58 -38
  36. warp/config.py +3 -1
  37. warp/context.py +234 -128
  38. warp/fem/__init__.py +2 -2
  39. warp/fem/cache.py +2 -1
  40. warp/fem/field/nodal_field.py +18 -17
  41. warp/fem/geometry/hexmesh.py +11 -6
  42. warp/fem/geometry/quadmesh_2d.py +16 -12
  43. warp/fem/geometry/tetmesh.py +19 -8
  44. warp/fem/geometry/trimesh_2d.py +18 -7
  45. warp/fem/integrate.py +341 -196
  46. warp/fem/quadrature/__init__.py +1 -1
  47. warp/fem/quadrature/pic_quadrature.py +138 -53
  48. warp/fem/quadrature/quadrature.py +81 -9
  49. warp/fem/space/__init__.py +1 -1
  50. warp/fem/space/basis_space.py +169 -51
  51. warp/fem/space/grid_2d_function_space.py +2 -2
  52. warp/fem/space/grid_3d_function_space.py +2 -2
  53. warp/fem/space/hexmesh_function_space.py +2 -2
  54. warp/fem/space/partition.py +9 -6
  55. warp/fem/space/quadmesh_2d_function_space.py +2 -2
  56. warp/fem/space/shape/cube_shape_function.py +27 -15
  57. warp/fem/space/shape/square_shape_function.py +29 -18
  58. warp/fem/space/tetmesh_function_space.py +2 -2
  59. warp/fem/space/topology.py +10 -0
  60. warp/fem/space/trimesh_2d_function_space.py +2 -2
  61. warp/fem/utils.py +10 -5
  62. warp/native/array.h +49 -8
  63. warp/native/builtin.h +31 -14
  64. warp/native/cuda_util.cpp +8 -3
  65. warp/native/cuda_util.h +1 -0
  66. warp/native/exports.h +1177 -1108
  67. warp/native/intersect.h +4 -4
  68. warp/native/intersect_adj.h +8 -8
  69. warp/native/mat.h +65 -6
  70. warp/native/mesh.h +126 -5
  71. warp/native/quat.h +28 -4
  72. warp/native/vec.h +76 -14
  73. warp/native/warp.cu +1 -6
  74. warp/render/render_opengl.py +261 -109
  75. warp/sim/import_mjcf.py +13 -7
  76. warp/sim/import_urdf.py +14 -14
  77. warp/sim/inertia.py +17 -18
  78. warp/sim/model.py +67 -67
  79. warp/sim/render.py +1 -1
  80. warp/sparse.py +6 -6
  81. warp/stubs.py +19 -81
  82. warp/tape.py +1 -1
  83. warp/tests/__main__.py +3 -6
  84. warp/tests/{test_class_kernel.py → aux_test_class_kernel.py} +9 -1
  85. warp/tests/aux_test_conditional_unequal_types_kernels.py +21 -0
  86. warp/tests/{test_dependent.py → aux_test_dependent.py} +2 -2
  87. warp/tests/{test_reference.py → aux_test_reference.py} +1 -1
  88. warp/tests/aux_test_unresolved_func.py +14 -0
  89. warp/tests/aux_test_unresolved_symbol.py +14 -0
  90. warp/tests/{test_kinematics.py → disabled_kinematics.py} +10 -12
  91. warp/tests/run_coverage_serial.py +31 -0
  92. warp/tests/test_adam.py +102 -106
  93. warp/tests/test_arithmetic.py +39 -40
  94. warp/tests/test_array.py +46 -48
  95. warp/tests/test_array_reduce.py +25 -19
  96. warp/tests/test_atomic.py +62 -26
  97. warp/tests/test_bool.py +16 -11
  98. warp/tests/test_builtins_resolution.py +1292 -0
  99. warp/tests/test_bvh.py +9 -12
  100. warp/tests/test_closest_point_edge_edge.py +53 -57
  101. warp/tests/test_codegen.py +164 -134
  102. warp/tests/test_compile_consts.py +13 -19
  103. warp/tests/test_conditional.py +30 -32
  104. warp/tests/test_copy.py +9 -12
  105. warp/tests/test_ctypes.py +90 -98
  106. warp/tests/test_dense.py +20 -14
  107. warp/tests/test_devices.py +34 -35
  108. warp/tests/test_dlpack.py +74 -75
  109. warp/tests/test_examples.py +215 -97
  110. warp/tests/test_fabricarray.py +15 -21
  111. warp/tests/test_fast_math.py +14 -11
  112. warp/tests/test_fem.py +280 -97
  113. warp/tests/test_fp16.py +19 -15
  114. warp/tests/test_func.py +177 -194
  115. warp/tests/test_generics.py +71 -77
  116. warp/tests/test_grad.py +83 -32
  117. warp/tests/test_grad_customs.py +7 -9
  118. warp/tests/test_hash_grid.py +6 -10
  119. warp/tests/test_import.py +9 -23
  120. warp/tests/test_indexedarray.py +19 -21
  121. warp/tests/test_intersect.py +15 -9
  122. warp/tests/test_large.py +17 -19
  123. warp/tests/test_launch.py +14 -17
  124. warp/tests/test_lerp.py +63 -63
  125. warp/tests/test_lvalue.py +84 -35
  126. warp/tests/test_marching_cubes.py +9 -13
  127. warp/tests/test_mat.py +388 -3004
  128. warp/tests/test_mat_lite.py +9 -12
  129. warp/tests/test_mat_scalar_ops.py +2889 -0
  130. warp/tests/test_math.py +10 -11
  131. warp/tests/test_matmul.py +104 -100
  132. warp/tests/test_matmul_lite.py +72 -98
  133. warp/tests/test_mesh.py +35 -32
  134. warp/tests/test_mesh_query_aabb.py +18 -25
  135. warp/tests/test_mesh_query_point.py +39 -23
  136. warp/tests/test_mesh_query_ray.py +9 -21
  137. warp/tests/test_mlp.py +8 -9
  138. warp/tests/test_model.py +89 -93
  139. warp/tests/test_modules_lite.py +15 -25
  140. warp/tests/test_multigpu.py +87 -114
  141. warp/tests/test_noise.py +10 -12
  142. warp/tests/test_operators.py +14 -21
  143. warp/tests/test_options.py +10 -11
  144. warp/tests/test_pinned.py +16 -18
  145. warp/tests/test_print.py +16 -20
  146. warp/tests/test_quat.py +121 -88
  147. warp/tests/test_rand.py +12 -13
  148. warp/tests/test_reload.py +27 -32
  149. warp/tests/test_rounding.py +7 -10
  150. warp/tests/test_runlength_encode.py +105 -106
  151. warp/tests/test_smoothstep.py +8 -9
  152. warp/tests/test_snippet.py +13 -22
  153. warp/tests/test_sparse.py +30 -29
  154. warp/tests/test_spatial.py +179 -174
  155. warp/tests/test_streams.py +100 -107
  156. warp/tests/test_struct.py +98 -67
  157. warp/tests/test_tape.py +11 -17
  158. warp/tests/test_torch.py +89 -86
  159. warp/tests/test_transient_module.py +9 -12
  160. warp/tests/test_types.py +328 -50
  161. warp/tests/test_utils.py +217 -218
  162. warp/tests/test_vec.py +133 -2133
  163. warp/tests/test_vec_lite.py +8 -11
  164. warp/tests/test_vec_scalar_ops.py +2099 -0
  165. warp/tests/test_volume.py +391 -382
  166. warp/tests/test_volume_write.py +122 -135
  167. warp/tests/unittest_serial.py +35 -0
  168. warp/tests/unittest_suites.py +291 -0
  169. warp/tests/{test_base.py → unittest_utils.py} +138 -25
  170. warp/tests/{test_misc.py → unused_test_misc.py} +13 -5
  171. warp/tests/{test_debug.py → walkthough_debug.py} +2 -15
  172. warp/thirdparty/unittest_parallel.py +257 -54
  173. warp/types.py +119 -98
  174. warp/utils.py +14 -0
  175. {warp_lang-1.0.0b5.dist-info → warp_lang-1.0.0b6.dist-info}/METADATA +2 -1
  176. {warp_lang-1.0.0b5.dist-info → warp_lang-1.0.0b6.dist-info}/RECORD +182 -178
  177. {warp_lang-1.0.0b5.dist-info → warp_lang-1.0.0b6.dist-info}/WHEEL +1 -1
  178. warp/tests/test_all.py +0 -239
  179. warp/tests/test_conditional_unequal_types_kernels.py +0 -14
  180. warp/tests/test_coverage.py +0 -38
  181. warp/tests/test_unresolved_func.py +0 -7
  182. warp/tests/test_unresolved_symbol.py +0 -7
  183. /warp/tests/{test_compile_consts_dummy.py → aux_test_compile_consts_dummy.py} +0 -0
  184. /warp/tests/{test_reference_reference.py → aux_test_reference_reference.py} +0 -0
  185. /warp/tests/{test_square.py → aux_test_square.py} +0 -0
  186. {warp_lang-1.0.0b5.dist-info → warp_lang-1.0.0b6.dist-info}/LICENSE.md +0 -0
  187. {warp_lang-1.0.0b5.dist-info → warp_lang-1.0.0b6.dist-info}/top_level.txt +0 -0
warp/tests/test_fp16.py CHANGED
@@ -1,9 +1,16 @@
1
+ # Copyright (c) 2023 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
+
1
8
  import unittest
2
9
 
3
10
  import numpy as np
4
11
 
5
12
  import warp as wp
6
- from warp.tests.test_base import *
13
+ from warp.tests.unittest_utils import *
7
14
 
8
15
  wp.init()
9
16
 
@@ -102,25 +109,22 @@ def test_fp16_grad(test, device):
102
109
  assert_np_equal(input.grad.numpy(), np.ones(len(s)) * 2.0)
103
110
 
104
111
 
105
- def register(parent):
106
- class TestFp16(parent):
107
- pass
112
+ class TestFp16(unittest.TestCase):
113
+ pass
108
114
 
109
- devices = []
110
- if wp.is_cpu_available():
111
- devices.append("cpu")
112
- for cuda_device in wp.get_cuda_devices():
113
- if cuda_device.arch >= 70:
114
- devices.append(cuda_device)
115
115
 
116
- add_function_test(TestFp16, "test_fp16_conversion", test_fp16_conversion, devices=devices)
117
- add_function_test(TestFp16, "test_fp16_grad", test_fp16_grad, devices=devices)
118
- add_function_test(TestFp16, "test_fp16_kernel_parameter", test_fp16_kernel_parameter, devices=devices)
116
+ devices = []
117
+ if wp.is_cpu_available():
118
+ devices.append("cpu")
119
+ for cuda_device in get_unique_cuda_test_devices():
120
+ if cuda_device.arch >= 70:
121
+ devices.append(cuda_device)
119
122
 
120
- return TestFp16
123
+ add_function_test(TestFp16, "test_fp16_conversion", test_fp16_conversion, devices=devices)
124
+ add_function_test(TestFp16, "test_fp16_grad", test_fp16_grad, devices=devices)
125
+ add_function_test(TestFp16, "test_fp16_kernel_parameter", test_fp16_kernel_parameter, devices=devices)
121
126
 
122
127
 
123
128
  if __name__ == "__main__":
124
129
  wp.build.clear_kernel_cache()
125
- _ = register(unittest.TestCase)
126
130
  unittest.main(verbosity=2)
warp/tests/test_func.py CHANGED
@@ -5,14 +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
- # include parent path
9
- import numpy as np
10
8
  import math
9
+ import unittest
11
10
 
12
- import warp as wp
13
- from warp.tests.test_base import *
11
+ import numpy as np
14
12
 
15
- import unittest
13
+ import warp as wp
14
+ from warp.tests.unittest_utils import *
16
15
 
17
16
  wp.init()
18
17
 
@@ -83,169 +82,6 @@ def test_override_func():
83
82
  wp.expect_eq(i, 3)
84
83
 
85
84
 
86
- def test_native_func_export(test, device):
87
- # tests calling native functions from Python
88
-
89
- q = wp.quat(0.0, 0.0, 0.0, 1.0)
90
- assert_np_equal(np.array([*q]), np.array([0.0, 0.0, 0.0, 1.0]))
91
-
92
- r = wp.quat_from_axis_angle((1.0, 0.0, 0.0), 2.0)
93
- assert_np_equal(np.array([*r]), np.array([0.8414709568023682, 0.0, 0.0, 0.5403022170066833]), tol=1.0e-3)
94
-
95
- q = wp.quat(1.0, 2.0, 3.0, 4.0)
96
- q = wp.normalize(q) * 2.0
97
- assert_np_equal(
98
- np.array([*q]),
99
- np.array([0.18257418274879456, 0.3651483654975891, 0.547722578048706, 0.7302967309951782]) * 2.0,
100
- tol=1.0e-3,
101
- )
102
-
103
- v2 = wp.vec2(1.0, 2.0)
104
- v2 = wp.normalize(v2) * 2.0
105
- assert_np_equal(np.array([*v2]), np.array([0.4472135901451111, 0.8944271802902222]) * 2.0, tol=1.0e-3)
106
-
107
- v3 = wp.vec3(1.0, 2.0, 3.0)
108
- v3 = wp.normalize(v3) * 2.0
109
- assert_np_equal(
110
- np.array([*v3]), np.array([0.26726123690605164, 0.5345224738121033, 0.8017836809158325]) * 2.0, tol=1.0e-3
111
- )
112
-
113
- v4 = wp.vec4(1.0, 2.0, 3.0, 4.0)
114
- v4 = wp.normalize(v4) * 2.0
115
- assert_np_equal(
116
- np.array([*v4]),
117
- np.array([0.18257418274879456, 0.3651483654975891, 0.547722578048706, 0.7302967309951782]) * 2.0,
118
- tol=1.0e-3,
119
- )
120
-
121
- v = wp.vec2(0.0)
122
- v += wp.vec2(1.0, 1.0)
123
- assert v == wp.vec2(1.0, 1.0)
124
- v -= wp.vec2(1.0, 1.0)
125
- assert v == wp.vec2(0.0, 0.0)
126
- v = wp.vec2(2.0, 2.0) - wp.vec2(1.0, 1.0)
127
- assert v == wp.vec2(1.0, 1.0)
128
- v *= 2.0
129
- assert v == wp.vec2(2.0, 2.0)
130
- v = v * 2.0
131
- assert v == wp.vec2(4.0, 4.0)
132
- v = v / 2.0
133
- assert v == wp.vec2(2.0, 2.0)
134
- v /= 2.0
135
- assert v == wp.vec2(1.0, 1.0)
136
- v = -v
137
- assert v == wp.vec2(-1.0, -1.0)
138
- v = +v
139
- assert v == wp.vec2(-1.0, -1.0)
140
-
141
- m22 = wp.mat22(1.0, 2.0, 3.0, 4.0)
142
- m22 = m22 + m22
143
-
144
- test.assertEqual(m22[1, 1], 8.0)
145
- test.assertEqual(str(m22), "[[2.0, 4.0],\n [6.0, 8.0]]")
146
-
147
- t = wp.transform(
148
- wp.vec3(1.0, 2.0, 3.0),
149
- wp.quat(4.0, 5.0, 6.0, 7.0),
150
- )
151
- test.assertSequenceEqual(t, (1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0))
152
- test.assertSequenceEqual(t * (1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0), (396.0, 432.0, 720.0, 56.0, 70.0, 84.0, -28.0))
153
- test.assertSequenceEqual(
154
- t * wp.transform((1.0, 2.0, 3.0), (4.0, 5.0, 6.0, 7.0)), (396.0, 432.0, 720.0, 56.0, 70.0, 84.0, -28.0)
155
- )
156
-
157
- t = wp.transform()
158
- test.assertSequenceEqual(t, (0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0))
159
-
160
- t = wp.transform(p=(1.0, 2.0, 3.0), q=(4.0, 5.0, 6.0, 7.0))
161
- test.assertSequenceEqual(t, (1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0))
162
-
163
- t = wp.transform(q=(4.0, 5.0, 6.0, 7.0), p=(1.0, 2.0, 3.0))
164
- test.assertSequenceEqual(t, (1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0))
165
-
166
- t = wp.transform((1.0, 2.0, 3.0), q=(4.0, 5.0, 6.0, 7.0))
167
- test.assertSequenceEqual(t, (1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0))
168
-
169
- t = wp.transform(p=(1.0, 2.0, 3.0))
170
- test.assertSequenceEqual(t, (1.0, 2.0, 3.0, 0.0, 0.0, 0.0, 1.0))
171
-
172
- t = wp.transform(q=(4.0, 5.0, 6.0, 7.0))
173
- test.assertSequenceEqual(t, (0.0, 0.0, 0.0, 4.0, 5.0, 6.0, 7.0))
174
-
175
- t = wp.transform((1.0, 2.0, 3.0), (4.0, 5.0, 6.0, 7.0))
176
- test.assertSequenceEqual(t, (1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0))
177
-
178
- t = wp.transform(p=wp.vec3(1.0, 2.0, 3.0), q=wp.quat(4.0, 5.0, 6.0, 7.0))
179
- test.assertSequenceEqual(t, (1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0))
180
-
181
- t = wp.transform(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0)
182
- test.assertSequenceEqual(t, (1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0))
183
-
184
- t = wp.transform(wp.transform(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0))
185
- test.assertSequenceEqual(t, (1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0))
186
-
187
- t = wp.transform(*wp.transform(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0))
188
- test.assertSequenceEqual(t, (1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0))
189
-
190
- transformf = wp.types.transformation(dtype=float)
191
-
192
- t = wp.transformf((1.0, 2.0, 3.0), (4.0, 5.0, 6.0, 7.0))
193
- test.assertSequenceEqual(
194
- t + transformf((2.0, 3.0, 4.0), (5.0, 6.0, 7.0, 8.0)),
195
- (3.0, 5.0, 7.0, 9.0, 11.0, 13.0, 15.0),
196
- )
197
- test.assertSequenceEqual(
198
- t - transformf((2.0, 3.0, 4.0), (5.0, 6.0, 7.0, 8.0)),
199
- (-1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0),
200
- )
201
-
202
- f = wp.sin(math.pi * 0.5)
203
- test.assertAlmostEqual(f, 1.0, places=3)
204
-
205
- m = wp.mat22(0.0, 0.0, 0.0, 0.0)
206
- m += wp.mat22(1.0, 1.0, 1.0, 1.0)
207
- assert m == wp.mat22(1.0, 1.0, 1.0, 1.0)
208
- m -= wp.mat22(1.0, 1.0, 1.0, 1.0)
209
- assert m == wp.mat22(0.0, 0.0, 0.0, 0.0)
210
- m = wp.mat22(2.0, 2.0, 2.0, 2.0) - wp.mat22(1.0, 1.0, 1.0, 1.0)
211
- assert m == wp.mat22(1.0, 1.0, 1.0, 1.0)
212
- m *= 2.0
213
- assert m == wp.mat22(2.0, 2.0, 2.0, 2.0)
214
- m = m * 2.0
215
- assert m == wp.mat22(4.0, 4.0, 4.0, 4.0)
216
- m = m / 2.0
217
- assert m == wp.mat22(2.0, 2.0, 2.0, 2.0)
218
- m /= 2.0
219
- assert m == wp.mat22(1.0, 1.0, 1.0, 1.0)
220
- m = -m
221
- assert m == wp.mat22(-1.0, -1.0, -1.0, -1.0)
222
- m = +m
223
- assert m == wp.mat22(-1.0, -1.0, -1.0, -1.0)
224
- m = m * m
225
- assert m == wp.mat22(2.0, 2.0, 2.0, 2.0)
226
-
227
-
228
- def test_native_function_error_resolution(test, device):
229
- a = wp.mat22f(1.0, 2.0, 3.0, 4.0)
230
- b = wp.mat22d(1.0, 2.0, 3.0, 4.0)
231
- with test.assertRaisesRegex(
232
- RuntimeError,
233
- r"^Couldn't find a function 'mul' compatible with " r"the arguments 'mat22f, mat22d'$",
234
- ):
235
- a * b
236
-
237
-
238
- def test_user_func_export(test, device):
239
- # tests calling overloaded user-defined functions from Python
240
- i = custom(1)
241
- f = custom(1.0)
242
- v = custom(wp.vec3(1.0, 0.0, 0.0))
243
-
244
- test.assertEqual(i, 2)
245
- test.assertEqual(f, 2.0)
246
- assert_np_equal(np.array([*v]), np.array([2.0, 0.0, 0.0]))
247
-
248
-
249
85
  def test_func_closure_capture(test, device):
250
86
  def make_closure_kernel(func):
251
87
  def closure_kernel_fn(data: wp.array(dtype=float), expected: float):
@@ -321,34 +157,181 @@ def test_builtin_shadowing():
321
157
  wp.expect_eq(sign(1.23), 123.0)
322
158
 
323
159
 
324
- def register(parent):
325
- devices = get_test_devices()
326
-
327
- class TestFunc(parent):
328
- pass
329
-
330
- add_kernel_test(TestFunc, kernel=test_overload_func, name="test_overload_func", dim=1, devices=devices)
331
- add_function_test(TestFunc, func=test_return_func, name="test_return_func", devices=devices)
332
- add_kernel_test(TestFunc, kernel=test_override_func, name="test_override_func", dim=1, devices=devices)
333
- add_function_test(TestFunc, func=test_native_func_export, name="test_native_func_export", devices=["cpu"])
334
- add_function_test(
335
- TestFunc,
336
- func=test_native_function_error_resolution,
337
- name="test_native_function_error_resolution",
338
- devices=["cpu"],
339
- )
340
- add_function_test(TestFunc, func=test_user_func_export, name="test_user_func_export", devices=["cpu"])
341
- add_function_test(TestFunc, func=test_func_closure_capture, name="test_func_closure_capture", devices=devices)
342
- add_function_test(TestFunc, func=test_multi_valued_func, name="test_multi_valued_func", devices=devices)
343
- add_kernel_test(TestFunc, kernel=test_func_defaults, name="test_func_defaults", dim=1, devices=devices)
344
- add_kernel_test(TestFunc, kernel=test_builtin_shadowing, name="test_builtin_shadowing", dim=1, devices=devices)
345
-
346
- return TestFunc
160
+ devices = get_test_devices()
161
+
162
+
163
+ class TestFunc(unittest.TestCase):
164
+ def test_user_func_export(self):
165
+ # tests calling overloaded user-defined functions from Python
166
+ i = custom(1)
167
+ f = custom(1.0)
168
+ v = custom(wp.vec3(1.0, 0.0, 0.0))
169
+
170
+ self.assertEqual(i, 2)
171
+ self.assertEqual(f, 2.0)
172
+ assert_np_equal(np.array([*v]), np.array([2.0, 0.0, 0.0]))
173
+
174
+ def test_native_func_export(self):
175
+ # tests calling native functions from Python
176
+
177
+ q = wp.quat(0.0, 0.0, 0.0, 1.0)
178
+ assert_np_equal(np.array([*q]), np.array([0.0, 0.0, 0.0, 1.0]))
179
+
180
+ r = wp.quat_from_axis_angle(wp.vec3(1.0, 0.0, 0.0), 2.0)
181
+ assert_np_equal(np.array([*r]), np.array([0.8414709568023682, 0.0, 0.0, 0.5403022170066833]), tol=1.0e-3)
182
+
183
+ q = wp.quat(1.0, 2.0, 3.0, 4.0)
184
+ q = wp.normalize(q) * 2.0
185
+ assert_np_equal(
186
+ np.array([*q]),
187
+ np.array([0.18257418274879456, 0.3651483654975891, 0.547722578048706, 0.7302967309951782]) * 2.0,
188
+ tol=1.0e-3,
189
+ )
190
+
191
+ v2 = wp.vec2(1.0, 2.0)
192
+ v2 = wp.normalize(v2) * 2.0
193
+ assert_np_equal(np.array([*v2]), np.array([0.4472135901451111, 0.8944271802902222]) * 2.0, tol=1.0e-3)
194
+
195
+ v3 = wp.vec3(1.0, 2.0, 3.0)
196
+ v3 = wp.normalize(v3) * 2.0
197
+ assert_np_equal(
198
+ np.array([*v3]), np.array([0.26726123690605164, 0.5345224738121033, 0.8017836809158325]) * 2.0, tol=1.0e-3
199
+ )
200
+
201
+ v4 = wp.vec4(1.0, 2.0, 3.0, 4.0)
202
+ v4 = wp.normalize(v4) * 2.0
203
+ assert_np_equal(
204
+ np.array([*v4]),
205
+ np.array([0.18257418274879456, 0.3651483654975891, 0.547722578048706, 0.7302967309951782]) * 2.0,
206
+ tol=1.0e-3,
207
+ )
208
+
209
+ v = wp.vec2(0.0)
210
+ v += wp.vec2(1.0, 1.0)
211
+ assert v == wp.vec2(1.0, 1.0)
212
+ v -= wp.vec2(1.0, 1.0)
213
+ assert v == wp.vec2(0.0, 0.0)
214
+ v = wp.vec2(2.0, 2.0) - wp.vec2(1.0, 1.0)
215
+ assert v == wp.vec2(1.0, 1.0)
216
+ v *= 2.0
217
+ assert v == wp.vec2(2.0, 2.0)
218
+ v = v * 2.0
219
+ assert v == wp.vec2(4.0, 4.0)
220
+ v = v / 2.0
221
+ assert v == wp.vec2(2.0, 2.0)
222
+ v /= 2.0
223
+ assert v == wp.vec2(1.0, 1.0)
224
+ v = -v
225
+ assert v == wp.vec2(-1.0, -1.0)
226
+ v = +v
227
+ assert v == wp.vec2(-1.0, -1.0)
228
+
229
+ m22 = wp.mat22(1.0, 2.0, 3.0, 4.0)
230
+ m22 = m22 + m22
231
+
232
+ self.assertEqual(m22[1, 1], 8.0)
233
+ self.assertEqual(str(m22), "[[2.0, 4.0],\n [6.0, 8.0]]")
234
+
235
+ t = wp.transform(
236
+ wp.vec3(1.0, 2.0, 3.0),
237
+ wp.quat(4.0, 5.0, 6.0, 7.0),
238
+ )
239
+ self.assertSequenceEqual(t, (1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0))
240
+ self.assertSequenceEqual(t * wp.transform(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0), (396.0, 432.0, 720.0, 56.0, 70.0, 84.0, -28.0))
241
+ self.assertSequenceEqual(
242
+ t * wp.transform((1.0, 2.0, 3.0), (4.0, 5.0, 6.0, 7.0)), (396.0, 432.0, 720.0, 56.0, 70.0, 84.0, -28.0)
243
+ )
244
+
245
+ t = wp.transform()
246
+ self.assertSequenceEqual(t, (0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0))
247
+
248
+ t = wp.transform(p=(1.0, 2.0, 3.0), q=(4.0, 5.0, 6.0, 7.0))
249
+ self.assertSequenceEqual(t, (1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0))
250
+
251
+ t = wp.transform(q=(4.0, 5.0, 6.0, 7.0), p=(1.0, 2.0, 3.0))
252
+ self.assertSequenceEqual(t, (1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0))
253
+
254
+ t = wp.transform((1.0, 2.0, 3.0), q=(4.0, 5.0, 6.0, 7.0))
255
+ self.assertSequenceEqual(t, (1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0))
256
+
257
+ t = wp.transform(p=(1.0, 2.0, 3.0))
258
+ self.assertSequenceEqual(t, (1.0, 2.0, 3.0, 0.0, 0.0, 0.0, 1.0))
259
+
260
+ t = wp.transform(q=(4.0, 5.0, 6.0, 7.0))
261
+ self.assertSequenceEqual(t, (0.0, 0.0, 0.0, 4.0, 5.0, 6.0, 7.0))
262
+
263
+ t = wp.transform((1.0, 2.0, 3.0), (4.0, 5.0, 6.0, 7.0))
264
+ self.assertSequenceEqual(t, (1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0))
265
+
266
+ t = wp.transform(p=wp.vec3(1.0, 2.0, 3.0), q=wp.quat(4.0, 5.0, 6.0, 7.0))
267
+ self.assertSequenceEqual(t, (1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0))
268
+
269
+ t = wp.transform(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0)
270
+ self.assertSequenceEqual(t, (1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0))
271
+
272
+ t = wp.transform(wp.transform(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0))
273
+ self.assertSequenceEqual(t, (1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0))
274
+
275
+ t = wp.transform(*wp.transform(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0))
276
+ self.assertSequenceEqual(t, (1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0))
277
+
278
+ transformf = wp.types.transformation(dtype=float)
279
+
280
+ t = wp.transformf((1.0, 2.0, 3.0), (4.0, 5.0, 6.0, 7.0))
281
+ self.assertSequenceEqual(
282
+ t + transformf((2.0, 3.0, 4.0), (5.0, 6.0, 7.0, 8.0)),
283
+ (3.0, 5.0, 7.0, 9.0, 11.0, 13.0, 15.0),
284
+ )
285
+ self.assertSequenceEqual(
286
+ t - transformf((2.0, 3.0, 4.0), (5.0, 6.0, 7.0, 8.0)),
287
+ (-1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0),
288
+ )
289
+
290
+ f = wp.sin(math.pi * 0.5)
291
+ self.assertAlmostEqual(f, 1.0, places=3)
292
+
293
+ m = wp.mat22(0.0, 0.0, 0.0, 0.0)
294
+ m += wp.mat22(1.0, 1.0, 1.0, 1.0)
295
+ assert m == wp.mat22(1.0, 1.0, 1.0, 1.0)
296
+ m -= wp.mat22(1.0, 1.0, 1.0, 1.0)
297
+ assert m == wp.mat22(0.0, 0.0, 0.0, 0.0)
298
+ m = wp.mat22(2.0, 2.0, 2.0, 2.0) - wp.mat22(1.0, 1.0, 1.0, 1.0)
299
+ assert m == wp.mat22(1.0, 1.0, 1.0, 1.0)
300
+ m *= 2.0
301
+ assert m == wp.mat22(2.0, 2.0, 2.0, 2.0)
302
+ m = m * 2.0
303
+ assert m == wp.mat22(4.0, 4.0, 4.0, 4.0)
304
+ m = m / 2.0
305
+ assert m == wp.mat22(2.0, 2.0, 2.0, 2.0)
306
+ m /= 2.0
307
+ assert m == wp.mat22(1.0, 1.0, 1.0, 1.0)
308
+ m = -m
309
+ assert m == wp.mat22(-1.0, -1.0, -1.0, -1.0)
310
+ m = +m
311
+ assert m == wp.mat22(-1.0, -1.0, -1.0, -1.0)
312
+ m = m * m
313
+ assert m == wp.mat22(2.0, 2.0, 2.0, 2.0)
314
+
315
+
316
+ def test_native_function_error_resolution(self):
317
+ a = wp.mat22f(1.0, 2.0, 3.0, 4.0)
318
+ b = wp.mat22d(1.0, 2.0, 3.0, 4.0)
319
+ with self.assertRaisesRegex(
320
+ RuntimeError,
321
+ r"^Couldn't find a function 'mul' compatible with " r"the arguments 'mat22f, mat22d'$",
322
+ ):
323
+ a * b
324
+
325
+
326
+ add_kernel_test(TestFunc, kernel=test_overload_func, name="test_overload_func", dim=1, devices=devices)
327
+ add_function_test(TestFunc, func=test_return_func, name="test_return_func", devices=devices)
328
+ add_kernel_test(TestFunc, kernel=test_override_func, name="test_override_func", dim=1, devices=devices)
329
+ add_function_test(TestFunc, func=test_func_closure_capture, name="test_func_closure_capture", devices=devices)
330
+ add_function_test(TestFunc, func=test_multi_valued_func, name="test_multi_valued_func", devices=devices)
331
+ add_kernel_test(TestFunc, kernel=test_func_defaults, name="test_func_defaults", dim=1, devices=devices)
332
+ add_kernel_test(TestFunc, kernel=test_builtin_shadowing, name="test_builtin_shadowing", dim=1, devices=devices)
347
333
 
348
334
 
349
335
  if __name__ == "__main__":
350
336
  wp.build.clear_kernel_cache()
351
- _ = register(unittest.TestCase)
352
- wp.force_load()
353
-
354
337
  unittest.main(verbosity=2)
@@ -5,12 +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 numpy as np
9
8
  import unittest
10
9
  from typing import Any
11
10
 
11
+ import numpy as np
12
+
12
13
  import warp as wp
13
- from warp.tests.test_base import *
14
+ from warp.tests.unittest_utils import *
14
15
 
15
16
  wp.init()
16
17
 
@@ -463,7 +464,7 @@ def test_type_operator_mispell(test, device):
463
464
  i = wp.tid()
464
465
  _ = typez(i)(0)
465
466
 
466
- with test.assertRaisesRegex(RuntimeError, r"Unknown operator 'typez'$"):
467
+ with test.assertRaisesRegex(RuntimeError, r"Unknown function or operator: 'typez'$"):
467
468
  wp.launch(
468
469
  kernel,
469
470
  dim=1,
@@ -487,81 +488,74 @@ def test_type_attribute_error(test, device):
487
488
  )
488
489
 
489
490
 
490
- def register(parent):
491
- class TestGenerics(parent):
492
- pass
493
-
494
- devices = get_test_devices()
495
-
496
- add_kernel_test(TestGenerics, name="test_generic_adder", kernel=test_generic_adder, dim=1, devices=devices)
497
- add_kernel_test(TestGenerics, name="test_specialized_func", kernel=test_specialized_func, dim=1, devices=devices)
498
-
499
- add_function_test(TestGenerics, "test_generic_array_kernel", test_generic_array_kernel, devices=devices)
500
- add_function_test(TestGenerics, "test_generic_accumulator_kernel", test_generic_accumulator_kernel, devices=devices)
501
- add_function_test(TestGenerics, "test_generic_fill", test_generic_fill, devices=devices)
502
- add_function_test(TestGenerics, "test_generic_fill_overloads", test_generic_fill_overloads, devices=devices)
503
- add_function_test(TestGenerics, "test_generic_transform_kernel", test_generic_transform_kernel, devices=devices)
504
- add_function_test(
505
- TestGenerics, "test_generic_transform_array_kernel", test_generic_transform_array_kernel, devices=devices
506
- )
507
- add_function_test(TestGenerics, "test_generic_type_cast", test_generic_type_cast, devices=devices)
508
- add_function_test(TestGenerics, "test_generic_type_construction", test_generic_type_construction, devices=devices)
509
- add_function_test(
510
- TestGenerics, "test_generic_scalar_construction", test_generic_scalar_construction, devices=devices
511
- )
512
- add_function_test(TestGenerics, "test_generic_type_as_argument", test_generic_type_as_argument, devices=devices)
513
-
514
- foo = Foo()
515
- foo.x = 17.0
516
- foo.y = 25.0
517
- foo.z = 42.0
518
-
519
- bar = Bar()
520
- bar.x = wp.vec3(1, 2, 3)
521
- bar.y = wp.vec3(10, 20, 30)
522
- bar.z = wp.vec3(11, 22, 33)
523
-
524
- add_kernel_test(
525
- TestGenerics,
526
- name="test_generic_struct_kernel",
527
- kernel=test_generic_struct_kernel,
528
- dim=1,
529
- inputs=[foo],
530
- devices=devices,
531
- )
532
- add_kernel_test(
533
- TestGenerics,
534
- name="test_generic_struct_kernel",
535
- kernel=test_generic_struct_kernel,
536
- dim=1,
537
- inputs=[bar],
538
- devices=devices,
539
- )
540
-
541
- add_kernel_test(
542
- TestGenerics,
543
- name="test_generic_struct_construction_kernel",
544
- kernel=test_generic_struct_construction_kernel,
545
- dim=1,
546
- inputs=[foo],
547
- devices=devices,
548
- )
549
- add_kernel_test(
550
- TestGenerics,
551
- name="test_generic_struct_construction_kernel",
552
- kernel=test_generic_struct_construction_kernel,
553
- dim=1,
554
- inputs=[bar],
555
- devices=devices,
556
- )
557
-
558
- add_function_test(TestGenerics, "test_type_operator_mispell", test_type_operator_mispell, devices=devices)
559
- add_function_test(TestGenerics, "test_type_attribute_error", test_type_attribute_error, devices=devices)
560
-
561
- return TestGenerics
562
-
491
+ class TestGenerics(unittest.TestCase):
492
+ pass
493
+
494
+
495
+ devices = get_test_devices()
496
+
497
+ add_kernel_test(TestGenerics, name="test_generic_adder", kernel=test_generic_adder, dim=1, devices=devices)
498
+ add_kernel_test(TestGenerics, name="test_specialized_func", kernel=test_specialized_func, dim=1, devices=devices)
499
+
500
+ add_function_test(TestGenerics, "test_generic_array_kernel", test_generic_array_kernel, devices=devices)
501
+ add_function_test(TestGenerics, "test_generic_accumulator_kernel", test_generic_accumulator_kernel, devices=devices)
502
+ add_function_test(TestGenerics, "test_generic_fill", test_generic_fill, devices=devices)
503
+ add_function_test(TestGenerics, "test_generic_fill_overloads", test_generic_fill_overloads, devices=devices)
504
+ add_function_test(TestGenerics, "test_generic_transform_kernel", test_generic_transform_kernel, devices=devices)
505
+ add_function_test(
506
+ TestGenerics, "test_generic_transform_array_kernel", test_generic_transform_array_kernel, devices=devices
507
+ )
508
+ add_function_test(TestGenerics, "test_generic_type_cast", test_generic_type_cast, devices=devices)
509
+ add_function_test(TestGenerics, "test_generic_type_construction", test_generic_type_construction, devices=devices)
510
+ add_function_test(TestGenerics, "test_generic_scalar_construction", test_generic_scalar_construction, devices=devices)
511
+ add_function_test(TestGenerics, "test_generic_type_as_argument", test_generic_type_as_argument, devices=devices)
512
+
513
+ foo = Foo()
514
+ foo.x = 17.0
515
+ foo.y = 25.0
516
+ foo.z = 42.0
517
+
518
+ bar = Bar()
519
+ bar.x = wp.vec3(1, 2, 3)
520
+ bar.y = wp.vec3(10, 20, 30)
521
+ bar.z = wp.vec3(11, 22, 33)
522
+
523
+ add_kernel_test(
524
+ TestGenerics,
525
+ name="test_generic_struct_kernel",
526
+ kernel=test_generic_struct_kernel,
527
+ dim=1,
528
+ inputs=[foo],
529
+ devices=devices,
530
+ )
531
+ add_kernel_test(
532
+ TestGenerics,
533
+ name="test_generic_struct_kernel",
534
+ kernel=test_generic_struct_kernel,
535
+ dim=1,
536
+ inputs=[bar],
537
+ devices=devices,
538
+ )
539
+
540
+ add_kernel_test(
541
+ TestGenerics,
542
+ name="test_generic_struct_construction_kernel",
543
+ kernel=test_generic_struct_construction_kernel,
544
+ dim=1,
545
+ inputs=[foo],
546
+ devices=devices,
547
+ )
548
+ add_kernel_test(
549
+ TestGenerics,
550
+ name="test_generic_struct_construction_kernel",
551
+ kernel=test_generic_struct_construction_kernel,
552
+ dim=1,
553
+ inputs=[bar],
554
+ devices=devices,
555
+ )
556
+ add_function_test(TestGenerics, "test_type_operator_mispell", test_type_operator_mispell, devices=devices)
557
+ add_function_test(TestGenerics, "test_type_attribute_error", test_type_attribute_error, devices=devices)
563
558
 
564
559
  if __name__ == "__main__":
565
560
  wp.build.clear_kernel_cache()
566
- _ = register(unittest.TestCase)
567
561
  unittest.main(verbosity=2)