warp-lang 1.6.2__py3-none-macosx_10_13_universal2.whl → 1.7.1__py3-none-macosx_10_13_universal2.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 +7 -1
- warp/autograd.py +12 -2
- warp/bin/libwarp-clang.dylib +0 -0
- warp/bin/libwarp.dylib +0 -0
- warp/build.py +410 -0
- warp/build_dll.py +6 -14
- warp/builtins.py +463 -372
- warp/codegen.py +196 -124
- warp/config.py +42 -6
- warp/context.py +496 -271
- warp/dlpack.py +8 -6
- warp/examples/assets/nonuniform.usd +0 -0
- warp/examples/assets/nvidia_logo.png +0 -0
- warp/examples/benchmarks/benchmark_cloth.py +1 -1
- warp/examples/benchmarks/benchmark_tile_load_store.py +103 -0
- warp/examples/core/example_sample_mesh.py +300 -0
- warp/examples/distributed/example_jacobi_mpi.py +507 -0
- warp/examples/fem/example_apic_fluid.py +1 -1
- warp/examples/fem/example_burgers.py +2 -2
- warp/examples/fem/example_deformed_geometry.py +1 -1
- warp/examples/fem/example_distortion_energy.py +1 -1
- warp/examples/fem/example_magnetostatics.py +6 -6
- warp/examples/fem/utils.py +9 -3
- warp/examples/interop/example_jax_callable.py +116 -0
- warp/examples/interop/example_jax_ffi_callback.py +132 -0
- warp/examples/interop/example_jax_kernel.py +205 -0
- warp/examples/optim/example_fluid_checkpoint.py +497 -0
- warp/examples/tile/example_tile_matmul.py +2 -4
- warp/fem/__init__.py +11 -1
- warp/fem/adaptivity.py +4 -4
- warp/fem/field/field.py +11 -1
- warp/fem/field/nodal_field.py +56 -88
- warp/fem/field/virtual.py +62 -23
- warp/fem/geometry/adaptive_nanogrid.py +16 -13
- warp/fem/geometry/closest_point.py +1 -1
- warp/fem/geometry/deformed_geometry.py +5 -2
- warp/fem/geometry/geometry.py +5 -0
- warp/fem/geometry/grid_2d.py +12 -12
- warp/fem/geometry/grid_3d.py +12 -15
- warp/fem/geometry/hexmesh.py +5 -7
- warp/fem/geometry/nanogrid.py +9 -11
- warp/fem/geometry/quadmesh.py +13 -13
- warp/fem/geometry/tetmesh.py +3 -4
- warp/fem/geometry/trimesh.py +7 -20
- warp/fem/integrate.py +262 -93
- warp/fem/linalg.py +5 -5
- warp/fem/quadrature/pic_quadrature.py +37 -22
- warp/fem/quadrature/quadrature.py +194 -25
- warp/fem/space/__init__.py +1 -1
- warp/fem/space/basis_function_space.py +4 -2
- warp/fem/space/basis_space.py +25 -18
- warp/fem/space/hexmesh_function_space.py +2 -2
- warp/fem/space/partition.py +6 -2
- warp/fem/space/quadmesh_function_space.py +8 -8
- warp/fem/space/shape/cube_shape_function.py +23 -23
- warp/fem/space/shape/square_shape_function.py +12 -12
- warp/fem/space/shape/triangle_shape_function.py +1 -1
- warp/fem/space/tetmesh_function_space.py +3 -3
- warp/fem/space/trimesh_function_space.py +2 -2
- warp/fem/utils.py +12 -6
- warp/jax.py +14 -1
- warp/jax_experimental/__init__.py +16 -0
- warp/{jax_experimental.py → jax_experimental/custom_call.py} +28 -29
- warp/jax_experimental/ffi.py +702 -0
- warp/jax_experimental/xla_ffi.py +602 -0
- warp/math.py +89 -0
- warp/native/array.h +13 -0
- warp/native/builtin.h +29 -3
- warp/native/bvh.cpp +3 -1
- warp/native/bvh.cu +42 -14
- warp/native/bvh.h +2 -1
- warp/native/clang/clang.cpp +30 -3
- warp/native/cuda_util.cpp +14 -0
- warp/native/cuda_util.h +2 -0
- warp/native/exports.h +68 -63
- warp/native/intersect.h +26 -26
- warp/native/intersect_adj.h +33 -33
- warp/native/marching.cu +1 -1
- warp/native/mat.h +513 -9
- warp/native/mesh.h +10 -10
- warp/native/quat.h +99 -11
- warp/native/rand.h +6 -0
- warp/native/sort.cpp +122 -59
- warp/native/sort.cu +152 -15
- warp/native/sort.h +8 -1
- warp/native/sparse.cpp +43 -22
- warp/native/sparse.cu +52 -17
- warp/native/svd.h +116 -0
- warp/native/tile.h +312 -116
- warp/native/tile_reduce.h +46 -3
- warp/native/vec.h +68 -7
- warp/native/volume.cpp +85 -113
- warp/native/volume_builder.cu +25 -10
- warp/native/volume_builder.h +6 -0
- warp/native/warp.cpp +5 -6
- warp/native/warp.cu +100 -11
- warp/native/warp.h +19 -10
- warp/optim/linear.py +10 -10
- warp/render/render_opengl.py +19 -17
- warp/render/render_usd.py +93 -3
- warp/sim/articulation.py +4 -4
- warp/sim/collide.py +32 -19
- warp/sim/import_mjcf.py +449 -155
- warp/sim/import_urdf.py +32 -12
- warp/sim/inertia.py +189 -156
- warp/sim/integrator_euler.py +8 -5
- warp/sim/integrator_featherstone.py +3 -10
- warp/sim/integrator_vbd.py +207 -2
- warp/sim/integrator_xpbd.py +8 -5
- warp/sim/model.py +71 -25
- warp/sim/render.py +4 -0
- warp/sim/utils.py +2 -2
- warp/sparse.py +642 -555
- warp/stubs.py +217 -20
- warp/tests/__main__.py +0 -15
- warp/tests/assets/torus.usda +1 -1
- warp/tests/cuda/__init__.py +0 -0
- warp/tests/{test_mempool.py → cuda/test_mempool.py} +39 -0
- warp/tests/{test_streams.py → cuda/test_streams.py} +71 -0
- warp/tests/geometry/__init__.py +0 -0
- warp/tests/{test_mesh_query_point.py → geometry/test_mesh_query_point.py} +66 -63
- warp/tests/{test_mesh_query_ray.py → geometry/test_mesh_query_ray.py} +1 -1
- warp/tests/{test_volume.py → geometry/test_volume.py} +41 -6
- warp/tests/interop/__init__.py +0 -0
- warp/tests/{test_dlpack.py → interop/test_dlpack.py} +28 -5
- warp/tests/sim/__init__.py +0 -0
- warp/tests/{disabled_kinematics.py → sim/disabled_kinematics.py} +9 -10
- warp/tests/{test_collision.py → sim/test_collision.py} +236 -205
- warp/tests/sim/test_inertia.py +161 -0
- warp/tests/{test_model.py → sim/test_model.py} +40 -0
- warp/tests/{flaky_test_sim_grad.py → sim/test_sim_grad.py} +4 -0
- warp/tests/{test_sim_kinematics.py → sim/test_sim_kinematics.py} +2 -1
- warp/tests/sim/test_vbd.py +597 -0
- warp/tests/sim/test_xpbd.py +399 -0
- warp/tests/test_bool.py +1 -1
- warp/tests/test_codegen.py +24 -3
- warp/tests/test_examples.py +40 -38
- warp/tests/test_fem.py +98 -14
- warp/tests/test_linear_solvers.py +0 -11
- warp/tests/test_mat.py +577 -156
- warp/tests/test_mat_scalar_ops.py +4 -4
- warp/tests/test_overwrite.py +0 -60
- warp/tests/test_quat.py +356 -151
- warp/tests/test_rand.py +44 -37
- warp/tests/test_sparse.py +47 -6
- warp/tests/test_spatial.py +75 -0
- warp/tests/test_static.py +1 -1
- warp/tests/test_utils.py +84 -4
- warp/tests/test_vec.py +336 -178
- warp/tests/tile/__init__.py +0 -0
- warp/tests/{test_tile.py → tile/test_tile.py} +136 -51
- warp/tests/{test_tile_load.py → tile/test_tile_load.py} +98 -1
- warp/tests/{test_tile_mathdx.py → tile/test_tile_mathdx.py} +9 -6
- warp/tests/{test_tile_mlp.py → tile/test_tile_mlp.py} +25 -14
- warp/tests/{test_tile_reduce.py → tile/test_tile_reduce.py} +60 -1
- warp/tests/{test_tile_view.py → tile/test_tile_view.py} +1 -1
- warp/tests/unittest_serial.py +1 -0
- warp/tests/unittest_suites.py +45 -62
- warp/tests/unittest_utils.py +2 -1
- warp/thirdparty/unittest_parallel.py +3 -1
- warp/types.py +175 -666
- warp/utils.py +137 -72
- {warp_lang-1.6.2.dist-info → warp_lang-1.7.1.dist-info}/METADATA +46 -12
- {warp_lang-1.6.2.dist-info → warp_lang-1.7.1.dist-info}/RECORD +184 -171
- {warp_lang-1.6.2.dist-info → warp_lang-1.7.1.dist-info}/WHEEL +1 -1
- {warp_lang-1.6.2.dist-info → warp_lang-1.7.1.dist-info/licenses}/LICENSE.md +0 -26
- warp/examples/optim/example_walker.py +0 -317
- warp/native/cutlass_gemm.cpp +0 -43
- warp/native/cutlass_gemm.cu +0 -382
- warp/tests/test_matmul.py +0 -511
- warp/tests/test_matmul_lite.py +0 -411
- warp/tests/test_vbd.py +0 -386
- warp/tests/unused_test_misc.py +0 -77
- /warp/tests/{test_async.py → cuda/test_async.py} +0 -0
- /warp/tests/{test_ipc.py → cuda/test_ipc.py} +0 -0
- /warp/tests/{test_multigpu.py → cuda/test_multigpu.py} +0 -0
- /warp/tests/{test_peer.py → cuda/test_peer.py} +0 -0
- /warp/tests/{test_pinned.py → cuda/test_pinned.py} +0 -0
- /warp/tests/{test_bvh.py → geometry/test_bvh.py} +0 -0
- /warp/tests/{test_hash_grid.py → geometry/test_hash_grid.py} +0 -0
- /warp/tests/{test_marching_cubes.py → geometry/test_marching_cubes.py} +0 -0
- /warp/tests/{test_mesh.py → geometry/test_mesh.py} +0 -0
- /warp/tests/{test_mesh_query_aabb.py → geometry/test_mesh_query_aabb.py} +0 -0
- /warp/tests/{test_volume_write.py → geometry/test_volume_write.py} +0 -0
- /warp/tests/{test_jax.py → interop/test_jax.py} +0 -0
- /warp/tests/{test_paddle.py → interop/test_paddle.py} +0 -0
- /warp/tests/{test_torch.py → interop/test_torch.py} +0 -0
- /warp/tests/{test_coloring.py → sim/test_coloring.py} +0 -0
- /warp/tests/{test_sim_grad_bounce_linear.py → sim/test_sim_grad_bounce_linear.py} +0 -0
- /warp/tests/{test_tile_shared_memory.py → tile/test_tile_shared_memory.py} +0 -0
- {warp_lang-1.6.2.dist-info → warp_lang-1.7.1.dist-info}/top_level.txt +0 -0
warp/tests/test_vec.py
CHANGED
|
@@ -58,6 +58,22 @@ def getkernel(func, suffix=""):
|
|
|
58
58
|
return kernel_cache[key]
|
|
59
59
|
|
|
60
60
|
|
|
61
|
+
def test_length_mismatch(test, device):
|
|
62
|
+
test.assertNotEqual(wp.vec3f(0.0, 0.0, 0.0), wp.vec2f(0.0, 0.0))
|
|
63
|
+
test.assertNotEqual(wp.vec2f(0.0, 0.0), wp.vec3f(0.0, 0.0, 0.0))
|
|
64
|
+
|
|
65
|
+
@wp.kernel
|
|
66
|
+
def kernel():
|
|
67
|
+
wp.expect_neq(wp.vec3f(0.0, 0.0, 0.0), wp.vec2f(0.0, 0.0))
|
|
68
|
+
wp.expect_neq(wp.vec2f(0.0, 0.0), wp.vec3f(0.0, 0.0, 0.0))
|
|
69
|
+
|
|
70
|
+
with test.assertRaisesRegex(
|
|
71
|
+
RuntimeError,
|
|
72
|
+
r"Can't test equality for objects with different types$",
|
|
73
|
+
):
|
|
74
|
+
wp.launch(kernel, dim=1, inputs=[], device=device)
|
|
75
|
+
|
|
76
|
+
|
|
61
77
|
def test_anon_constructor_error_length_mismatch(test, device):
|
|
62
78
|
@wp.kernel
|
|
63
79
|
def kernel():
|
|
@@ -1044,148 +1060,13 @@ def test_casting_constructors(test, device, dtype, register_kernels=False):
|
|
|
1044
1060
|
assert_np_equal(out, a_grad.numpy())
|
|
1045
1061
|
|
|
1046
1062
|
|
|
1047
|
-
def test_vec_assign(test, device, dtype, register_kernels=False):
|
|
1048
|
-
np_type = np.dtype(dtype)
|
|
1049
|
-
wp_type = wp.types.np_dtype_to_warp_type[np_type]
|
|
1050
|
-
|
|
1051
|
-
vec2 = wp.types.vector(length=2, dtype=wp_type)
|
|
1052
|
-
vec3 = wp.types.vector(length=3, dtype=wp_type)
|
|
1053
|
-
vec4 = wp.types.vector(length=4, dtype=wp_type)
|
|
1054
|
-
|
|
1055
|
-
def vectest_read_write_store(
|
|
1056
|
-
x: wp.array(dtype=wp_type), a: wp.array(dtype=vec2), b: wp.array(dtype=vec3), c: wp.array(dtype=vec4)
|
|
1057
|
-
):
|
|
1058
|
-
tid = wp.tid()
|
|
1059
|
-
|
|
1060
|
-
t = a[tid]
|
|
1061
|
-
t[0] = x[tid]
|
|
1062
|
-
a[tid] = t
|
|
1063
|
-
|
|
1064
|
-
u = b[tid]
|
|
1065
|
-
u[1] = x[tid]
|
|
1066
|
-
b[tid] = u
|
|
1067
|
-
|
|
1068
|
-
v = c[tid]
|
|
1069
|
-
v[2] = x[tid]
|
|
1070
|
-
c[tid] = v
|
|
1071
|
-
|
|
1072
|
-
def vectest_in_register(
|
|
1073
|
-
x: wp.array(dtype=wp_type), y: wp.array(dtype=vec3), a: wp.array(dtype=vec2), b: wp.array(dtype=vec3)
|
|
1074
|
-
):
|
|
1075
|
-
tid = wp.tid()
|
|
1076
|
-
|
|
1077
|
-
f = vec3(wp_type(0.0))
|
|
1078
|
-
b_vec = b[tid]
|
|
1079
|
-
f[0] = b_vec[1]
|
|
1080
|
-
f[2] = b_vec[0] * b_vec[1]
|
|
1081
|
-
y[tid] = f
|
|
1082
|
-
|
|
1083
|
-
g = wp_type(0.0)
|
|
1084
|
-
a_vec = a[tid]
|
|
1085
|
-
g = a_vec[0] + a_vec[1]
|
|
1086
|
-
x[tid] = g
|
|
1087
|
-
|
|
1088
|
-
def vectest_in_register_overwrite(x: wp.array(dtype=vec3), a: wp.array(dtype=vec3)):
|
|
1089
|
-
tid = wp.tid()
|
|
1090
|
-
|
|
1091
|
-
f = vec3(wp_type(0.0))
|
|
1092
|
-
a_vec = a[tid]
|
|
1093
|
-
f = a_vec
|
|
1094
|
-
f[1] = wp_type(3.0)
|
|
1095
|
-
|
|
1096
|
-
x[tid] = f
|
|
1097
|
-
|
|
1098
|
-
def vectest_component(x: wp.array(dtype=vec3), y: wp.array(dtype=wp_type)):
|
|
1099
|
-
i = wp.tid()
|
|
1100
|
-
|
|
1101
|
-
a = vec3(wp_type(0.0))
|
|
1102
|
-
a.x = wp_type(1.0) * y[i]
|
|
1103
|
-
a.y = wp_type(2.0) * y[i]
|
|
1104
|
-
a.z = wp_type(3.0) * y[i]
|
|
1105
|
-
x[i] = a
|
|
1106
|
-
|
|
1107
|
-
kernel_read_write_store = getkernel(vectest_read_write_store, suffix=dtype.__name__)
|
|
1108
|
-
kernel_in_register = getkernel(vectest_in_register, suffix=dtype.__name__)
|
|
1109
|
-
kernel_in_register_overwrite = getkernel(vectest_in_register_overwrite, suffix=dtype.__name__)
|
|
1110
|
-
kernel_component = getkernel(vectest_component, suffix=dtype.__name__)
|
|
1111
|
-
|
|
1112
|
-
if register_kernels:
|
|
1113
|
-
return
|
|
1114
|
-
|
|
1115
|
-
a = wp.ones(1, dtype=vec2, device=device, requires_grad=True)
|
|
1116
|
-
b = wp.ones(1, dtype=vec3, device=device, requires_grad=True)
|
|
1117
|
-
c = wp.ones(1, dtype=vec4, device=device, requires_grad=True)
|
|
1118
|
-
x = wp.full(1, value=2.0, dtype=wp_type, device=device, requires_grad=True)
|
|
1119
|
-
|
|
1120
|
-
tape = wp.Tape()
|
|
1121
|
-
with tape:
|
|
1122
|
-
wp.launch(kernel_read_write_store, dim=1, inputs=[x, a, b, c], device=device)
|
|
1123
|
-
|
|
1124
|
-
tape.backward(
|
|
1125
|
-
grads={
|
|
1126
|
-
a: wp.ones_like(a, requires_grad=False),
|
|
1127
|
-
b: wp.ones_like(b, requires_grad=False),
|
|
1128
|
-
c: wp.ones_like(c, requires_grad=False),
|
|
1129
|
-
}
|
|
1130
|
-
)
|
|
1131
|
-
|
|
1132
|
-
assert_np_equal(a.numpy(), np.array([[2.0, 1.0]], dtype=np_type))
|
|
1133
|
-
assert_np_equal(b.numpy(), np.array([[1.0, 2.0, 1.0]], dtype=np_type))
|
|
1134
|
-
assert_np_equal(c.numpy(), np.array([[1.0, 1.0, 2.0, 1.0]], dtype=np_type))
|
|
1135
|
-
assert_np_equal(x.grad.numpy(), np.array([3.0], dtype=np_type))
|
|
1136
|
-
|
|
1137
|
-
tape.reset()
|
|
1138
|
-
|
|
1139
|
-
a = wp.ones(1, dtype=vec2, device=device, requires_grad=True)
|
|
1140
|
-
b = wp.ones(1, dtype=vec3, device=device, requires_grad=True)
|
|
1141
|
-
x = wp.zeros(1, dtype=wp_type, device=device, requires_grad=True)
|
|
1142
|
-
y = wp.zeros(1, dtype=vec3, device=device, requires_grad=True)
|
|
1143
|
-
|
|
1144
|
-
with tape:
|
|
1145
|
-
wp.launch(kernel_in_register, dim=1, inputs=[x, y, a, b], device=device)
|
|
1146
|
-
|
|
1147
|
-
tape.backward(grads={x: wp.ones_like(x, requires_grad=False), y: wp.ones_like(y, requires_grad=False)})
|
|
1148
|
-
|
|
1149
|
-
assert_np_equal(x.numpy(), np.array([2.0], dtype=np_type))
|
|
1150
|
-
assert_np_equal(y.numpy(), np.array([[1.0, 0.0, 1.0]], dtype=np_type))
|
|
1151
|
-
assert_np_equal(a.grad.numpy(), np.array([[1.0, 1.0]], dtype=np_type))
|
|
1152
|
-
assert_np_equal(b.grad.numpy(), np.array([[1.0, 2.0, 0.0]], dtype=np_type))
|
|
1153
|
-
|
|
1154
|
-
tape.reset()
|
|
1155
|
-
|
|
1156
|
-
x = wp.zeros(1, dtype=vec3, device=device, requires_grad=True)
|
|
1157
|
-
y = wp.ones(1, dtype=wp_type, device=device, requires_grad=True)
|
|
1158
|
-
|
|
1159
|
-
tape = wp.Tape()
|
|
1160
|
-
with tape:
|
|
1161
|
-
wp.launch(kernel_component, dim=1, inputs=[x, y], device=device)
|
|
1162
|
-
|
|
1163
|
-
tape.backward(grads={x: wp.ones_like(x, requires_grad=False)})
|
|
1164
|
-
|
|
1165
|
-
assert_np_equal(x.numpy(), np.array([[1.0, 2.0, 3.0]], dtype=np_type))
|
|
1166
|
-
assert_np_equal(y.grad.numpy(), np.array([6.0], dtype=np_type))
|
|
1167
|
-
|
|
1168
|
-
tape.reset()
|
|
1169
|
-
|
|
1170
|
-
x = wp.zeros(1, dtype=vec3, device=device, requires_grad=True)
|
|
1171
|
-
a = wp.ones(1, dtype=vec3, device=device, requires_grad=True)
|
|
1172
|
-
|
|
1173
|
-
tape = wp.Tape()
|
|
1174
|
-
with tape:
|
|
1175
|
-
wp.launch(kernel_in_register_overwrite, dim=1, inputs=[x, a], device=device)
|
|
1176
|
-
|
|
1177
|
-
tape.backward(grads={x: wp.ones_like(x, requires_grad=False)})
|
|
1178
|
-
|
|
1179
|
-
assert_np_equal(x.numpy(), np.array([[1.0, 3.0, 1.0]], dtype=np_type))
|
|
1180
|
-
assert_np_equal(a.grad.numpy(), np.array([[1.0, 0.0, 1.0]], dtype=np_type))
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
1063
|
@wp.kernel
|
|
1184
1064
|
def test_vector_constructor_value_func():
|
|
1185
1065
|
a = wp.vec2()
|
|
1186
1066
|
b = wp.vector(a, dtype=wp.float16)
|
|
1187
1067
|
c = wp.vector(a)
|
|
1188
1068
|
d = wp.vector(a, length=2)
|
|
1069
|
+
e = wp.vector(1.0, 2.0, 3.0, dtype=float)
|
|
1189
1070
|
|
|
1190
1071
|
|
|
1191
1072
|
# Test matrix constructors using explicit type (float16)
|
|
@@ -1298,52 +1179,327 @@ def test_vector_len(test, device):
|
|
|
1298
1179
|
|
|
1299
1180
|
|
|
1300
1181
|
@wp.kernel
|
|
1301
|
-
def
|
|
1302
|
-
|
|
1303
|
-
|
|
1182
|
+
def vec_extract_subscript(x: wp.array(dtype=wp.vec3), y: wp.array(dtype=float)):
|
|
1183
|
+
tid = wp.tid()
|
|
1184
|
+
|
|
1185
|
+
a = x[tid]
|
|
1186
|
+
b = a[0] + 2.0 * a[1] + 3.0 * a[2]
|
|
1187
|
+
y[tid] = b
|
|
1188
|
+
|
|
1189
|
+
|
|
1190
|
+
@wp.kernel
|
|
1191
|
+
def vec_extract_attribute(x: wp.array(dtype=wp.vec3), y: wp.array(dtype=float)):
|
|
1192
|
+
tid = wp.tid()
|
|
1193
|
+
|
|
1194
|
+
a = x[tid]
|
|
1195
|
+
b = a.x + float(2.0) * a.y + 3.0 * a.z
|
|
1196
|
+
y[tid] = b
|
|
1197
|
+
|
|
1198
|
+
|
|
1199
|
+
def test_vec_extract(test, device):
|
|
1200
|
+
def run(kernel):
|
|
1201
|
+
x = wp.ones(1, dtype=wp.vec3, requires_grad=True, device=device)
|
|
1202
|
+
y = wp.zeros(1, dtype=float, requires_grad=True, device=device)
|
|
1203
|
+
|
|
1204
|
+
tape = wp.Tape()
|
|
1205
|
+
with tape:
|
|
1206
|
+
wp.launch(kernel, 1, inputs=[x], outputs=[y], device=device)
|
|
1207
|
+
|
|
1208
|
+
y.grad = wp.ones_like(y)
|
|
1209
|
+
tape.backward()
|
|
1210
|
+
|
|
1211
|
+
assert_np_equal(y.numpy(), np.array([6.0], dtype=float))
|
|
1212
|
+
assert_np_equal(x.grad.numpy(), np.array([[1.0, 2.0, 3.0]], dtype=float))
|
|
1213
|
+
|
|
1214
|
+
run(vec_extract_subscript)
|
|
1215
|
+
run(vec_extract_attribute)
|
|
1216
|
+
|
|
1217
|
+
|
|
1218
|
+
@wp.kernel
|
|
1219
|
+
def vec_assign_subscript(x: wp.array(dtype=float), y: wp.array(dtype=wp.vec3)):
|
|
1220
|
+
i = wp.tid()
|
|
1221
|
+
|
|
1222
|
+
a = wp.vec3()
|
|
1223
|
+
a[0] = 1.0 * x[i]
|
|
1224
|
+
a[1] = 2.0 * x[i]
|
|
1225
|
+
a[2] = 3.0 * x[i]
|
|
1226
|
+
y[i] = a
|
|
1227
|
+
|
|
1228
|
+
|
|
1229
|
+
@wp.kernel
|
|
1230
|
+
def vec_assign_attribute(x: wp.array(dtype=float), y: wp.array(dtype=wp.vec3)):
|
|
1231
|
+
i = wp.tid()
|
|
1232
|
+
|
|
1233
|
+
a = wp.vec3()
|
|
1234
|
+
a.x = 1.0 * x[i]
|
|
1235
|
+
a.y = 2.0 * x[i]
|
|
1236
|
+
a.z = 3.0 * x[i]
|
|
1237
|
+
y[i] = a
|
|
1238
|
+
|
|
1239
|
+
|
|
1240
|
+
def test_vec_assign(test, device):
|
|
1241
|
+
def run(kernel):
|
|
1242
|
+
x = wp.ones(1, dtype=float, requires_grad=True, device=device)
|
|
1243
|
+
y = wp.zeros(1, dtype=wp.vec3, requires_grad=True, device=device)
|
|
1244
|
+
|
|
1245
|
+
tape = wp.Tape()
|
|
1246
|
+
with tape:
|
|
1247
|
+
wp.launch(kernel, 1, inputs=[x], outputs=[y], device=device)
|
|
1248
|
+
|
|
1249
|
+
y.grad = wp.ones_like(y)
|
|
1250
|
+
tape.backward()
|
|
1251
|
+
|
|
1252
|
+
assert_np_equal(y.numpy(), np.array([[1.0, 2.0, 3.0]], dtype=float))
|
|
1253
|
+
assert_np_equal(x.grad.numpy(), np.array([6.0], dtype=float))
|
|
1254
|
+
|
|
1255
|
+
run(vec_assign_subscript)
|
|
1256
|
+
run(vec_assign_attribute)
|
|
1257
|
+
|
|
1258
|
+
|
|
1259
|
+
def test_vec_assign_copy(test, device):
|
|
1260
|
+
saved_enable_vector_component_overwrites_setting = wp.config.enable_vector_component_overwrites
|
|
1261
|
+
try:
|
|
1262
|
+
wp.config.enable_vector_component_overwrites = True
|
|
1263
|
+
|
|
1264
|
+
@wp.kernel
|
|
1265
|
+
def vec_assign_overwrite(x: wp.array(dtype=wp.vec3), y: wp.array(dtype=wp.vec3)):
|
|
1266
|
+
tid = wp.tid()
|
|
1267
|
+
|
|
1268
|
+
a = wp.vec3()
|
|
1269
|
+
b = x[tid]
|
|
1270
|
+
a = b
|
|
1271
|
+
a[1] = 3.0
|
|
1272
|
+
|
|
1273
|
+
y[tid] = a
|
|
1274
|
+
|
|
1275
|
+
x = wp.ones(1, dtype=wp.vec3, device=device, requires_grad=True)
|
|
1276
|
+
y = wp.zeros(1, dtype=wp.vec3, device=device, requires_grad=True)
|
|
1277
|
+
|
|
1278
|
+
tape = wp.Tape()
|
|
1279
|
+
with tape:
|
|
1280
|
+
wp.launch(vec_assign_overwrite, dim=1, inputs=[x, y], device=device)
|
|
1281
|
+
|
|
1282
|
+
y.grad = wp.ones_like(y, requires_grad=False)
|
|
1283
|
+
tape.backward()
|
|
1284
|
+
|
|
1285
|
+
assert_np_equal(y.numpy(), np.array([[1.0, 3.0, 1.0]], dtype=float))
|
|
1286
|
+
assert_np_equal(x.grad.numpy(), np.array([[1.0, 0.0, 1.0]], dtype=float))
|
|
1287
|
+
|
|
1288
|
+
finally:
|
|
1289
|
+
wp.config.enable_vector_component_overwrites = saved_enable_vector_component_overwrites_setting
|
|
1290
|
+
|
|
1291
|
+
|
|
1292
|
+
@wp.kernel
|
|
1293
|
+
def vec_array_extract_subscript(x: wp.array2d(dtype=wp.vec3), y: wp.array2d(dtype=float)):
|
|
1294
|
+
i, j = wp.tid()
|
|
1295
|
+
a = x[i, j][0]
|
|
1296
|
+
b = x[i, j][1]
|
|
1297
|
+
c = x[i, j][2]
|
|
1298
|
+
y[i, j] = 1.0 * a + 2.0 * b + 3.0 * c
|
|
1299
|
+
|
|
1300
|
+
|
|
1301
|
+
@wp.kernel
|
|
1302
|
+
def vec_array_extract_attribute(x: wp.array2d(dtype=wp.vec3), y: wp.array2d(dtype=float)):
|
|
1303
|
+
i, j = wp.tid()
|
|
1304
|
+
a = x[i, j].x
|
|
1305
|
+
b = x[i, j].y
|
|
1306
|
+
c = x[i, j].z
|
|
1307
|
+
y[i, j] = 1.0 * a + 2.0 * b + 3.0 * c
|
|
1308
|
+
|
|
1309
|
+
|
|
1310
|
+
def test_vec_array_extract(test, device):
|
|
1311
|
+
def run(kernel):
|
|
1312
|
+
x = wp.ones((1, 1), dtype=wp.vec3, requires_grad=True, device=device)
|
|
1313
|
+
y = wp.zeros((1, 1), dtype=float, requires_grad=True, device=device)
|
|
1314
|
+
|
|
1315
|
+
tape = wp.Tape()
|
|
1316
|
+
with tape:
|
|
1317
|
+
wp.launch(kernel, (1, 1), inputs=[x], outputs=[y], device=device)
|
|
1318
|
+
|
|
1319
|
+
y.grad = wp.ones_like(y)
|
|
1320
|
+
tape.backward()
|
|
1321
|
+
|
|
1322
|
+
assert_np_equal(y.numpy(), np.array([[6.0]], dtype=float))
|
|
1323
|
+
assert_np_equal(x.grad.numpy(), np.array([[[1.0, 2.0, 3.0]]], dtype=float))
|
|
1324
|
+
|
|
1325
|
+
run(vec_array_extract_subscript)
|
|
1326
|
+
run(vec_array_extract_attribute)
|
|
1327
|
+
|
|
1328
|
+
|
|
1329
|
+
@wp.kernel
|
|
1330
|
+
def vec_array_assign_subscript(x: wp.array2d(dtype=float), y: wp.array2d(dtype=wp.vec3)):
|
|
1331
|
+
i, j = wp.tid()
|
|
1332
|
+
|
|
1333
|
+
y[i, j][0] = 1.0 * x[i, j]
|
|
1334
|
+
y[i, j][1] = 2.0 * x[i, j]
|
|
1335
|
+
y[i, j][2] = 3.0 * x[i, j]
|
|
1336
|
+
|
|
1337
|
+
|
|
1338
|
+
@wp.kernel
|
|
1339
|
+
def vec_array_assign_attribute(x: wp.array2d(dtype=float), y: wp.array2d(dtype=wp.vec3)):
|
|
1340
|
+
i, j = wp.tid()
|
|
1341
|
+
|
|
1342
|
+
y[i, j].x = 1.0 * x[i, j]
|
|
1343
|
+
y[i, j].y = 2.0 * x[i, j]
|
|
1344
|
+
y[i, j].z = 3.0 * x[i, j]
|
|
1345
|
+
|
|
1346
|
+
|
|
1347
|
+
def test_vec_array_assign(test, device):
|
|
1348
|
+
def run(kernel):
|
|
1349
|
+
x = wp.ones((1, 1), dtype=float, requires_grad=True, device=device)
|
|
1350
|
+
y = wp.zeros((1, 1), dtype=wp.vec3, requires_grad=True, device=device)
|
|
1351
|
+
|
|
1352
|
+
tape = wp.Tape()
|
|
1353
|
+
with tape:
|
|
1354
|
+
wp.launch(kernel, (1, 1), inputs=[x], outputs=[y], device=device)
|
|
1355
|
+
|
|
1356
|
+
y.grad = wp.ones_like(y)
|
|
1357
|
+
tape.backward()
|
|
1358
|
+
|
|
1359
|
+
assert_np_equal(y.numpy(), np.array([[[1.0, 2.0, 3.0]]], dtype=float))
|
|
1360
|
+
# TODO: gradient propagation for in-place array assignment
|
|
1361
|
+
# assert_np_equal(x.grad.numpy(), np.array([[6.0]], dtype=float))
|
|
1362
|
+
|
|
1363
|
+
run(vec_array_assign_subscript)
|
|
1364
|
+
run(vec_array_assign_attribute)
|
|
1365
|
+
|
|
1366
|
+
|
|
1367
|
+
@wp.kernel
|
|
1368
|
+
def vec_add_inplace_subscript(x: wp.array(dtype=wp.vec3), y: wp.array(dtype=wp.vec3)):
|
|
1304
1369
|
i = wp.tid()
|
|
1305
1370
|
|
|
1306
|
-
|
|
1307
|
-
|
|
1371
|
+
a = wp.vec3()
|
|
1372
|
+
b = x[i]
|
|
1308
1373
|
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1374
|
+
a[0] += 1.0 * b[0]
|
|
1375
|
+
a[1] += 2.0 * b[1]
|
|
1376
|
+
a[2] += 3.0 * b[2]
|
|
1312
1377
|
|
|
1313
|
-
|
|
1378
|
+
y[i] = a
|
|
1314
1379
|
|
|
1315
|
-
v3 = wp.vec3()
|
|
1316
|
-
v4 = d[i]
|
|
1317
1380
|
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1381
|
+
@wp.kernel
|
|
1382
|
+
def vec_add_inplace_attribute(x: wp.array(dtype=wp.vec3), y: wp.array(dtype=wp.vec3)):
|
|
1383
|
+
i = wp.tid()
|
|
1384
|
+
|
|
1385
|
+
a = wp.vec3()
|
|
1386
|
+
b = x[i]
|
|
1387
|
+
|
|
1388
|
+
a.x += 1.0 * b.x
|
|
1389
|
+
a.y += 2.0 * b.y
|
|
1390
|
+
a.z += 3.0 * b.z
|
|
1391
|
+
|
|
1392
|
+
y[i] = a
|
|
1393
|
+
|
|
1321
1394
|
|
|
1322
|
-
|
|
1395
|
+
def test_vec_add_inplace(test, device):
|
|
1396
|
+
def run(kernel):
|
|
1397
|
+
x = wp.ones(1, dtype=wp.vec3, requires_grad=True, device=device)
|
|
1398
|
+
y = wp.zeros(1, dtype=wp.vec3, requires_grad=True, device=device)
|
|
1323
1399
|
|
|
1400
|
+
tape = wp.Tape()
|
|
1401
|
+
with tape:
|
|
1402
|
+
wp.launch(kernel, 1, inputs=[x], outputs=[y], device=device)
|
|
1324
1403
|
|
|
1325
|
-
|
|
1326
|
-
|
|
1404
|
+
y.grad = wp.ones_like(y)
|
|
1405
|
+
tape.backward()
|
|
1327
1406
|
|
|
1328
|
-
|
|
1329
|
-
|
|
1407
|
+
assert_np_equal(y.numpy(), np.array([[1.0, 2.0, 3.0]], dtype=float))
|
|
1408
|
+
assert_np_equal(x.grad.numpy(), np.array([[1.0, 2.0, 3.0]], dtype=float))
|
|
1409
|
+
|
|
1410
|
+
run(vec_add_inplace_subscript)
|
|
1411
|
+
run(vec_add_inplace_attribute)
|
|
1412
|
+
|
|
1413
|
+
|
|
1414
|
+
@wp.kernel
|
|
1415
|
+
def vec_sub_inplace_subscript(x: wp.array(dtype=wp.vec3), y: wp.array(dtype=wp.vec3)):
|
|
1416
|
+
i = wp.tid()
|
|
1330
1417
|
|
|
1331
|
-
|
|
1332
|
-
|
|
1418
|
+
a = wp.vec3()
|
|
1419
|
+
b = x[i]
|
|
1420
|
+
|
|
1421
|
+
a[0] -= 1.0 * b[0]
|
|
1422
|
+
a[1] -= 2.0 * b[1]
|
|
1423
|
+
a[2] -= 3.0 * b[2]
|
|
1424
|
+
|
|
1425
|
+
y[i] = a
|
|
1426
|
+
|
|
1427
|
+
|
|
1428
|
+
@wp.kernel
|
|
1429
|
+
def vec_sub_inplace_attribute(x: wp.array(dtype=wp.vec3), y: wp.array(dtype=wp.vec3)):
|
|
1430
|
+
i = wp.tid()
|
|
1431
|
+
|
|
1432
|
+
a = wp.vec3()
|
|
1433
|
+
b = x[i]
|
|
1434
|
+
|
|
1435
|
+
a.x -= 1.0 * b.x
|
|
1436
|
+
a.y -= 2.0 * b.y
|
|
1437
|
+
a.z -= 3.0 * b.z
|
|
1438
|
+
|
|
1439
|
+
y[i] = a
|
|
1440
|
+
|
|
1441
|
+
|
|
1442
|
+
def test_vec_sub_inplace(test, device):
|
|
1443
|
+
def run(kernel):
|
|
1444
|
+
x = wp.ones(1, dtype=wp.vec3, requires_grad=True, device=device)
|
|
1445
|
+
y = wp.zeros(1, dtype=wp.vec3, requires_grad=True, device=device)
|
|
1446
|
+
|
|
1447
|
+
tape = wp.Tape()
|
|
1448
|
+
with tape:
|
|
1449
|
+
wp.launch(kernel, 1, inputs=[x], outputs=[y], device=device)
|
|
1450
|
+
|
|
1451
|
+
y.grad = wp.ones_like(y)
|
|
1452
|
+
tape.backward()
|
|
1453
|
+
|
|
1454
|
+
assert_np_equal(y.numpy(), np.array([[-1.0, -2.0, -3.0]], dtype=float))
|
|
1455
|
+
assert_np_equal(x.grad.numpy(), np.array([[-1.0, -2.0, -3.0]], dtype=float))
|
|
1456
|
+
|
|
1457
|
+
run(vec_sub_inplace_subscript)
|
|
1458
|
+
run(vec_sub_inplace_attribute)
|
|
1459
|
+
|
|
1460
|
+
|
|
1461
|
+
@wp.kernel
|
|
1462
|
+
def vec_array_add_inplace(x: wp.array(dtype=wp.vec3), y: wp.array(dtype=wp.vec3)):
|
|
1463
|
+
i = wp.tid()
|
|
1464
|
+
|
|
1465
|
+
y[i] += x[i]
|
|
1466
|
+
|
|
1467
|
+
|
|
1468
|
+
def test_vec_array_add_inplace(test, device):
|
|
1469
|
+
x = wp.ones(1, dtype=wp.vec3, requires_grad=True, device=device)
|
|
1470
|
+
y = wp.zeros(1, dtype=wp.vec3, requires_grad=True, device=device)
|
|
1333
1471
|
|
|
1334
1472
|
tape = wp.Tape()
|
|
1335
1473
|
with tape:
|
|
1336
|
-
wp.launch(
|
|
1474
|
+
wp.launch(vec_array_add_inplace, 1, inputs=[x], outputs=[y], device=device)
|
|
1475
|
+
|
|
1476
|
+
y.grad = wp.ones_like(y)
|
|
1477
|
+
tape.backward()
|
|
1337
1478
|
|
|
1338
|
-
|
|
1479
|
+
assert_np_equal(y.numpy(), np.array([[1.0, 1.0, 1.0]], dtype=float))
|
|
1480
|
+
assert_np_equal(x.grad.numpy(), np.array([[1.0, 1.0, 1.0]], dtype=float))
|
|
1339
1481
|
|
|
1340
|
-
assert_np_equal(a.numpy(), wp.ones_like(a).numpy())
|
|
1341
|
-
assert_np_equal(a.grad.numpy(), wp.ones_like(a).numpy())
|
|
1342
|
-
assert_np_equal(b.grad.numpy(), wp.ones_like(a).numpy())
|
|
1343
1482
|
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1483
|
+
@wp.kernel
|
|
1484
|
+
def vec_array_sub_inplace(x: wp.array(dtype=wp.vec3), y: wp.array(dtype=wp.vec3)):
|
|
1485
|
+
i = wp.tid()
|
|
1486
|
+
|
|
1487
|
+
y[i] -= x[i]
|
|
1488
|
+
|
|
1489
|
+
|
|
1490
|
+
def test_vec_array_sub_inplace(test, device):
|
|
1491
|
+
x = wp.ones(1, dtype=wp.vec3, requires_grad=True, device=device)
|
|
1492
|
+
y = wp.zeros(1, dtype=wp.vec3, requires_grad=True, device=device)
|
|
1493
|
+
|
|
1494
|
+
tape = wp.Tape()
|
|
1495
|
+
with tape:
|
|
1496
|
+
wp.launch(vec_array_sub_inplace, 1, inputs=[x], outputs=[y], device=device)
|
|
1497
|
+
|
|
1498
|
+
y.grad = wp.ones_like(y)
|
|
1499
|
+
tape.backward()
|
|
1500
|
+
|
|
1501
|
+
assert_np_equal(y.numpy(), np.array([[-1.0, -1.0, -1.0]], dtype=float))
|
|
1502
|
+
assert_np_equal(x.grad.numpy(), np.array([[-1.0, -1.0, -1.0]], dtype=float))
|
|
1347
1503
|
|
|
1348
1504
|
|
|
1349
1505
|
devices = get_test_devices()
|
|
@@ -1412,14 +1568,13 @@ for dtype in np_float_types:
|
|
|
1412
1568
|
devices=devices,
|
|
1413
1569
|
dtype=dtype,
|
|
1414
1570
|
)
|
|
1415
|
-
add_function_test_register_kernel(
|
|
1416
|
-
TestVec,
|
|
1417
|
-
f"test_vec_assign_{dtype.__name__}",
|
|
1418
|
-
test_vec_assign,
|
|
1419
|
-
devices=devices,
|
|
1420
|
-
dtype=dtype,
|
|
1421
|
-
)
|
|
1422
1571
|
|
|
1572
|
+
add_function_test(
|
|
1573
|
+
TestVec,
|
|
1574
|
+
"test_length_mismatch",
|
|
1575
|
+
test_length_mismatch,
|
|
1576
|
+
devices=devices,
|
|
1577
|
+
)
|
|
1423
1578
|
add_function_test(
|
|
1424
1579
|
TestVec,
|
|
1425
1580
|
"test_anon_constructor_error_length_mismatch",
|
|
@@ -1462,12 +1617,15 @@ add_function_test(
|
|
|
1462
1617
|
test_vector_len,
|
|
1463
1618
|
devices=devices,
|
|
1464
1619
|
)
|
|
1465
|
-
add_function_test(
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
)
|
|
1620
|
+
add_function_test(TestVec, "test_vec_extract", test_vec_extract, devices=devices)
|
|
1621
|
+
add_function_test(TestVec, "test_vec_assign", test_vec_assign, devices=devices)
|
|
1622
|
+
add_function_test(TestVec, "test_vec_assign_copy", test_vec_assign_copy, devices=devices)
|
|
1623
|
+
add_function_test(TestVec, "test_vec_array_extract", test_vec_array_extract, devices=devices)
|
|
1624
|
+
add_function_test(TestVec, "test_vec_array_assign", test_vec_array_assign, devices=devices)
|
|
1625
|
+
add_function_test(TestVec, "test_vec_add_inplace", test_vec_add_inplace, devices=devices)
|
|
1626
|
+
add_function_test(TestVec, "test_vec_sub_inplace", test_vec_sub_inplace, devices=devices)
|
|
1627
|
+
add_function_test(TestVec, "test_vec_array_add_inplace", test_vec_array_add_inplace, devices=devices)
|
|
1628
|
+
add_function_test(TestVec, "test_vec_array_sub_inplace", test_vec_array_sub_inplace, devices=devices)
|
|
1471
1629
|
|
|
1472
1630
|
|
|
1473
1631
|
if __name__ == "__main__":
|
|
File without changes
|