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.
- docs/conf.py +3 -4
- examples/env/env_ant.py +1 -1
- examples/env/env_cartpole.py +1 -1
- examples/env/env_humanoid.py +1 -1
- examples/example_dem.py +28 -26
- examples/example_diffray.py +37 -30
- examples/example_fluid.py +7 -3
- examples/example_jacobian_ik.py +1 -1
- examples/example_mesh_intersect.py +10 -7
- examples/example_nvdb.py +3 -3
- examples/example_render_opengl.py +19 -10
- examples/example_sim_cartpole.py +9 -5
- examples/example_sim_cloth.py +29 -25
- examples/example_sim_fk_grad.py +2 -2
- examples/example_sim_fk_grad_torch.py +3 -3
- examples/example_sim_grad_bounce.py +11 -8
- examples/example_sim_grad_cloth.py +12 -9
- examples/example_sim_granular.py +2 -2
- examples/example_sim_granular_collision_sdf.py +13 -13
- examples/example_sim_neo_hookean.py +3 -3
- examples/example_sim_particle_chain.py +2 -2
- examples/example_sim_quadruped.py +8 -5
- examples/example_sim_rigid_chain.py +8 -5
- examples/example_sim_rigid_contact.py +13 -10
- examples/example_sim_rigid_fem.py +2 -2
- examples/example_sim_rigid_gyroscopic.py +2 -2
- examples/example_sim_rigid_kinematics.py +1 -1
- examples/example_sim_trajopt.py +3 -2
- examples/fem/example_apic_fluid.py +5 -7
- examples/fem/example_diffusion_mgpu.py +18 -16
- warp/__init__.py +3 -2
- warp/bin/warp.so +0 -0
- warp/build_dll.py +29 -9
- warp/builtins.py +206 -7
- warp/codegen.py +58 -38
- warp/config.py +3 -1
- warp/context.py +234 -128
- warp/fem/__init__.py +2 -2
- warp/fem/cache.py +2 -1
- warp/fem/field/nodal_field.py +18 -17
- warp/fem/geometry/hexmesh.py +11 -6
- warp/fem/geometry/quadmesh_2d.py +16 -12
- warp/fem/geometry/tetmesh.py +19 -8
- warp/fem/geometry/trimesh_2d.py +18 -7
- warp/fem/integrate.py +341 -196
- warp/fem/quadrature/__init__.py +1 -1
- warp/fem/quadrature/pic_quadrature.py +138 -53
- warp/fem/quadrature/quadrature.py +81 -9
- warp/fem/space/__init__.py +1 -1
- warp/fem/space/basis_space.py +169 -51
- warp/fem/space/grid_2d_function_space.py +2 -2
- warp/fem/space/grid_3d_function_space.py +2 -2
- warp/fem/space/hexmesh_function_space.py +2 -2
- warp/fem/space/partition.py +9 -6
- warp/fem/space/quadmesh_2d_function_space.py +2 -2
- warp/fem/space/shape/cube_shape_function.py +27 -15
- warp/fem/space/shape/square_shape_function.py +29 -18
- warp/fem/space/tetmesh_function_space.py +2 -2
- warp/fem/space/topology.py +10 -0
- warp/fem/space/trimesh_2d_function_space.py +2 -2
- warp/fem/utils.py +10 -5
- warp/native/array.h +49 -8
- warp/native/builtin.h +31 -14
- warp/native/cuda_util.cpp +8 -3
- warp/native/cuda_util.h +1 -0
- warp/native/exports.h +1177 -1108
- warp/native/intersect.h +4 -4
- warp/native/intersect_adj.h +8 -8
- warp/native/mat.h +65 -6
- warp/native/mesh.h +126 -5
- warp/native/quat.h +28 -4
- warp/native/vec.h +76 -14
- warp/native/warp.cu +1 -6
- warp/render/render_opengl.py +261 -109
- warp/sim/import_mjcf.py +13 -7
- warp/sim/import_urdf.py +14 -14
- warp/sim/inertia.py +17 -18
- warp/sim/model.py +67 -67
- warp/sim/render.py +1 -1
- warp/sparse.py +6 -6
- warp/stubs.py +19 -81
- warp/tape.py +1 -1
- warp/tests/__main__.py +3 -6
- warp/tests/{test_class_kernel.py → aux_test_class_kernel.py} +9 -1
- warp/tests/aux_test_conditional_unequal_types_kernels.py +21 -0
- warp/tests/{test_dependent.py → aux_test_dependent.py} +2 -2
- warp/tests/{test_reference.py → aux_test_reference.py} +1 -1
- warp/tests/aux_test_unresolved_func.py +14 -0
- warp/tests/aux_test_unresolved_symbol.py +14 -0
- warp/tests/{test_kinematics.py → disabled_kinematics.py} +10 -12
- warp/tests/run_coverage_serial.py +31 -0
- warp/tests/test_adam.py +102 -106
- warp/tests/test_arithmetic.py +39 -40
- warp/tests/test_array.py +46 -48
- warp/tests/test_array_reduce.py +25 -19
- warp/tests/test_atomic.py +62 -26
- warp/tests/test_bool.py +16 -11
- warp/tests/test_builtins_resolution.py +1292 -0
- warp/tests/test_bvh.py +9 -12
- warp/tests/test_closest_point_edge_edge.py +53 -57
- warp/tests/test_codegen.py +164 -134
- warp/tests/test_compile_consts.py +13 -19
- warp/tests/test_conditional.py +30 -32
- warp/tests/test_copy.py +9 -12
- warp/tests/test_ctypes.py +90 -98
- warp/tests/test_dense.py +20 -14
- warp/tests/test_devices.py +34 -35
- warp/tests/test_dlpack.py +74 -75
- warp/tests/test_examples.py +215 -97
- warp/tests/test_fabricarray.py +15 -21
- warp/tests/test_fast_math.py +14 -11
- warp/tests/test_fem.py +280 -97
- warp/tests/test_fp16.py +19 -15
- warp/tests/test_func.py +177 -194
- warp/tests/test_generics.py +71 -77
- warp/tests/test_grad.py +83 -32
- warp/tests/test_grad_customs.py +7 -9
- warp/tests/test_hash_grid.py +6 -10
- warp/tests/test_import.py +9 -23
- warp/tests/test_indexedarray.py +19 -21
- warp/tests/test_intersect.py +15 -9
- warp/tests/test_large.py +17 -19
- warp/tests/test_launch.py +14 -17
- warp/tests/test_lerp.py +63 -63
- warp/tests/test_lvalue.py +84 -35
- warp/tests/test_marching_cubes.py +9 -13
- warp/tests/test_mat.py +388 -3004
- warp/tests/test_mat_lite.py +9 -12
- warp/tests/test_mat_scalar_ops.py +2889 -0
- warp/tests/test_math.py +10 -11
- warp/tests/test_matmul.py +104 -100
- warp/tests/test_matmul_lite.py +72 -98
- warp/tests/test_mesh.py +35 -32
- warp/tests/test_mesh_query_aabb.py +18 -25
- warp/tests/test_mesh_query_point.py +39 -23
- warp/tests/test_mesh_query_ray.py +9 -21
- warp/tests/test_mlp.py +8 -9
- warp/tests/test_model.py +89 -93
- warp/tests/test_modules_lite.py +15 -25
- warp/tests/test_multigpu.py +87 -114
- warp/tests/test_noise.py +10 -12
- warp/tests/test_operators.py +14 -21
- warp/tests/test_options.py +10 -11
- warp/tests/test_pinned.py +16 -18
- warp/tests/test_print.py +16 -20
- warp/tests/test_quat.py +121 -88
- warp/tests/test_rand.py +12 -13
- warp/tests/test_reload.py +27 -32
- warp/tests/test_rounding.py +7 -10
- warp/tests/test_runlength_encode.py +105 -106
- warp/tests/test_smoothstep.py +8 -9
- warp/tests/test_snippet.py +13 -22
- warp/tests/test_sparse.py +30 -29
- warp/tests/test_spatial.py +179 -174
- warp/tests/test_streams.py +100 -107
- warp/tests/test_struct.py +98 -67
- warp/tests/test_tape.py +11 -17
- warp/tests/test_torch.py +89 -86
- warp/tests/test_transient_module.py +9 -12
- warp/tests/test_types.py +328 -50
- warp/tests/test_utils.py +217 -218
- warp/tests/test_vec.py +133 -2133
- warp/tests/test_vec_lite.py +8 -11
- warp/tests/test_vec_scalar_ops.py +2099 -0
- warp/tests/test_volume.py +391 -382
- warp/tests/test_volume_write.py +122 -135
- warp/tests/unittest_serial.py +35 -0
- warp/tests/unittest_suites.py +291 -0
- warp/tests/{test_base.py → unittest_utils.py} +138 -25
- warp/tests/{test_misc.py → unused_test_misc.py} +13 -5
- warp/tests/{test_debug.py → walkthough_debug.py} +2 -15
- warp/thirdparty/unittest_parallel.py +257 -54
- warp/types.py +119 -98
- warp/utils.py +14 -0
- {warp_lang-1.0.0b5.dist-info → warp_lang-1.0.0b6.dist-info}/METADATA +2 -1
- {warp_lang-1.0.0b5.dist-info → warp_lang-1.0.0b6.dist-info}/RECORD +182 -178
- {warp_lang-1.0.0b5.dist-info → warp_lang-1.0.0b6.dist-info}/WHEEL +1 -1
- warp/tests/test_all.py +0 -239
- warp/tests/test_conditional_unequal_types_kernels.py +0 -14
- warp/tests/test_coverage.py +0 -38
- warp/tests/test_unresolved_func.py +0 -7
- warp/tests/test_unresolved_symbol.py +0 -7
- /warp/tests/{test_compile_consts_dummy.py → aux_test_compile_consts_dummy.py} +0 -0
- /warp/tests/{test_reference_reference.py → aux_test_reference_reference.py} +0 -0
- /warp/tests/{test_square.py → aux_test_square.py} +0 -0
- {warp_lang-1.0.0b5.dist-info → warp_lang-1.0.0b6.dist-info}/LICENSE.md +0 -0
- {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.
|
|
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
|
-
|
|
106
|
-
|
|
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
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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
|
-
|
|
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
|
|
13
|
-
from warp.tests.test_base import *
|
|
11
|
+
import numpy as np
|
|
14
12
|
|
|
15
|
-
import
|
|
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
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
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)
|
warp/tests/test_generics.py
CHANGED
|
@@ -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.
|
|
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
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
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)
|