warp-lang 1.7.2rc1__py3-none-win_amd64.whl → 1.8.1__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.
- warp/__init__.py +3 -1
- warp/__init__.pyi +3489 -1
- warp/autograd.py +45 -122
- warp/bin/warp-clang.dll +0 -0
- warp/bin/warp.dll +0 -0
- warp/build.py +241 -252
- warp/build_dll.py +130 -26
- warp/builtins.py +1907 -384
- warp/codegen.py +272 -104
- warp/config.py +12 -1
- warp/constants.py +1 -1
- warp/context.py +770 -238
- warp/dlpack.py +1 -1
- warp/examples/benchmarks/benchmark_cloth.py +2 -2
- warp/examples/benchmarks/benchmark_tile_sort.py +155 -0
- warp/examples/core/example_sample_mesh.py +1 -1
- warp/examples/core/example_spin_lock.py +93 -0
- warp/examples/core/example_work_queue.py +118 -0
- warp/examples/fem/example_adaptive_grid.py +5 -5
- warp/examples/fem/example_apic_fluid.py +1 -1
- warp/examples/fem/example_burgers.py +1 -1
- warp/examples/fem/example_convection_diffusion.py +9 -6
- warp/examples/fem/example_darcy_ls_optimization.py +489 -0
- warp/examples/fem/example_deformed_geometry.py +1 -1
- warp/examples/fem/example_diffusion.py +2 -2
- warp/examples/fem/example_diffusion_3d.py +1 -1
- warp/examples/fem/example_distortion_energy.py +1 -1
- warp/examples/fem/example_elastic_shape_optimization.py +387 -0
- warp/examples/fem/example_magnetostatics.py +5 -3
- warp/examples/fem/example_mixed_elasticity.py +5 -3
- warp/examples/fem/example_navier_stokes.py +11 -9
- warp/examples/fem/example_nonconforming_contact.py +5 -3
- warp/examples/fem/example_streamlines.py +8 -3
- warp/examples/fem/utils.py +9 -8
- warp/examples/interop/example_jax_callable.py +34 -4
- warp/examples/interop/example_jax_ffi_callback.py +2 -2
- warp/examples/interop/example_jax_kernel.py +27 -1
- warp/examples/optim/example_drone.py +1 -1
- warp/examples/sim/example_cloth.py +1 -1
- warp/examples/sim/example_cloth_self_contact.py +48 -54
- warp/examples/tile/example_tile_block_cholesky.py +502 -0
- warp/examples/tile/example_tile_cholesky.py +2 -1
- warp/examples/tile/example_tile_convolution.py +1 -1
- warp/examples/tile/example_tile_filtering.py +1 -1
- warp/examples/tile/example_tile_matmul.py +1 -1
- warp/examples/tile/example_tile_mlp.py +2 -0
- warp/fabric.py +7 -7
- warp/fem/__init__.py +5 -0
- warp/fem/adaptivity.py +1 -1
- warp/fem/cache.py +152 -63
- warp/fem/dirichlet.py +2 -2
- warp/fem/domain.py +136 -6
- warp/fem/field/field.py +141 -99
- warp/fem/field/nodal_field.py +85 -39
- warp/fem/field/virtual.py +99 -52
- warp/fem/geometry/adaptive_nanogrid.py +91 -86
- warp/fem/geometry/closest_point.py +13 -0
- warp/fem/geometry/deformed_geometry.py +102 -40
- warp/fem/geometry/element.py +56 -2
- warp/fem/geometry/geometry.py +323 -22
- warp/fem/geometry/grid_2d.py +157 -62
- warp/fem/geometry/grid_3d.py +116 -20
- warp/fem/geometry/hexmesh.py +86 -20
- warp/fem/geometry/nanogrid.py +166 -86
- warp/fem/geometry/partition.py +59 -25
- warp/fem/geometry/quadmesh.py +86 -135
- warp/fem/geometry/tetmesh.py +47 -119
- warp/fem/geometry/trimesh.py +77 -270
- warp/fem/integrate.py +181 -95
- warp/fem/linalg.py +25 -58
- warp/fem/operator.py +124 -27
- warp/fem/quadrature/pic_quadrature.py +36 -14
- warp/fem/quadrature/quadrature.py +40 -16
- warp/fem/space/__init__.py +1 -1
- warp/fem/space/basis_function_space.py +66 -46
- warp/fem/space/basis_space.py +17 -4
- warp/fem/space/dof_mapper.py +1 -1
- warp/fem/space/function_space.py +2 -2
- warp/fem/space/grid_2d_function_space.py +4 -1
- warp/fem/space/hexmesh_function_space.py +4 -2
- warp/fem/space/nanogrid_function_space.py +3 -1
- warp/fem/space/partition.py +11 -2
- warp/fem/space/quadmesh_function_space.py +4 -1
- warp/fem/space/restriction.py +5 -2
- warp/fem/space/shape/__init__.py +10 -8
- warp/fem/space/tetmesh_function_space.py +4 -1
- warp/fem/space/topology.py +52 -21
- warp/fem/space/trimesh_function_space.py +4 -1
- warp/fem/utils.py +53 -8
- warp/jax.py +1 -2
- warp/jax_experimental/ffi.py +210 -67
- warp/jax_experimental/xla_ffi.py +37 -24
- warp/math.py +171 -1
- warp/native/array.h +103 -4
- warp/native/builtin.h +182 -35
- warp/native/coloring.cpp +6 -2
- warp/native/cuda_util.cpp +1 -1
- warp/native/exports.h +118 -63
- warp/native/intersect.h +5 -5
- warp/native/mat.h +8 -13
- warp/native/mathdx.cpp +11 -5
- warp/native/matnn.h +1 -123
- warp/native/mesh.h +1 -1
- warp/native/quat.h +34 -6
- warp/native/rand.h +7 -7
- warp/native/sparse.cpp +121 -258
- warp/native/sparse.cu +181 -274
- warp/native/spatial.h +305 -17
- warp/native/svd.h +23 -8
- warp/native/tile.h +603 -73
- warp/native/tile_radix_sort.h +1112 -0
- warp/native/tile_reduce.h +239 -13
- warp/native/tile_scan.h +240 -0
- warp/native/tuple.h +189 -0
- warp/native/vec.h +10 -20
- warp/native/warp.cpp +36 -4
- warp/native/warp.cu +588 -52
- warp/native/warp.h +47 -74
- warp/optim/linear.py +5 -1
- warp/paddle.py +7 -8
- warp/py.typed +0 -0
- warp/render/render_opengl.py +110 -80
- warp/render/render_usd.py +124 -62
- warp/sim/__init__.py +9 -0
- warp/sim/collide.py +253 -80
- warp/sim/graph_coloring.py +8 -1
- warp/sim/import_mjcf.py +4 -3
- warp/sim/import_usd.py +11 -7
- warp/sim/integrator.py +5 -2
- warp/sim/integrator_euler.py +1 -1
- warp/sim/integrator_featherstone.py +1 -1
- warp/sim/integrator_vbd.py +761 -322
- warp/sim/integrator_xpbd.py +1 -1
- warp/sim/model.py +265 -260
- warp/sim/utils.py +10 -7
- warp/sparse.py +303 -166
- warp/tape.py +54 -51
- warp/tests/cuda/test_conditional_captures.py +1046 -0
- warp/tests/cuda/test_streams.py +1 -1
- warp/tests/geometry/test_volume.py +2 -2
- warp/tests/interop/test_dlpack.py +9 -9
- warp/tests/interop/test_jax.py +0 -1
- warp/tests/run_coverage_serial.py +1 -1
- warp/tests/sim/disabled_kinematics.py +2 -2
- warp/tests/sim/{test_vbd.py → test_cloth.py} +378 -112
- warp/tests/sim/test_collision.py +159 -51
- warp/tests/sim/test_coloring.py +91 -2
- warp/tests/test_array.py +254 -2
- warp/tests/test_array_reduce.py +2 -2
- warp/tests/test_assert.py +53 -0
- warp/tests/test_atomic_cas.py +312 -0
- warp/tests/test_codegen.py +142 -19
- warp/tests/test_conditional.py +47 -1
- warp/tests/test_ctypes.py +0 -20
- warp/tests/test_devices.py +8 -0
- warp/tests/test_fabricarray.py +4 -2
- warp/tests/test_fem.py +58 -25
- warp/tests/test_func.py +42 -1
- warp/tests/test_grad.py +1 -1
- warp/tests/test_lerp.py +1 -3
- warp/tests/test_map.py +481 -0
- warp/tests/test_mat.py +23 -24
- warp/tests/test_quat.py +28 -15
- warp/tests/test_rounding.py +10 -38
- warp/tests/test_runlength_encode.py +7 -7
- warp/tests/test_smoothstep.py +1 -1
- warp/tests/test_sparse.py +83 -2
- warp/tests/test_spatial.py +507 -1
- warp/tests/test_static.py +48 -0
- warp/tests/test_struct.py +2 -2
- warp/tests/test_tape.py +38 -0
- warp/tests/test_tuple.py +265 -0
- warp/tests/test_types.py +2 -2
- warp/tests/test_utils.py +24 -18
- warp/tests/test_vec.py +38 -408
- warp/tests/test_vec_constructors.py +325 -0
- warp/tests/tile/test_tile.py +438 -131
- warp/tests/tile/test_tile_mathdx.py +518 -14
- warp/tests/tile/test_tile_matmul.py +179 -0
- warp/tests/tile/test_tile_reduce.py +307 -5
- warp/tests/tile/test_tile_shared_memory.py +136 -7
- warp/tests/tile/test_tile_sort.py +121 -0
- warp/tests/unittest_suites.py +14 -6
- warp/types.py +462 -308
- warp/utils.py +647 -86
- {warp_lang-1.7.2rc1.dist-info → warp_lang-1.8.1.dist-info}/METADATA +20 -6
- {warp_lang-1.7.2rc1.dist-info → warp_lang-1.8.1.dist-info}/RECORD +190 -176
- warp/stubs.py +0 -3381
- warp/tests/sim/test_xpbd.py +0 -399
- warp/tests/test_mlp.py +0 -282
- {warp_lang-1.7.2rc1.dist-info → warp_lang-1.8.1.dist-info}/WHEEL +0 -0
- {warp_lang-1.7.2rc1.dist-info → warp_lang-1.8.1.dist-info}/licenses/LICENSE.md +0 -0
- {warp_lang-1.7.2rc1.dist-info → warp_lang-1.8.1.dist-info}/top_level.txt +0 -0
warp/tests/test_vec.py
CHANGED
|
@@ -74,111 +74,6 @@ def test_length_mismatch(test, device):
|
|
|
74
74
|
wp.launch(kernel, dim=1, inputs=[], device=device)
|
|
75
75
|
|
|
76
76
|
|
|
77
|
-
def test_anon_constructor_error_length_mismatch(test, device):
|
|
78
|
-
@wp.kernel
|
|
79
|
-
def kernel():
|
|
80
|
-
wp.vector(
|
|
81
|
-
wp.vector(length=2, dtype=float),
|
|
82
|
-
length=3,
|
|
83
|
-
dtype=float,
|
|
84
|
-
)
|
|
85
|
-
|
|
86
|
-
with test.assertRaisesRegex(
|
|
87
|
-
RuntimeError,
|
|
88
|
-
r"incompatible vector of length 3 given when copy constructing a vector of length 2$",
|
|
89
|
-
):
|
|
90
|
-
wp.launch(
|
|
91
|
-
kernel,
|
|
92
|
-
dim=1,
|
|
93
|
-
inputs=[],
|
|
94
|
-
device=device,
|
|
95
|
-
)
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
def test_anon_constructor_error_numeric_arg_missing(test, device):
|
|
99
|
-
@wp.kernel
|
|
100
|
-
def kernel():
|
|
101
|
-
wp.vector(1.0, 2.0, length=12345)
|
|
102
|
-
|
|
103
|
-
with test.assertRaisesRegex(
|
|
104
|
-
RuntimeError,
|
|
105
|
-
r"incompatible number of values given \(2\) when constructing a vector of length 12345$",
|
|
106
|
-
):
|
|
107
|
-
wp.launch(
|
|
108
|
-
kernel,
|
|
109
|
-
dim=1,
|
|
110
|
-
inputs=[],
|
|
111
|
-
device=device,
|
|
112
|
-
)
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
def test_anon_constructor_error_length_arg_missing(test, device):
|
|
116
|
-
@wp.kernel
|
|
117
|
-
def kernel():
|
|
118
|
-
wp.vector()
|
|
119
|
-
|
|
120
|
-
with test.assertRaisesRegex(
|
|
121
|
-
RuntimeError,
|
|
122
|
-
r"the `length` argument must be specified when zero-initializing a vector$",
|
|
123
|
-
):
|
|
124
|
-
wp.launch(
|
|
125
|
-
kernel,
|
|
126
|
-
dim=1,
|
|
127
|
-
inputs=[],
|
|
128
|
-
device=device,
|
|
129
|
-
)
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
def test_anon_constructor_error_numeric_args_mismatch(test, device):
|
|
133
|
-
@wp.kernel
|
|
134
|
-
def kernel():
|
|
135
|
-
wp.vector(1.0, 2)
|
|
136
|
-
|
|
137
|
-
with test.assertRaisesRegex(
|
|
138
|
-
RuntimeError,
|
|
139
|
-
r"all values given when constructing a vector must have the same type$",
|
|
140
|
-
):
|
|
141
|
-
wp.launch(
|
|
142
|
-
kernel,
|
|
143
|
-
dim=1,
|
|
144
|
-
inputs=[],
|
|
145
|
-
device=device,
|
|
146
|
-
)
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
def test_tpl_constructor_error_incompatible_sizes(test, device):
|
|
150
|
-
@wp.kernel
|
|
151
|
-
def kernel():
|
|
152
|
-
wp.vec3(wp.vec2(1.0, 2.0))
|
|
153
|
-
|
|
154
|
-
with test.assertRaisesRegex(
|
|
155
|
-
RuntimeError, "incompatible vector of length 3 given when copy constructing a vector of length 2"
|
|
156
|
-
):
|
|
157
|
-
wp.launch(
|
|
158
|
-
kernel,
|
|
159
|
-
dim=1,
|
|
160
|
-
inputs=[],
|
|
161
|
-
device=device,
|
|
162
|
-
)
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
def test_tpl_constructor_error_numeric_args_mismatch(test, device):
|
|
166
|
-
@wp.kernel
|
|
167
|
-
def kernel():
|
|
168
|
-
wp.vec2(1.0, 2)
|
|
169
|
-
|
|
170
|
-
with test.assertRaisesRegex(
|
|
171
|
-
RuntimeError,
|
|
172
|
-
r"all values given when constructing a vector must have the same type$",
|
|
173
|
-
):
|
|
174
|
-
wp.launch(
|
|
175
|
-
kernel,
|
|
176
|
-
dim=1,
|
|
177
|
-
inputs=[],
|
|
178
|
-
device=device,
|
|
179
|
-
)
|
|
180
|
-
|
|
181
|
-
|
|
182
77
|
def test_negation(test, device, dtype, register_kernels=False):
|
|
183
78
|
rng = np.random.default_rng(123)
|
|
184
79
|
|
|
@@ -312,32 +207,15 @@ def test_subtraction_unsigned(test, device, dtype, register_kernels=False):
|
|
|
312
207
|
def check_subtraction_unsigned():
|
|
313
208
|
wp.expect_eq(vec2(wptype(3), wptype(4)) - vec2(wptype(1), wptype(2)), vec2(wptype(2), wptype(2)))
|
|
314
209
|
wp.expect_eq(
|
|
315
|
-
vec3(
|
|
316
|
-
wptype(3),
|
|
317
|
-
wptype(4),
|
|
318
|
-
wptype(4),
|
|
319
|
-
)
|
|
320
|
-
- vec3(wptype(1), wptype(2), wptype(3)),
|
|
210
|
+
vec3(wptype(3), wptype(4), wptype(4)) - vec3(wptype(1), wptype(2), wptype(3)),
|
|
321
211
|
vec3(wptype(2), wptype(2), wptype(1)),
|
|
322
212
|
)
|
|
323
213
|
wp.expect_eq(
|
|
324
|
-
vec4(
|
|
325
|
-
wptype(3),
|
|
326
|
-
wptype(4),
|
|
327
|
-
wptype(4),
|
|
328
|
-
wptype(5),
|
|
329
|
-
)
|
|
330
|
-
- vec4(wptype(1), wptype(2), wptype(3), wptype(4)),
|
|
214
|
+
vec4(wptype(3), wptype(4), wptype(4), wptype(5)) - vec4(wptype(1), wptype(2), wptype(3), wptype(4)),
|
|
331
215
|
vec4(wptype(2), wptype(2), wptype(1), wptype(1)),
|
|
332
216
|
)
|
|
333
217
|
wp.expect_eq(
|
|
334
|
-
vec5(
|
|
335
|
-
wptype(3),
|
|
336
|
-
wptype(4),
|
|
337
|
-
wptype(4),
|
|
338
|
-
wptype(5),
|
|
339
|
-
wptype(4),
|
|
340
|
-
)
|
|
218
|
+
vec5(wptype(3), wptype(4), wptype(4), wptype(5), wptype(4))
|
|
341
219
|
- vec5(wptype(1), wptype(2), wptype(3), wptype(4), wptype(4)),
|
|
342
220
|
vec5(wptype(2), wptype(2), wptype(1), wptype(1), wptype(0)),
|
|
343
221
|
)
|
|
@@ -445,16 +323,7 @@ def test_subtraction(test, device, dtype, register_kernels=False):
|
|
|
445
323
|
wp.launch(
|
|
446
324
|
kernel,
|
|
447
325
|
dim=1,
|
|
448
|
-
inputs=[
|
|
449
|
-
s2,
|
|
450
|
-
s3,
|
|
451
|
-
s4,
|
|
452
|
-
s5,
|
|
453
|
-
v2,
|
|
454
|
-
v3,
|
|
455
|
-
v4,
|
|
456
|
-
v5,
|
|
457
|
-
],
|
|
326
|
+
inputs=[s2, s3, s4, s5, v2, v3, v4, v5],
|
|
458
327
|
outputs=[v20, v21, v30, v31, v32, v40, v41, v42, v43, v50, v51, v52, v53, v54],
|
|
459
328
|
device=device,
|
|
460
329
|
)
|
|
@@ -557,18 +426,7 @@ def test_length(test, device, dtype, register_kernels=False):
|
|
|
557
426
|
|
|
558
427
|
tape = wp.Tape()
|
|
559
428
|
with tape:
|
|
560
|
-
wp.launch(
|
|
561
|
-
kernel,
|
|
562
|
-
dim=1,
|
|
563
|
-
inputs=[
|
|
564
|
-
v2,
|
|
565
|
-
v3,
|
|
566
|
-
v4,
|
|
567
|
-
v5,
|
|
568
|
-
],
|
|
569
|
-
outputs=[l2, l3, l4, l5, l22, l23, l24, l25],
|
|
570
|
-
device=device,
|
|
571
|
-
)
|
|
429
|
+
wp.launch(kernel, dim=1, inputs=[v2, v3, v4, v5], outputs=[l2, l3, l4, l5, l22, l23, l24, l25], device=device)
|
|
572
430
|
|
|
573
431
|
assert_np_equal(l2.numpy()[0], 2 * np.linalg.norm(v2.numpy()), tol=10 * tol)
|
|
574
432
|
assert_np_equal(l3.numpy()[0], 2 * np.linalg.norm(v3.numpy()), tol=10 * tol)
|
|
@@ -791,18 +649,7 @@ def test_normalize(test, device, dtype, register_kernels=False):
|
|
|
791
649
|
]
|
|
792
650
|
tape0 = wp.Tape()
|
|
793
651
|
with tape0:
|
|
794
|
-
wp.launch(
|
|
795
|
-
normalize_kernel,
|
|
796
|
-
dim=1,
|
|
797
|
-
inputs=[
|
|
798
|
-
v2,
|
|
799
|
-
v3,
|
|
800
|
-
v4,
|
|
801
|
-
v5,
|
|
802
|
-
],
|
|
803
|
-
outputs=outputs0,
|
|
804
|
-
device=device,
|
|
805
|
-
)
|
|
652
|
+
wp.launch(normalize_kernel, dim=1, inputs=[v2, v3, v4, v5], outputs=outputs0, device=device)
|
|
806
653
|
|
|
807
654
|
outputs1 = [
|
|
808
655
|
n20_alt,
|
|
@@ -838,22 +685,7 @@ def test_normalize(test, device, dtype, register_kernels=False):
|
|
|
838
685
|
for ncmp, ncmpalt in zip(outputs0, outputs1):
|
|
839
686
|
assert_np_equal(ncmp.numpy()[0], ncmpalt.numpy()[0], tol=10 * tol)
|
|
840
687
|
|
|
841
|
-
invecs = [
|
|
842
|
-
v2,
|
|
843
|
-
v2,
|
|
844
|
-
v3,
|
|
845
|
-
v3,
|
|
846
|
-
v3,
|
|
847
|
-
v4,
|
|
848
|
-
v4,
|
|
849
|
-
v4,
|
|
850
|
-
v4,
|
|
851
|
-
v5,
|
|
852
|
-
v5,
|
|
853
|
-
v5,
|
|
854
|
-
v5,
|
|
855
|
-
v5,
|
|
856
|
-
]
|
|
688
|
+
invecs = [v2, v2, v3, v3, v3, v4, v4, v4, v4, v5, v5, v5, v5, v5]
|
|
857
689
|
for ncmp, ncmpalt, v in zip(outputs0, outputs1, invecs):
|
|
858
690
|
tape0.backward(loss=ncmp)
|
|
859
691
|
tape1.backward(loss=ncmpalt)
|
|
@@ -957,154 +789,7 @@ def test_crossproduct(test, device, dtype, register_kernels=False):
|
|
|
957
789
|
tape.zero()
|
|
958
790
|
|
|
959
791
|
|
|
960
|
-
|
|
961
|
-
np_type = np.dtype(dtype)
|
|
962
|
-
wp_type = wp.types.np_dtype_to_warp_type[np_type]
|
|
963
|
-
vec3 = wp.types.vector(length=3, dtype=wp_type)
|
|
964
|
-
|
|
965
|
-
np16 = np.dtype(np.float16)
|
|
966
|
-
wp16 = wp.types.np_dtype_to_warp_type[np16]
|
|
967
|
-
|
|
968
|
-
np32 = np.dtype(np.float32)
|
|
969
|
-
wp32 = wp.types.np_dtype_to_warp_type[np32]
|
|
970
|
-
|
|
971
|
-
np64 = np.dtype(np.float64)
|
|
972
|
-
wp64 = wp.types.np_dtype_to_warp_type[np64]
|
|
973
|
-
|
|
974
|
-
def cast_float16(a: wp.array(dtype=wp_type, ndim=2), b: wp.array(dtype=wp16, ndim=2)):
|
|
975
|
-
tid = wp.tid()
|
|
976
|
-
|
|
977
|
-
v1 = vec3(a[tid, 0], a[tid, 1], a[tid, 2])
|
|
978
|
-
v2 = wp.vector(v1, dtype=wp16)
|
|
979
|
-
|
|
980
|
-
b[tid, 0] = v2[0]
|
|
981
|
-
b[tid, 1] = v2[1]
|
|
982
|
-
b[tid, 2] = v2[2]
|
|
983
|
-
|
|
984
|
-
def cast_float32(a: wp.array(dtype=wp_type, ndim=2), b: wp.array(dtype=wp32, ndim=2)):
|
|
985
|
-
tid = wp.tid()
|
|
986
|
-
|
|
987
|
-
v1 = vec3(a[tid, 0], a[tid, 1], a[tid, 2])
|
|
988
|
-
v2 = wp.vector(v1, dtype=wp32)
|
|
989
|
-
|
|
990
|
-
b[tid, 0] = v2[0]
|
|
991
|
-
b[tid, 1] = v2[1]
|
|
992
|
-
b[tid, 2] = v2[2]
|
|
993
|
-
|
|
994
|
-
def cast_float64(a: wp.array(dtype=wp_type, ndim=2), b: wp.array(dtype=wp64, ndim=2)):
|
|
995
|
-
tid = wp.tid()
|
|
996
|
-
|
|
997
|
-
v1 = vec3(a[tid, 0], a[tid, 1], a[tid, 2])
|
|
998
|
-
v2 = wp.vector(v1, dtype=wp64)
|
|
999
|
-
|
|
1000
|
-
b[tid, 0] = v2[0]
|
|
1001
|
-
b[tid, 1] = v2[1]
|
|
1002
|
-
b[tid, 2] = v2[2]
|
|
1003
|
-
|
|
1004
|
-
kernel_16 = getkernel(cast_float16, suffix=dtype.__name__)
|
|
1005
|
-
kernel_32 = getkernel(cast_float32, suffix=dtype.__name__)
|
|
1006
|
-
kernel_64 = getkernel(cast_float64, suffix=dtype.__name__)
|
|
1007
|
-
|
|
1008
|
-
if register_kernels:
|
|
1009
|
-
return
|
|
1010
|
-
|
|
1011
|
-
# check casting to float 16
|
|
1012
|
-
a = wp.array(np.ones((1, 3), dtype=np_type), dtype=wp_type, requires_grad=True, device=device)
|
|
1013
|
-
b = wp.array(np.zeros((1, 3), dtype=np16), dtype=wp16, requires_grad=True, device=device)
|
|
1014
|
-
b_result = np.ones((1, 3), dtype=np16)
|
|
1015
|
-
b_grad = wp.array(np.ones((1, 3), dtype=np16), dtype=wp16, device=device)
|
|
1016
|
-
a_grad = wp.array(np.ones((1, 3), dtype=np_type), dtype=wp_type, device=device)
|
|
1017
|
-
|
|
1018
|
-
tape = wp.Tape()
|
|
1019
|
-
with tape:
|
|
1020
|
-
wp.launch(kernel=kernel_16, dim=1, inputs=[a, b], device=device)
|
|
1021
|
-
|
|
1022
|
-
tape.backward(grads={b: b_grad})
|
|
1023
|
-
out = tape.gradients[a].numpy()
|
|
1024
|
-
|
|
1025
|
-
assert_np_equal(b.numpy(), b_result)
|
|
1026
|
-
assert_np_equal(out, a_grad.numpy())
|
|
1027
|
-
|
|
1028
|
-
# check casting to float 32
|
|
1029
|
-
a = wp.array(np.ones((1, 3), dtype=np_type), dtype=wp_type, requires_grad=True, device=device)
|
|
1030
|
-
b = wp.array(np.zeros((1, 3), dtype=np32), dtype=wp32, requires_grad=True, device=device)
|
|
1031
|
-
b_result = np.ones((1, 3), dtype=np32)
|
|
1032
|
-
b_grad = wp.array(np.ones((1, 3), dtype=np32), dtype=wp32, device=device)
|
|
1033
|
-
a_grad = wp.array(np.ones((1, 3), dtype=np_type), dtype=wp_type, device=device)
|
|
1034
|
-
|
|
1035
|
-
tape = wp.Tape()
|
|
1036
|
-
with tape:
|
|
1037
|
-
wp.launch(kernel=kernel_32, dim=1, inputs=[a, b], device=device)
|
|
1038
|
-
|
|
1039
|
-
tape.backward(grads={b: b_grad})
|
|
1040
|
-
out = tape.gradients[a].numpy()
|
|
1041
|
-
|
|
1042
|
-
assert_np_equal(b.numpy(), b_result)
|
|
1043
|
-
assert_np_equal(out, a_grad.numpy())
|
|
1044
|
-
|
|
1045
|
-
# check casting to float 64
|
|
1046
|
-
a = wp.array(np.ones((1, 3), dtype=np_type), dtype=wp_type, requires_grad=True, device=device)
|
|
1047
|
-
b = wp.array(np.zeros((1, 3), dtype=np64), dtype=wp64, requires_grad=True, device=device)
|
|
1048
|
-
b_result = np.ones((1, 3), dtype=np64)
|
|
1049
|
-
b_grad = wp.array(np.ones((1, 3), dtype=np64), dtype=wp64, device=device)
|
|
1050
|
-
a_grad = wp.array(np.ones((1, 3), dtype=np_type), dtype=wp_type, device=device)
|
|
1051
|
-
|
|
1052
|
-
tape = wp.Tape()
|
|
1053
|
-
with tape:
|
|
1054
|
-
wp.launch(kernel=kernel_64, dim=1, inputs=[a, b], device=device)
|
|
1055
|
-
|
|
1056
|
-
tape.backward(grads={b: b_grad})
|
|
1057
|
-
out = tape.gradients[a].numpy()
|
|
1058
|
-
|
|
1059
|
-
assert_np_equal(b.numpy(), b_result)
|
|
1060
|
-
assert_np_equal(out, a_grad.numpy())
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
@wp.kernel
|
|
1064
|
-
def test_vector_constructor_value_func():
|
|
1065
|
-
a = wp.vec2()
|
|
1066
|
-
b = wp.vector(a, dtype=wp.float16)
|
|
1067
|
-
c = wp.vector(a)
|
|
1068
|
-
d = wp.vector(a, length=2)
|
|
1069
|
-
e = wp.vector(1.0, 2.0, 3.0, dtype=float)
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
# Test matrix constructors using explicit type (float16)
|
|
1073
|
-
# note that these tests are specifically not using generics / closure
|
|
1074
|
-
# args to create kernels dynamically (like the rest of this file)
|
|
1075
|
-
# as those use different code paths to resolve arg types which
|
|
1076
|
-
# has lead to regressions.
|
|
1077
|
-
@wp.kernel
|
|
1078
|
-
def test_constructors_explicit_precision():
|
|
1079
|
-
# construction for custom matrix types
|
|
1080
|
-
ones = wp.vector(wp.float16(1.0), length=2)
|
|
1081
|
-
zeros = wp.vector(length=2, dtype=wp.float16)
|
|
1082
|
-
custom = wp.vector(wp.float16(0.0), wp.float16(1.0))
|
|
1083
|
-
|
|
1084
|
-
for i in range(2):
|
|
1085
|
-
wp.expect_eq(ones[i], wp.float16(1.0))
|
|
1086
|
-
wp.expect_eq(zeros[i], wp.float16(0.0))
|
|
1087
|
-
wp.expect_eq(custom[i], wp.float16(i))
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
# Same as above but with a default (float/int) type
|
|
1091
|
-
# which tests some different code paths that
|
|
1092
|
-
# need to ensure types are correctly canonicalized
|
|
1093
|
-
# during codegen
|
|
1094
|
-
@wp.kernel
|
|
1095
|
-
def test_constructors_default_precision():
|
|
1096
|
-
# construction for custom matrix types
|
|
1097
|
-
ones = wp.vector(1.0, length=2)
|
|
1098
|
-
zeros = wp.vector(length=2, dtype=float)
|
|
1099
|
-
custom = wp.vector(0.0, 1.0)
|
|
1100
|
-
|
|
1101
|
-
for i in range(2):
|
|
1102
|
-
wp.expect_eq(ones[i], 1.0)
|
|
1103
|
-
wp.expect_eq(zeros[i], 0.0)
|
|
1104
|
-
wp.expect_eq(custom[i], float(i))
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
@wp.kernel
|
|
792
|
+
@wp.kernel(module="unique")
|
|
1108
793
|
def test_vector_mutation(expected: wp.types.vector(length=10, dtype=float)):
|
|
1109
794
|
v = wp.vector(length=10, dtype=float)
|
|
1110
795
|
|
|
@@ -1117,30 +802,11 @@ def test_vector_mutation(expected: wp.types.vector(length=10, dtype=float)):
|
|
|
1117
802
|
wp.expect_eq(v, expected)
|
|
1118
803
|
|
|
1119
804
|
|
|
1120
|
-
CONSTANT_LENGTH = wp.constant(10)
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
# tests that we can use global constants in length keyword argument
|
|
1124
|
-
# for vector constructor
|
|
1125
|
-
@wp.kernel
|
|
1126
|
-
def test_constructors_constant_length():
|
|
1127
|
-
v = wp.vector(length=(CONSTANT_LENGTH), dtype=float)
|
|
1128
|
-
|
|
1129
|
-
for i in range(CONSTANT_LENGTH):
|
|
1130
|
-
v[i] = float(i)
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
805
|
Vec123 = wp.vec(123, dtype=wp.float16)
|
|
1134
806
|
|
|
1135
807
|
|
|
1136
|
-
@wp.kernel
|
|
1137
|
-
def vector_len_kernel(
|
|
1138
|
-
v1: wp.vec2,
|
|
1139
|
-
v2: wp.vec(3, float),
|
|
1140
|
-
v3: wp.vec(Any, float),
|
|
1141
|
-
v4: Vec123,
|
|
1142
|
-
out: wp.array(dtype=int),
|
|
1143
|
-
):
|
|
808
|
+
@wp.kernel(module="unique")
|
|
809
|
+
def vector_len_kernel(v1: wp.vec2, v2: wp.vec(3, float), v3: wp.vec(Any, float), v4: Vec123, out: wp.array(dtype=int)):
|
|
1144
810
|
length = wp.static(len(v1))
|
|
1145
811
|
wp.expect_eq(len(v1), 2)
|
|
1146
812
|
out[0] = len(v1)
|
|
@@ -1261,7 +927,7 @@ def test_vec_assign_copy(test, device):
|
|
|
1261
927
|
try:
|
|
1262
928
|
wp.config.enable_vector_component_overwrites = True
|
|
1263
929
|
|
|
1264
|
-
@wp.kernel
|
|
930
|
+
@wp.kernel(module="unique")
|
|
1265
931
|
def vec_assign_overwrite(x: wp.array(dtype=wp.vec3), y: wp.array(dtype=wp.vec3)):
|
|
1266
932
|
tid = wp.tid()
|
|
1267
933
|
|
|
@@ -1364,7 +1030,7 @@ def test_vec_array_assign(test, device):
|
|
|
1364
1030
|
run(vec_array_assign_attribute)
|
|
1365
1031
|
|
|
1366
1032
|
|
|
1367
|
-
@wp.kernel
|
|
1033
|
+
@wp.kernel(module="unique")
|
|
1368
1034
|
def vec_add_inplace_subscript(x: wp.array(dtype=wp.vec3), y: wp.array(dtype=wp.vec3)):
|
|
1369
1035
|
i = wp.tid()
|
|
1370
1036
|
|
|
@@ -1378,7 +1044,7 @@ def vec_add_inplace_subscript(x: wp.array(dtype=wp.vec3), y: wp.array(dtype=wp.v
|
|
|
1378
1044
|
y[i] = a
|
|
1379
1045
|
|
|
1380
1046
|
|
|
1381
|
-
@wp.kernel
|
|
1047
|
+
@wp.kernel(module="unique")
|
|
1382
1048
|
def vec_add_inplace_attribute(x: wp.array(dtype=wp.vec3), y: wp.array(dtype=wp.vec3)):
|
|
1383
1049
|
i = wp.tid()
|
|
1384
1050
|
|
|
@@ -1458,7 +1124,7 @@ def test_vec_sub_inplace(test, device):
|
|
|
1458
1124
|
run(vec_sub_inplace_attribute)
|
|
1459
1125
|
|
|
1460
1126
|
|
|
1461
|
-
@wp.kernel
|
|
1127
|
+
@wp.kernel(module="unique")
|
|
1462
1128
|
def vec_array_add_inplace(x: wp.array(dtype=wp.vec3), y: wp.array(dtype=wp.vec3)):
|
|
1463
1129
|
i = wp.tid()
|
|
1464
1130
|
|
|
@@ -1502,6 +1168,27 @@ def test_vec_array_sub_inplace(test, device):
|
|
|
1502
1168
|
assert_np_equal(x.grad.numpy(), np.array([[-1.0, -1.0, -1.0]], dtype=float))
|
|
1503
1169
|
|
|
1504
1170
|
|
|
1171
|
+
@wp.kernel
|
|
1172
|
+
def scalar_vec_div(x: wp.array(dtype=wp.vec3), y: wp.array(dtype=wp.vec3)):
|
|
1173
|
+
i = wp.tid()
|
|
1174
|
+
y[i] = 1.0 / x[i]
|
|
1175
|
+
|
|
1176
|
+
|
|
1177
|
+
def test_scalar_vec_div(test, device):
|
|
1178
|
+
x = wp.array((wp.vec3(1.0, 2.0, 4.0),), dtype=wp.vec3, requires_grad=True, device=device)
|
|
1179
|
+
y = wp.ones(1, dtype=wp.vec3, requires_grad=True, device=device)
|
|
1180
|
+
|
|
1181
|
+
tape = wp.Tape()
|
|
1182
|
+
with tape:
|
|
1183
|
+
wp.launch(scalar_vec_div, 1, inputs=(x,), outputs=(y,), device=device)
|
|
1184
|
+
|
|
1185
|
+
y.grad = wp.ones_like(y)
|
|
1186
|
+
tape.backward()
|
|
1187
|
+
|
|
1188
|
+
assert_np_equal(y.numpy(), np.array(((1.0, 0.5, 0.25),), dtype=float))
|
|
1189
|
+
assert_np_equal(x.grad.numpy(), np.array(((-1.0, -0.25, -0.0625),), dtype=float))
|
|
1190
|
+
|
|
1191
|
+
|
|
1505
1192
|
devices = get_test_devices()
|
|
1506
1193
|
|
|
1507
1194
|
|
|
@@ -1520,11 +1207,6 @@ class TestVec(unittest.TestCase):
|
|
|
1520
1207
|
self.assertSequenceEqual(v, (0, 1, 2))
|
|
1521
1208
|
|
|
1522
1209
|
|
|
1523
|
-
add_kernel_test(TestVec, test_vector_constructor_value_func, dim=1, devices=devices)
|
|
1524
|
-
add_kernel_test(TestVec, test_constructors_explicit_precision, dim=1, devices=devices)
|
|
1525
|
-
add_kernel_test(TestVec, test_constructors_default_precision, dim=1, devices=devices)
|
|
1526
|
-
add_kernel_test(TestVec, test_constructors_constant_length, dim=1, devices=devices)
|
|
1527
|
-
|
|
1528
1210
|
vec10 = wp.types.vector(length=10, dtype=float)
|
|
1529
1211
|
add_kernel_test(
|
|
1530
1212
|
TestVec,
|
|
@@ -1561,62 +1243,9 @@ for dtype in np_float_types:
|
|
|
1561
1243
|
add_function_test_register_kernel(
|
|
1562
1244
|
TestVec, f"test_normalize_{dtype.__name__}", test_normalize, devices=devices, dtype=dtype
|
|
1563
1245
|
)
|
|
1564
|
-
add_function_test_register_kernel(
|
|
1565
|
-
TestVec,
|
|
1566
|
-
f"test_casting_constructors_{dtype.__name__}",
|
|
1567
|
-
test_casting_constructors,
|
|
1568
|
-
devices=devices,
|
|
1569
|
-
dtype=dtype,
|
|
1570
|
-
)
|
|
1571
1246
|
|
|
1572
|
-
add_function_test(
|
|
1573
|
-
|
|
1574
|
-
"test_length_mismatch",
|
|
1575
|
-
test_length_mismatch,
|
|
1576
|
-
devices=devices,
|
|
1577
|
-
)
|
|
1578
|
-
add_function_test(
|
|
1579
|
-
TestVec,
|
|
1580
|
-
"test_anon_constructor_error_length_mismatch",
|
|
1581
|
-
test_anon_constructor_error_length_mismatch,
|
|
1582
|
-
devices=devices,
|
|
1583
|
-
)
|
|
1584
|
-
add_function_test(
|
|
1585
|
-
TestVec,
|
|
1586
|
-
"test_anon_constructor_error_numeric_arg_missing",
|
|
1587
|
-
test_anon_constructor_error_numeric_arg_missing,
|
|
1588
|
-
devices=devices,
|
|
1589
|
-
)
|
|
1590
|
-
add_function_test(
|
|
1591
|
-
TestVec,
|
|
1592
|
-
"test_anon_constructor_error_length_arg_missing",
|
|
1593
|
-
test_anon_constructor_error_length_arg_missing,
|
|
1594
|
-
devices=devices,
|
|
1595
|
-
)
|
|
1596
|
-
add_function_test(
|
|
1597
|
-
TestVec,
|
|
1598
|
-
"test_anon_constructor_error_numeric_args_mismatch",
|
|
1599
|
-
test_anon_constructor_error_numeric_args_mismatch,
|
|
1600
|
-
devices=devices,
|
|
1601
|
-
)
|
|
1602
|
-
add_function_test(
|
|
1603
|
-
TestVec,
|
|
1604
|
-
"test_tpl_constructor_error_incompatible_sizes",
|
|
1605
|
-
test_tpl_constructor_error_incompatible_sizes,
|
|
1606
|
-
devices=devices,
|
|
1607
|
-
)
|
|
1608
|
-
add_function_test(
|
|
1609
|
-
TestVec,
|
|
1610
|
-
"test_tpl_constructor_error_numeric_args_mismatch",
|
|
1611
|
-
test_tpl_constructor_error_numeric_args_mismatch,
|
|
1612
|
-
devices=devices,
|
|
1613
|
-
)
|
|
1614
|
-
add_function_test(
|
|
1615
|
-
TestVec,
|
|
1616
|
-
"test_vector_len",
|
|
1617
|
-
test_vector_len,
|
|
1618
|
-
devices=devices,
|
|
1619
|
-
)
|
|
1247
|
+
add_function_test(TestVec, "test_length_mismatch", test_length_mismatch, devices=devices)
|
|
1248
|
+
add_function_test(TestVec, "test_vector_len", test_vector_len, devices=devices)
|
|
1620
1249
|
add_function_test(TestVec, "test_vec_extract", test_vec_extract, devices=devices)
|
|
1621
1250
|
add_function_test(TestVec, "test_vec_assign", test_vec_assign, devices=devices)
|
|
1622
1251
|
add_function_test(TestVec, "test_vec_assign_copy", test_vec_assign_copy, devices=devices)
|
|
@@ -1626,6 +1255,7 @@ add_function_test(TestVec, "test_vec_add_inplace", test_vec_add_inplace, devices
|
|
|
1626
1255
|
add_function_test(TestVec, "test_vec_sub_inplace", test_vec_sub_inplace, devices=devices)
|
|
1627
1256
|
add_function_test(TestVec, "test_vec_array_add_inplace", test_vec_array_add_inplace, devices=devices)
|
|
1628
1257
|
add_function_test(TestVec, "test_vec_array_sub_inplace", test_vec_array_sub_inplace, devices=devices)
|
|
1258
|
+
add_function_test(TestVec, "test_scalar_vec_div", test_scalar_vec_div, devices=devices)
|
|
1629
1259
|
|
|
1630
1260
|
|
|
1631
1261
|
if __name__ == "__main__":
|