warp-lang 1.6.2__py3-none-win_amd64.whl → 1.7.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.

Files changed (191) hide show
  1. warp/__init__.py +7 -1
  2. warp/autograd.py +12 -2
  3. warp/bin/warp-clang.dll +0 -0
  4. warp/bin/warp.dll +0 -0
  5. warp/build.py +410 -0
  6. warp/build_dll.py +6 -14
  7. warp/builtins.py +463 -372
  8. warp/codegen.py +196 -124
  9. warp/config.py +42 -6
  10. warp/context.py +496 -271
  11. warp/dlpack.py +8 -6
  12. warp/examples/assets/nonuniform.usd +0 -0
  13. warp/examples/assets/nvidia_logo.png +0 -0
  14. warp/examples/benchmarks/benchmark_cloth.py +1 -1
  15. warp/examples/benchmarks/benchmark_tile_load_store.py +103 -0
  16. warp/examples/core/example_sample_mesh.py +300 -0
  17. warp/examples/distributed/example_jacobi_mpi.py +507 -0
  18. warp/examples/fem/example_apic_fluid.py +1 -1
  19. warp/examples/fem/example_burgers.py +2 -2
  20. warp/examples/fem/example_deformed_geometry.py +1 -1
  21. warp/examples/fem/example_distortion_energy.py +1 -1
  22. warp/examples/fem/example_magnetostatics.py +6 -6
  23. warp/examples/fem/utils.py +9 -3
  24. warp/examples/interop/example_jax_callable.py +116 -0
  25. warp/examples/interop/example_jax_ffi_callback.py +132 -0
  26. warp/examples/interop/example_jax_kernel.py +205 -0
  27. warp/examples/optim/example_fluid_checkpoint.py +497 -0
  28. warp/examples/tile/example_tile_matmul.py +2 -4
  29. warp/fem/__init__.py +11 -1
  30. warp/fem/adaptivity.py +4 -4
  31. warp/fem/field/field.py +11 -1
  32. warp/fem/field/nodal_field.py +56 -88
  33. warp/fem/field/virtual.py +62 -23
  34. warp/fem/geometry/adaptive_nanogrid.py +16 -13
  35. warp/fem/geometry/closest_point.py +1 -1
  36. warp/fem/geometry/deformed_geometry.py +5 -2
  37. warp/fem/geometry/geometry.py +5 -0
  38. warp/fem/geometry/grid_2d.py +12 -12
  39. warp/fem/geometry/grid_3d.py +12 -15
  40. warp/fem/geometry/hexmesh.py +5 -7
  41. warp/fem/geometry/nanogrid.py +9 -11
  42. warp/fem/geometry/quadmesh.py +13 -13
  43. warp/fem/geometry/tetmesh.py +3 -4
  44. warp/fem/geometry/trimesh.py +7 -20
  45. warp/fem/integrate.py +262 -93
  46. warp/fem/linalg.py +5 -5
  47. warp/fem/quadrature/pic_quadrature.py +37 -22
  48. warp/fem/quadrature/quadrature.py +194 -25
  49. warp/fem/space/__init__.py +1 -1
  50. warp/fem/space/basis_function_space.py +4 -2
  51. warp/fem/space/basis_space.py +25 -18
  52. warp/fem/space/hexmesh_function_space.py +2 -2
  53. warp/fem/space/partition.py +6 -2
  54. warp/fem/space/quadmesh_function_space.py +8 -8
  55. warp/fem/space/shape/cube_shape_function.py +23 -23
  56. warp/fem/space/shape/square_shape_function.py +12 -12
  57. warp/fem/space/shape/triangle_shape_function.py +1 -1
  58. warp/fem/space/tetmesh_function_space.py +3 -3
  59. warp/fem/space/trimesh_function_space.py +2 -2
  60. warp/fem/utils.py +12 -6
  61. warp/jax.py +14 -1
  62. warp/jax_experimental/__init__.py +16 -0
  63. warp/{jax_experimental.py → jax_experimental/custom_call.py} +28 -29
  64. warp/jax_experimental/ffi.py +702 -0
  65. warp/jax_experimental/xla_ffi.py +602 -0
  66. warp/math.py +89 -0
  67. warp/native/array.h +13 -0
  68. warp/native/builtin.h +29 -3
  69. warp/native/bvh.cpp +3 -1
  70. warp/native/bvh.cu +42 -14
  71. warp/native/bvh.h +2 -1
  72. warp/native/clang/clang.cpp +30 -3
  73. warp/native/cuda_util.cpp +14 -0
  74. warp/native/cuda_util.h +2 -0
  75. warp/native/exports.h +68 -63
  76. warp/native/intersect.h +26 -26
  77. warp/native/intersect_adj.h +33 -33
  78. warp/native/marching.cu +1 -1
  79. warp/native/mat.h +513 -9
  80. warp/native/mesh.h +10 -10
  81. warp/native/quat.h +99 -11
  82. warp/native/rand.h +6 -0
  83. warp/native/sort.cpp +122 -59
  84. warp/native/sort.cu +152 -15
  85. warp/native/sort.h +8 -1
  86. warp/native/sparse.cpp +43 -22
  87. warp/native/sparse.cu +52 -17
  88. warp/native/svd.h +116 -0
  89. warp/native/tile.h +312 -116
  90. warp/native/tile_reduce.h +46 -3
  91. warp/native/vec.h +68 -7
  92. warp/native/volume.cpp +85 -113
  93. warp/native/volume_builder.cu +25 -10
  94. warp/native/volume_builder.h +6 -0
  95. warp/native/warp.cpp +5 -6
  96. warp/native/warp.cu +100 -11
  97. warp/native/warp.h +19 -10
  98. warp/optim/linear.py +10 -10
  99. warp/render/render_opengl.py +19 -17
  100. warp/render/render_usd.py +93 -3
  101. warp/sim/articulation.py +4 -4
  102. warp/sim/collide.py +32 -19
  103. warp/sim/import_mjcf.py +449 -155
  104. warp/sim/import_urdf.py +32 -12
  105. warp/sim/inertia.py +189 -156
  106. warp/sim/integrator_euler.py +8 -5
  107. warp/sim/integrator_featherstone.py +3 -10
  108. warp/sim/integrator_vbd.py +207 -2
  109. warp/sim/integrator_xpbd.py +8 -5
  110. warp/sim/model.py +71 -25
  111. warp/sim/render.py +4 -0
  112. warp/sim/utils.py +2 -2
  113. warp/sparse.py +642 -555
  114. warp/stubs.py +217 -20
  115. warp/tests/__main__.py +0 -15
  116. warp/tests/assets/torus.usda +1 -1
  117. warp/tests/cuda/__init__.py +0 -0
  118. warp/tests/{test_mempool.py → cuda/test_mempool.py} +39 -0
  119. warp/tests/{test_streams.py → cuda/test_streams.py} +71 -0
  120. warp/tests/geometry/__init__.py +0 -0
  121. warp/tests/{test_mesh_query_point.py → geometry/test_mesh_query_point.py} +66 -63
  122. warp/tests/{test_mesh_query_ray.py → geometry/test_mesh_query_ray.py} +1 -1
  123. warp/tests/{test_volume.py → geometry/test_volume.py} +41 -6
  124. warp/tests/interop/__init__.py +0 -0
  125. warp/tests/{test_dlpack.py → interop/test_dlpack.py} +28 -5
  126. warp/tests/sim/__init__.py +0 -0
  127. warp/tests/{disabled_kinematics.py → sim/disabled_kinematics.py} +9 -10
  128. warp/tests/{test_collision.py → sim/test_collision.py} +236 -205
  129. warp/tests/sim/test_inertia.py +161 -0
  130. warp/tests/{test_model.py → sim/test_model.py} +40 -0
  131. warp/tests/{flaky_test_sim_grad.py → sim/test_sim_grad.py} +4 -0
  132. warp/tests/{test_sim_kinematics.py → sim/test_sim_kinematics.py} +2 -1
  133. warp/tests/sim/test_vbd.py +597 -0
  134. warp/tests/sim/test_xpbd.py +399 -0
  135. warp/tests/test_bool.py +1 -1
  136. warp/tests/test_codegen.py +24 -3
  137. warp/tests/test_examples.py +40 -38
  138. warp/tests/test_fem.py +98 -14
  139. warp/tests/test_linear_solvers.py +0 -11
  140. warp/tests/test_mat.py +577 -156
  141. warp/tests/test_mat_scalar_ops.py +4 -4
  142. warp/tests/test_overwrite.py +0 -60
  143. warp/tests/test_quat.py +356 -151
  144. warp/tests/test_rand.py +44 -37
  145. warp/tests/test_sparse.py +47 -6
  146. warp/tests/test_spatial.py +75 -0
  147. warp/tests/test_static.py +1 -1
  148. warp/tests/test_utils.py +84 -4
  149. warp/tests/test_vec.py +336 -178
  150. warp/tests/tile/__init__.py +0 -0
  151. warp/tests/{test_tile.py → tile/test_tile.py} +136 -51
  152. warp/tests/{test_tile_load.py → tile/test_tile_load.py} +98 -1
  153. warp/tests/{test_tile_mathdx.py → tile/test_tile_mathdx.py} +9 -6
  154. warp/tests/{test_tile_mlp.py → tile/test_tile_mlp.py} +25 -14
  155. warp/tests/{test_tile_reduce.py → tile/test_tile_reduce.py} +60 -1
  156. warp/tests/{test_tile_view.py → tile/test_tile_view.py} +1 -1
  157. warp/tests/unittest_serial.py +1 -0
  158. warp/tests/unittest_suites.py +45 -62
  159. warp/tests/unittest_utils.py +2 -1
  160. warp/thirdparty/unittest_parallel.py +3 -1
  161. warp/types.py +175 -666
  162. warp/utils.py +137 -72
  163. {warp_lang-1.6.2.dist-info → warp_lang-1.7.1.dist-info}/METADATA +46 -12
  164. {warp_lang-1.6.2.dist-info → warp_lang-1.7.1.dist-info}/RECORD +184 -171
  165. {warp_lang-1.6.2.dist-info → warp_lang-1.7.1.dist-info}/WHEEL +1 -1
  166. {warp_lang-1.6.2.dist-info → warp_lang-1.7.1.dist-info/licenses}/LICENSE.md +0 -26
  167. warp/examples/optim/example_walker.py +0 -317
  168. warp/native/cutlass_gemm.cpp +0 -43
  169. warp/native/cutlass_gemm.cu +0 -382
  170. warp/tests/test_matmul.py +0 -511
  171. warp/tests/test_matmul_lite.py +0 -411
  172. warp/tests/test_vbd.py +0 -386
  173. warp/tests/unused_test_misc.py +0 -77
  174. /warp/tests/{test_async.py → cuda/test_async.py} +0 -0
  175. /warp/tests/{test_ipc.py → cuda/test_ipc.py} +0 -0
  176. /warp/tests/{test_multigpu.py → cuda/test_multigpu.py} +0 -0
  177. /warp/tests/{test_peer.py → cuda/test_peer.py} +0 -0
  178. /warp/tests/{test_pinned.py → cuda/test_pinned.py} +0 -0
  179. /warp/tests/{test_bvh.py → geometry/test_bvh.py} +0 -0
  180. /warp/tests/{test_hash_grid.py → geometry/test_hash_grid.py} +0 -0
  181. /warp/tests/{test_marching_cubes.py → geometry/test_marching_cubes.py} +0 -0
  182. /warp/tests/{test_mesh.py → geometry/test_mesh.py} +0 -0
  183. /warp/tests/{test_mesh_query_aabb.py → geometry/test_mesh_query_aabb.py} +0 -0
  184. /warp/tests/{test_volume_write.py → geometry/test_volume_write.py} +0 -0
  185. /warp/tests/{test_jax.py → interop/test_jax.py} +0 -0
  186. /warp/tests/{test_paddle.py → interop/test_paddle.py} +0 -0
  187. /warp/tests/{test_torch.py → interop/test_torch.py} +0 -0
  188. /warp/tests/{test_coloring.py → sim/test_coloring.py} +0 -0
  189. /warp/tests/{test_sim_grad_bounce_linear.py → sim/test_sim_grad_bounce_linear.py} +0 -0
  190. /warp/tests/{test_tile_shared_memory.py → tile/test_tile_shared_memory.py} +0 -0
  191. {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 vector_augassign_kernel(
1302
- a: wp.array(dtype=wp.vec3), b: wp.array(dtype=wp.vec3), c: wp.array(dtype=wp.vec3), d: wp.array(dtype=wp.vec3)
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
- v1 = wp.vec3()
1307
- v2 = b[i]
1371
+ a = wp.vec3()
1372
+ b = x[i]
1308
1373
 
1309
- v1[0] += v2[0]
1310
- v1[1] += v2[1]
1311
- v1[2] += v2[2]
1374
+ a[0] += 1.0 * b[0]
1375
+ a[1] += 2.0 * b[1]
1376
+ a[2] += 3.0 * b[2]
1312
1377
 
1313
- a[i] = v1
1378
+ y[i] = a
1314
1379
 
1315
- v3 = wp.vec3()
1316
- v4 = d[i]
1317
1380
 
1318
- v3[0] -= v4[0]
1319
- v3[1] -= v4[1]
1320
- v3[2] -= v4[2]
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
- c[i] = v3
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
- def test_vector_augassign(test, device):
1326
- N = 3
1404
+ y.grad = wp.ones_like(y)
1405
+ tape.backward()
1327
1406
 
1328
- a = wp.zeros(N, dtype=wp.vec3, requires_grad=True)
1329
- b = wp.ones(N, dtype=wp.vec3, requires_grad=True)
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
- c = wp.zeros(N, dtype=wp.vec3, requires_grad=True)
1332
- d = wp.ones(N, dtype=wp.vec3, requires_grad=True)
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(vector_augassign_kernel, N, inputs=[a, b, c, d])
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
- tape.backward(grads={a: wp.ones_like(a), c: wp.ones_like(c)})
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
- assert_np_equal(c.numpy(), -wp.ones_like(c).numpy())
1345
- assert_np_equal(c.grad.numpy(), wp.ones_like(c).numpy())
1346
- assert_np_equal(d.grad.numpy(), -wp.ones_like(d).numpy())
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
- TestVec,
1467
- "test_vector_augassign",
1468
- test_vector_augassign,
1469
- devices=devices,
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