warp-lang 1.10.0__py3-none-macosx_11_0_arm64.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 (468) hide show
  1. warp/__init__.py +334 -0
  2. warp/__init__.pyi +5856 -0
  3. warp/_src/__init__.py +14 -0
  4. warp/_src/autograd.py +1077 -0
  5. warp/_src/build.py +620 -0
  6. warp/_src/build_dll.py +642 -0
  7. warp/_src/builtins.py +10555 -0
  8. warp/_src/codegen.py +4361 -0
  9. warp/_src/config.py +178 -0
  10. warp/_src/constants.py +59 -0
  11. warp/_src/context.py +8352 -0
  12. warp/_src/dlpack.py +464 -0
  13. warp/_src/fabric.py +362 -0
  14. warp/_src/fem/__init__.py +14 -0
  15. warp/_src/fem/adaptivity.py +510 -0
  16. warp/_src/fem/cache.py +689 -0
  17. warp/_src/fem/dirichlet.py +190 -0
  18. warp/_src/fem/domain.py +553 -0
  19. warp/_src/fem/field/__init__.py +131 -0
  20. warp/_src/fem/field/field.py +703 -0
  21. warp/_src/fem/field/nodal_field.py +403 -0
  22. warp/_src/fem/field/restriction.py +39 -0
  23. warp/_src/fem/field/virtual.py +1021 -0
  24. warp/_src/fem/geometry/__init__.py +32 -0
  25. warp/_src/fem/geometry/adaptive_nanogrid.py +782 -0
  26. warp/_src/fem/geometry/closest_point.py +99 -0
  27. warp/_src/fem/geometry/deformed_geometry.py +277 -0
  28. warp/_src/fem/geometry/element.py +854 -0
  29. warp/_src/fem/geometry/geometry.py +693 -0
  30. warp/_src/fem/geometry/grid_2d.py +478 -0
  31. warp/_src/fem/geometry/grid_3d.py +539 -0
  32. warp/_src/fem/geometry/hexmesh.py +956 -0
  33. warp/_src/fem/geometry/nanogrid.py +660 -0
  34. warp/_src/fem/geometry/partition.py +483 -0
  35. warp/_src/fem/geometry/quadmesh.py +597 -0
  36. warp/_src/fem/geometry/tetmesh.py +762 -0
  37. warp/_src/fem/geometry/trimesh.py +588 -0
  38. warp/_src/fem/integrate.py +2507 -0
  39. warp/_src/fem/linalg.py +385 -0
  40. warp/_src/fem/operator.py +398 -0
  41. warp/_src/fem/polynomial.py +231 -0
  42. warp/_src/fem/quadrature/__init__.py +17 -0
  43. warp/_src/fem/quadrature/pic_quadrature.py +318 -0
  44. warp/_src/fem/quadrature/quadrature.py +665 -0
  45. warp/_src/fem/space/__init__.py +248 -0
  46. warp/_src/fem/space/basis_function_space.py +499 -0
  47. warp/_src/fem/space/basis_space.py +681 -0
  48. warp/_src/fem/space/dof_mapper.py +253 -0
  49. warp/_src/fem/space/function_space.py +312 -0
  50. warp/_src/fem/space/grid_2d_function_space.py +179 -0
  51. warp/_src/fem/space/grid_3d_function_space.py +229 -0
  52. warp/_src/fem/space/hexmesh_function_space.py +255 -0
  53. warp/_src/fem/space/nanogrid_function_space.py +199 -0
  54. warp/_src/fem/space/partition.py +435 -0
  55. warp/_src/fem/space/quadmesh_function_space.py +222 -0
  56. warp/_src/fem/space/restriction.py +221 -0
  57. warp/_src/fem/space/shape/__init__.py +152 -0
  58. warp/_src/fem/space/shape/cube_shape_function.py +1107 -0
  59. warp/_src/fem/space/shape/shape_function.py +134 -0
  60. warp/_src/fem/space/shape/square_shape_function.py +928 -0
  61. warp/_src/fem/space/shape/tet_shape_function.py +829 -0
  62. warp/_src/fem/space/shape/triangle_shape_function.py +674 -0
  63. warp/_src/fem/space/tetmesh_function_space.py +270 -0
  64. warp/_src/fem/space/topology.py +461 -0
  65. warp/_src/fem/space/trimesh_function_space.py +193 -0
  66. warp/_src/fem/types.py +114 -0
  67. warp/_src/fem/utils.py +488 -0
  68. warp/_src/jax.py +188 -0
  69. warp/_src/jax_experimental/__init__.py +14 -0
  70. warp/_src/jax_experimental/custom_call.py +389 -0
  71. warp/_src/jax_experimental/ffi.py +1286 -0
  72. warp/_src/jax_experimental/xla_ffi.py +658 -0
  73. warp/_src/marching_cubes.py +710 -0
  74. warp/_src/math.py +416 -0
  75. warp/_src/optim/__init__.py +14 -0
  76. warp/_src/optim/adam.py +165 -0
  77. warp/_src/optim/linear.py +1608 -0
  78. warp/_src/optim/sgd.py +114 -0
  79. warp/_src/paddle.py +408 -0
  80. warp/_src/render/__init__.py +14 -0
  81. warp/_src/render/imgui_manager.py +291 -0
  82. warp/_src/render/render_opengl.py +3638 -0
  83. warp/_src/render/render_usd.py +939 -0
  84. warp/_src/render/utils.py +162 -0
  85. warp/_src/sparse.py +2718 -0
  86. warp/_src/tape.py +1208 -0
  87. warp/_src/thirdparty/__init__.py +0 -0
  88. warp/_src/thirdparty/appdirs.py +598 -0
  89. warp/_src/thirdparty/dlpack.py +145 -0
  90. warp/_src/thirdparty/unittest_parallel.py +676 -0
  91. warp/_src/torch.py +393 -0
  92. warp/_src/types.py +5888 -0
  93. warp/_src/utils.py +1695 -0
  94. warp/autograd.py +33 -0
  95. warp/bin/libwarp-clang.dylib +0 -0
  96. warp/bin/libwarp.dylib +0 -0
  97. warp/build.py +29 -0
  98. warp/build_dll.py +24 -0
  99. warp/codegen.py +24 -0
  100. warp/constants.py +24 -0
  101. warp/context.py +33 -0
  102. warp/dlpack.py +24 -0
  103. warp/examples/__init__.py +24 -0
  104. warp/examples/assets/bear.usd +0 -0
  105. warp/examples/assets/bunny.usd +0 -0
  106. warp/examples/assets/cube.usd +0 -0
  107. warp/examples/assets/nonuniform.usd +0 -0
  108. warp/examples/assets/nvidia_logo.png +0 -0
  109. warp/examples/assets/pixel.jpg +0 -0
  110. warp/examples/assets/rocks.nvdb +0 -0
  111. warp/examples/assets/rocks.usd +0 -0
  112. warp/examples/assets/sphere.usd +0 -0
  113. warp/examples/assets/square_cloth.usd +0 -0
  114. warp/examples/benchmarks/benchmark_api.py +389 -0
  115. warp/examples/benchmarks/benchmark_cloth.py +296 -0
  116. warp/examples/benchmarks/benchmark_cloth_cupy.py +96 -0
  117. warp/examples/benchmarks/benchmark_cloth_jax.py +105 -0
  118. warp/examples/benchmarks/benchmark_cloth_numba.py +161 -0
  119. warp/examples/benchmarks/benchmark_cloth_numpy.py +85 -0
  120. warp/examples/benchmarks/benchmark_cloth_paddle.py +94 -0
  121. warp/examples/benchmarks/benchmark_cloth_pytorch.py +94 -0
  122. warp/examples/benchmarks/benchmark_cloth_taichi.py +120 -0
  123. warp/examples/benchmarks/benchmark_cloth_warp.py +153 -0
  124. warp/examples/benchmarks/benchmark_gemm.py +164 -0
  125. warp/examples/benchmarks/benchmark_interop_paddle.py +166 -0
  126. warp/examples/benchmarks/benchmark_interop_torch.py +166 -0
  127. warp/examples/benchmarks/benchmark_launches.py +301 -0
  128. warp/examples/benchmarks/benchmark_tile_load_store.py +103 -0
  129. warp/examples/benchmarks/benchmark_tile_sort.py +155 -0
  130. warp/examples/browse.py +37 -0
  131. warp/examples/core/example_cupy.py +86 -0
  132. warp/examples/core/example_dem.py +241 -0
  133. warp/examples/core/example_fluid.py +299 -0
  134. warp/examples/core/example_graph_capture.py +150 -0
  135. warp/examples/core/example_marching_cubes.py +195 -0
  136. warp/examples/core/example_mesh.py +180 -0
  137. warp/examples/core/example_mesh_intersect.py +211 -0
  138. warp/examples/core/example_nvdb.py +182 -0
  139. warp/examples/core/example_raycast.py +111 -0
  140. warp/examples/core/example_raymarch.py +205 -0
  141. warp/examples/core/example_render_opengl.py +290 -0
  142. warp/examples/core/example_sample_mesh.py +300 -0
  143. warp/examples/core/example_sph.py +411 -0
  144. warp/examples/core/example_spin_lock.py +93 -0
  145. warp/examples/core/example_torch.py +211 -0
  146. warp/examples/core/example_wave.py +269 -0
  147. warp/examples/core/example_work_queue.py +118 -0
  148. warp/examples/distributed/example_jacobi_mpi.py +506 -0
  149. warp/examples/fem/example_adaptive_grid.py +286 -0
  150. warp/examples/fem/example_apic_fluid.py +469 -0
  151. warp/examples/fem/example_burgers.py +261 -0
  152. warp/examples/fem/example_convection_diffusion.py +181 -0
  153. warp/examples/fem/example_convection_diffusion_dg.py +225 -0
  154. warp/examples/fem/example_darcy_ls_optimization.py +489 -0
  155. warp/examples/fem/example_deformed_geometry.py +172 -0
  156. warp/examples/fem/example_diffusion.py +196 -0
  157. warp/examples/fem/example_diffusion_3d.py +225 -0
  158. warp/examples/fem/example_diffusion_mgpu.py +225 -0
  159. warp/examples/fem/example_distortion_energy.py +228 -0
  160. warp/examples/fem/example_elastic_shape_optimization.py +387 -0
  161. warp/examples/fem/example_magnetostatics.py +242 -0
  162. warp/examples/fem/example_mixed_elasticity.py +293 -0
  163. warp/examples/fem/example_navier_stokes.py +263 -0
  164. warp/examples/fem/example_nonconforming_contact.py +300 -0
  165. warp/examples/fem/example_stokes.py +213 -0
  166. warp/examples/fem/example_stokes_transfer.py +262 -0
  167. warp/examples/fem/example_streamlines.py +357 -0
  168. warp/examples/fem/utils.py +1047 -0
  169. warp/examples/interop/example_jax_callable.py +146 -0
  170. warp/examples/interop/example_jax_ffi_callback.py +132 -0
  171. warp/examples/interop/example_jax_kernel.py +232 -0
  172. warp/examples/optim/example_diffray.py +561 -0
  173. warp/examples/optim/example_fluid_checkpoint.py +497 -0
  174. warp/examples/tile/example_tile_block_cholesky.py +502 -0
  175. warp/examples/tile/example_tile_cholesky.py +88 -0
  176. warp/examples/tile/example_tile_convolution.py +66 -0
  177. warp/examples/tile/example_tile_fft.py +55 -0
  178. warp/examples/tile/example_tile_filtering.py +113 -0
  179. warp/examples/tile/example_tile_matmul.py +85 -0
  180. warp/examples/tile/example_tile_mcgp.py +191 -0
  181. warp/examples/tile/example_tile_mlp.py +385 -0
  182. warp/examples/tile/example_tile_nbody.py +199 -0
  183. warp/fabric.py +24 -0
  184. warp/fem/__init__.py +173 -0
  185. warp/fem/adaptivity.py +26 -0
  186. warp/fem/cache.py +30 -0
  187. warp/fem/dirichlet.py +24 -0
  188. warp/fem/field/__init__.py +24 -0
  189. warp/fem/field/field.py +26 -0
  190. warp/fem/geometry/__init__.py +21 -0
  191. warp/fem/geometry/closest_point.py +31 -0
  192. warp/fem/linalg.py +38 -0
  193. warp/fem/operator.py +32 -0
  194. warp/fem/polynomial.py +29 -0
  195. warp/fem/space/__init__.py +22 -0
  196. warp/fem/space/basis_space.py +24 -0
  197. warp/fem/space/shape/__init__.py +68 -0
  198. warp/fem/space/topology.py +24 -0
  199. warp/fem/types.py +24 -0
  200. warp/fem/utils.py +32 -0
  201. warp/jax.py +29 -0
  202. warp/jax_experimental/__init__.py +29 -0
  203. warp/jax_experimental/custom_call.py +29 -0
  204. warp/jax_experimental/ffi.py +39 -0
  205. warp/jax_experimental/xla_ffi.py +24 -0
  206. warp/marching_cubes.py +24 -0
  207. warp/math.py +37 -0
  208. warp/native/array.h +1687 -0
  209. warp/native/builtin.h +2327 -0
  210. warp/native/bvh.cpp +562 -0
  211. warp/native/bvh.cu +826 -0
  212. warp/native/bvh.h +555 -0
  213. warp/native/clang/clang.cpp +541 -0
  214. warp/native/coloring.cpp +622 -0
  215. warp/native/crt.cpp +51 -0
  216. warp/native/crt.h +568 -0
  217. warp/native/cuda_crt.h +1058 -0
  218. warp/native/cuda_util.cpp +677 -0
  219. warp/native/cuda_util.h +313 -0
  220. warp/native/error.cpp +77 -0
  221. warp/native/error.h +36 -0
  222. warp/native/exports.h +2023 -0
  223. warp/native/fabric.h +246 -0
  224. warp/native/hashgrid.cpp +311 -0
  225. warp/native/hashgrid.cu +89 -0
  226. warp/native/hashgrid.h +240 -0
  227. warp/native/initializer_array.h +41 -0
  228. warp/native/intersect.h +1253 -0
  229. warp/native/intersect_adj.h +375 -0
  230. warp/native/intersect_tri.h +348 -0
  231. warp/native/mat.h +5189 -0
  232. warp/native/mathdx.cpp +93 -0
  233. warp/native/matnn.h +221 -0
  234. warp/native/mesh.cpp +266 -0
  235. warp/native/mesh.cu +406 -0
  236. warp/native/mesh.h +2097 -0
  237. warp/native/nanovdb/GridHandle.h +533 -0
  238. warp/native/nanovdb/HostBuffer.h +591 -0
  239. warp/native/nanovdb/NanoVDB.h +6246 -0
  240. warp/native/nanovdb/NodeManager.h +323 -0
  241. warp/native/nanovdb/PNanoVDB.h +3390 -0
  242. warp/native/noise.h +859 -0
  243. warp/native/quat.h +1664 -0
  244. warp/native/rand.h +342 -0
  245. warp/native/range.h +145 -0
  246. warp/native/reduce.cpp +174 -0
  247. warp/native/reduce.cu +363 -0
  248. warp/native/runlength_encode.cpp +79 -0
  249. warp/native/runlength_encode.cu +61 -0
  250. warp/native/scan.cpp +47 -0
  251. warp/native/scan.cu +55 -0
  252. warp/native/scan.h +23 -0
  253. warp/native/solid_angle.h +466 -0
  254. warp/native/sort.cpp +251 -0
  255. warp/native/sort.cu +286 -0
  256. warp/native/sort.h +35 -0
  257. warp/native/sparse.cpp +241 -0
  258. warp/native/sparse.cu +435 -0
  259. warp/native/spatial.h +1306 -0
  260. warp/native/svd.h +727 -0
  261. warp/native/temp_buffer.h +46 -0
  262. warp/native/tile.h +4124 -0
  263. warp/native/tile_radix_sort.h +1112 -0
  264. warp/native/tile_reduce.h +838 -0
  265. warp/native/tile_scan.h +240 -0
  266. warp/native/tuple.h +189 -0
  267. warp/native/vec.h +2199 -0
  268. warp/native/version.h +23 -0
  269. warp/native/volume.cpp +501 -0
  270. warp/native/volume.cu +68 -0
  271. warp/native/volume.h +970 -0
  272. warp/native/volume_builder.cu +483 -0
  273. warp/native/volume_builder.h +52 -0
  274. warp/native/volume_impl.h +70 -0
  275. warp/native/warp.cpp +1143 -0
  276. warp/native/warp.cu +4604 -0
  277. warp/native/warp.h +358 -0
  278. warp/optim/__init__.py +20 -0
  279. warp/optim/adam.py +24 -0
  280. warp/optim/linear.py +35 -0
  281. warp/optim/sgd.py +24 -0
  282. warp/paddle.py +24 -0
  283. warp/py.typed +0 -0
  284. warp/render/__init__.py +22 -0
  285. warp/render/imgui_manager.py +29 -0
  286. warp/render/render_opengl.py +24 -0
  287. warp/render/render_usd.py +24 -0
  288. warp/render/utils.py +24 -0
  289. warp/sparse.py +51 -0
  290. warp/tape.py +24 -0
  291. warp/tests/__init__.py +1 -0
  292. warp/tests/__main__.py +4 -0
  293. warp/tests/assets/curlnoise_golden.npy +0 -0
  294. warp/tests/assets/mlp_golden.npy +0 -0
  295. warp/tests/assets/pixel.npy +0 -0
  296. warp/tests/assets/pnoise_golden.npy +0 -0
  297. warp/tests/assets/spiky.usd +0 -0
  298. warp/tests/assets/test_grid.nvdb +0 -0
  299. warp/tests/assets/test_index_grid.nvdb +0 -0
  300. warp/tests/assets/test_int32_grid.nvdb +0 -0
  301. warp/tests/assets/test_vec_grid.nvdb +0 -0
  302. warp/tests/assets/torus.nvdb +0 -0
  303. warp/tests/assets/torus.usda +105 -0
  304. warp/tests/aux_test_class_kernel.py +34 -0
  305. warp/tests/aux_test_compile_consts_dummy.py +18 -0
  306. warp/tests/aux_test_conditional_unequal_types_kernels.py +29 -0
  307. warp/tests/aux_test_dependent.py +29 -0
  308. warp/tests/aux_test_grad_customs.py +29 -0
  309. warp/tests/aux_test_instancing_gc.py +26 -0
  310. warp/tests/aux_test_module_aot.py +7 -0
  311. warp/tests/aux_test_module_unload.py +23 -0
  312. warp/tests/aux_test_name_clash1.py +40 -0
  313. warp/tests/aux_test_name_clash2.py +40 -0
  314. warp/tests/aux_test_reference.py +9 -0
  315. warp/tests/aux_test_reference_reference.py +8 -0
  316. warp/tests/aux_test_square.py +16 -0
  317. warp/tests/aux_test_unresolved_func.py +22 -0
  318. warp/tests/aux_test_unresolved_symbol.py +22 -0
  319. warp/tests/cuda/__init__.py +0 -0
  320. warp/tests/cuda/test_async.py +676 -0
  321. warp/tests/cuda/test_conditional_captures.py +1147 -0
  322. warp/tests/cuda/test_ipc.py +124 -0
  323. warp/tests/cuda/test_mempool.py +233 -0
  324. warp/tests/cuda/test_multigpu.py +169 -0
  325. warp/tests/cuda/test_peer.py +139 -0
  326. warp/tests/cuda/test_pinned.py +84 -0
  327. warp/tests/cuda/test_streams.py +691 -0
  328. warp/tests/geometry/__init__.py +0 -0
  329. warp/tests/geometry/test_bvh.py +335 -0
  330. warp/tests/geometry/test_hash_grid.py +259 -0
  331. warp/tests/geometry/test_marching_cubes.py +294 -0
  332. warp/tests/geometry/test_mesh.py +318 -0
  333. warp/tests/geometry/test_mesh_query_aabb.py +392 -0
  334. warp/tests/geometry/test_mesh_query_point.py +935 -0
  335. warp/tests/geometry/test_mesh_query_ray.py +323 -0
  336. warp/tests/geometry/test_volume.py +1103 -0
  337. warp/tests/geometry/test_volume_write.py +346 -0
  338. warp/tests/interop/__init__.py +0 -0
  339. warp/tests/interop/test_dlpack.py +730 -0
  340. warp/tests/interop/test_jax.py +1673 -0
  341. warp/tests/interop/test_paddle.py +800 -0
  342. warp/tests/interop/test_torch.py +1001 -0
  343. warp/tests/run_coverage_serial.py +39 -0
  344. warp/tests/test_adam.py +162 -0
  345. warp/tests/test_arithmetic.py +1096 -0
  346. warp/tests/test_array.py +3756 -0
  347. warp/tests/test_array_reduce.py +156 -0
  348. warp/tests/test_assert.py +303 -0
  349. warp/tests/test_atomic.py +336 -0
  350. warp/tests/test_atomic_bitwise.py +209 -0
  351. warp/tests/test_atomic_cas.py +312 -0
  352. warp/tests/test_bool.py +220 -0
  353. warp/tests/test_builtins_resolution.py +732 -0
  354. warp/tests/test_closest_point_edge_edge.py +327 -0
  355. warp/tests/test_codegen.py +974 -0
  356. warp/tests/test_codegen_instancing.py +1495 -0
  357. warp/tests/test_compile_consts.py +215 -0
  358. warp/tests/test_conditional.py +298 -0
  359. warp/tests/test_context.py +35 -0
  360. warp/tests/test_copy.py +319 -0
  361. warp/tests/test_ctypes.py +618 -0
  362. warp/tests/test_dense.py +73 -0
  363. warp/tests/test_devices.py +127 -0
  364. warp/tests/test_enum.py +136 -0
  365. warp/tests/test_examples.py +424 -0
  366. warp/tests/test_fabricarray.py +998 -0
  367. warp/tests/test_fast_math.py +72 -0
  368. warp/tests/test_fem.py +2204 -0
  369. warp/tests/test_fixedarray.py +229 -0
  370. warp/tests/test_fp16.py +136 -0
  371. warp/tests/test_func.py +501 -0
  372. warp/tests/test_future_annotations.py +100 -0
  373. warp/tests/test_generics.py +656 -0
  374. warp/tests/test_grad.py +893 -0
  375. warp/tests/test_grad_customs.py +339 -0
  376. warp/tests/test_grad_debug.py +341 -0
  377. warp/tests/test_implicit_init.py +411 -0
  378. warp/tests/test_import.py +45 -0
  379. warp/tests/test_indexedarray.py +1140 -0
  380. warp/tests/test_intersect.py +103 -0
  381. warp/tests/test_iter.py +76 -0
  382. warp/tests/test_large.py +177 -0
  383. warp/tests/test_launch.py +411 -0
  384. warp/tests/test_lerp.py +151 -0
  385. warp/tests/test_linear_solvers.py +223 -0
  386. warp/tests/test_lvalue.py +427 -0
  387. warp/tests/test_map.py +526 -0
  388. warp/tests/test_mat.py +3515 -0
  389. warp/tests/test_mat_assign_copy.py +178 -0
  390. warp/tests/test_mat_constructors.py +573 -0
  391. warp/tests/test_mat_lite.py +122 -0
  392. warp/tests/test_mat_scalar_ops.py +2913 -0
  393. warp/tests/test_math.py +212 -0
  394. warp/tests/test_module_aot.py +287 -0
  395. warp/tests/test_module_hashing.py +258 -0
  396. warp/tests/test_modules_lite.py +70 -0
  397. warp/tests/test_noise.py +252 -0
  398. warp/tests/test_operators.py +299 -0
  399. warp/tests/test_options.py +129 -0
  400. warp/tests/test_overwrite.py +551 -0
  401. warp/tests/test_print.py +408 -0
  402. warp/tests/test_quat.py +2653 -0
  403. warp/tests/test_quat_assign_copy.py +145 -0
  404. warp/tests/test_rand.py +339 -0
  405. warp/tests/test_reload.py +303 -0
  406. warp/tests/test_rounding.py +157 -0
  407. warp/tests/test_runlength_encode.py +196 -0
  408. warp/tests/test_scalar_ops.py +133 -0
  409. warp/tests/test_smoothstep.py +108 -0
  410. warp/tests/test_snippet.py +318 -0
  411. warp/tests/test_sparse.py +845 -0
  412. warp/tests/test_spatial.py +2859 -0
  413. warp/tests/test_spatial_assign_copy.py +160 -0
  414. warp/tests/test_special_values.py +361 -0
  415. warp/tests/test_static.py +640 -0
  416. warp/tests/test_struct.py +901 -0
  417. warp/tests/test_tape.py +242 -0
  418. warp/tests/test_transient_module.py +93 -0
  419. warp/tests/test_triangle_closest_point.py +192 -0
  420. warp/tests/test_tuple.py +361 -0
  421. warp/tests/test_types.py +615 -0
  422. warp/tests/test_utils.py +594 -0
  423. warp/tests/test_vec.py +1408 -0
  424. warp/tests/test_vec_assign_copy.py +143 -0
  425. warp/tests/test_vec_constructors.py +325 -0
  426. warp/tests/test_vec_lite.py +80 -0
  427. warp/tests/test_vec_scalar_ops.py +2327 -0
  428. warp/tests/test_verify_fp.py +100 -0
  429. warp/tests/test_version.py +75 -0
  430. warp/tests/tile/__init__.py +0 -0
  431. warp/tests/tile/test_tile.py +1519 -0
  432. warp/tests/tile/test_tile_atomic_bitwise.py +403 -0
  433. warp/tests/tile/test_tile_cholesky.py +608 -0
  434. warp/tests/tile/test_tile_load.py +724 -0
  435. warp/tests/tile/test_tile_mathdx.py +156 -0
  436. warp/tests/tile/test_tile_matmul.py +179 -0
  437. warp/tests/tile/test_tile_mlp.py +400 -0
  438. warp/tests/tile/test_tile_reduce.py +950 -0
  439. warp/tests/tile/test_tile_shared_memory.py +376 -0
  440. warp/tests/tile/test_tile_sort.py +121 -0
  441. warp/tests/tile/test_tile_view.py +173 -0
  442. warp/tests/unittest_serial.py +47 -0
  443. warp/tests/unittest_suites.py +430 -0
  444. warp/tests/unittest_utils.py +469 -0
  445. warp/tests/walkthrough_debug.py +95 -0
  446. warp/torch.py +24 -0
  447. warp/types.py +51 -0
  448. warp/utils.py +31 -0
  449. warp_lang-1.10.0.dist-info/METADATA +459 -0
  450. warp_lang-1.10.0.dist-info/RECORD +468 -0
  451. warp_lang-1.10.0.dist-info/WHEEL +5 -0
  452. warp_lang-1.10.0.dist-info/licenses/LICENSE.md +176 -0
  453. warp_lang-1.10.0.dist-info/licenses/licenses/Gaia-LICENSE.txt +6 -0
  454. warp_lang-1.10.0.dist-info/licenses/licenses/appdirs-LICENSE.txt +22 -0
  455. warp_lang-1.10.0.dist-info/licenses/licenses/asset_pixel_jpg-LICENSE.txt +3 -0
  456. warp_lang-1.10.0.dist-info/licenses/licenses/cuda-LICENSE.txt +1582 -0
  457. warp_lang-1.10.0.dist-info/licenses/licenses/dlpack-LICENSE.txt +201 -0
  458. warp_lang-1.10.0.dist-info/licenses/licenses/fp16-LICENSE.txt +28 -0
  459. warp_lang-1.10.0.dist-info/licenses/licenses/libmathdx-LICENSE.txt +220 -0
  460. warp_lang-1.10.0.dist-info/licenses/licenses/llvm-LICENSE.txt +279 -0
  461. warp_lang-1.10.0.dist-info/licenses/licenses/moller-LICENSE.txt +16 -0
  462. warp_lang-1.10.0.dist-info/licenses/licenses/nanovdb-LICENSE.txt +2 -0
  463. warp_lang-1.10.0.dist-info/licenses/licenses/nvrtc-LICENSE.txt +1592 -0
  464. warp_lang-1.10.0.dist-info/licenses/licenses/svd-LICENSE.txt +23 -0
  465. warp_lang-1.10.0.dist-info/licenses/licenses/unittest_parallel-LICENSE.txt +21 -0
  466. warp_lang-1.10.0.dist-info/licenses/licenses/usd-LICENSE.txt +213 -0
  467. warp_lang-1.10.0.dist-info/licenses/licenses/windingnumber-LICENSE.txt +21 -0
  468. warp_lang-1.10.0.dist-info/top_level.txt +1 -0
warp/tests/test_vec.py ADDED
@@ -0,0 +1,1408 @@
1
+ # SPDX-FileCopyrightText: Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2
+ # SPDX-License-Identifier: Apache-2.0
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ import unittest
17
+ from typing import Any
18
+
19
+ import numpy as np
20
+
21
+ import warp as wp
22
+ from warp.tests.unittest_utils import *
23
+
24
+ np_signed_int_types = [
25
+ np.int8,
26
+ np.int16,
27
+ np.int32,
28
+ np.int64,
29
+ np.byte,
30
+ ]
31
+
32
+ np_unsigned_int_types = [
33
+ np.uint8,
34
+ np.uint16,
35
+ np.uint32,
36
+ np.uint64,
37
+ np.ubyte,
38
+ ]
39
+
40
+ np_float_types = [np.float16, np.float32, np.float64]
41
+
42
+
43
+ def randvals(rng, shape, dtype):
44
+ if dtype in np_float_types:
45
+ return rng.standard_normal(size=shape).astype(dtype)
46
+ elif dtype in [np.int8, np.uint8, np.byte, np.ubyte]:
47
+ return rng.integers(1, high=3, size=shape, dtype=dtype)
48
+ return rng.integers(1, high=5, size=shape, dtype=dtype)
49
+
50
+
51
+ kernel_cache = {}
52
+
53
+
54
+ def getkernel(func, suffix=""):
55
+ key = func.__name__ + "_" + suffix
56
+ if key not in kernel_cache:
57
+ kernel_cache[key] = wp.Kernel(func=func, key=key)
58
+ return kernel_cache[key]
59
+
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
+
77
+ def test_negation(test, device, dtype, register_kernels=False):
78
+ rng = np.random.default_rng(123)
79
+
80
+ tol = {
81
+ np.float16: 5.0e-3,
82
+ np.float32: 1.0e-6,
83
+ np.float64: 1.0e-8,
84
+ }.get(dtype, 0)
85
+
86
+ wptype = wp._src.types.np_dtype_to_warp_type[np.dtype(dtype)]
87
+ vec2 = wp._src.types.vector(length=2, dtype=wptype)
88
+ vec3 = wp._src.types.vector(length=3, dtype=wptype)
89
+ vec4 = wp._src.types.vector(length=4, dtype=wptype)
90
+ vec5 = wp._src.types.vector(length=5, dtype=wptype)
91
+
92
+ def check_negation(
93
+ v2: wp.array(dtype=vec2),
94
+ v3: wp.array(dtype=vec3),
95
+ v4: wp.array(dtype=vec4),
96
+ v5: wp.array(dtype=vec5),
97
+ v2out: wp.array(dtype=vec2),
98
+ v3out: wp.array(dtype=vec3),
99
+ v4out: wp.array(dtype=vec4),
100
+ v5out: wp.array(dtype=vec5),
101
+ v20: wp.array(dtype=wptype),
102
+ v21: wp.array(dtype=wptype),
103
+ v30: wp.array(dtype=wptype),
104
+ v31: wp.array(dtype=wptype),
105
+ v32: wp.array(dtype=wptype),
106
+ v40: wp.array(dtype=wptype),
107
+ v41: wp.array(dtype=wptype),
108
+ v42: wp.array(dtype=wptype),
109
+ v43: wp.array(dtype=wptype),
110
+ v50: wp.array(dtype=wptype),
111
+ v51: wp.array(dtype=wptype),
112
+ v52: wp.array(dtype=wptype),
113
+ v53: wp.array(dtype=wptype),
114
+ v54: wp.array(dtype=wptype),
115
+ ):
116
+ v2result = -v2[0]
117
+ v3result = -v3[0]
118
+ v4result = -v4[0]
119
+ v5result = -v5[0]
120
+
121
+ v2out[0] = v2result
122
+ v3out[0] = v3result
123
+ v4out[0] = v4result
124
+ v5out[0] = v5result
125
+
126
+ # multiply these outputs by 2 so we've got something to backpropagate:
127
+ v20[0] = wptype(2) * v2result[0]
128
+ v21[0] = wptype(2) * v2result[1]
129
+
130
+ v30[0] = wptype(2) * v3result[0]
131
+ v31[0] = wptype(2) * v3result[1]
132
+ v32[0] = wptype(2) * v3result[2]
133
+
134
+ v40[0] = wptype(2) * v4result[0]
135
+ v41[0] = wptype(2) * v4result[1]
136
+ v42[0] = wptype(2) * v4result[2]
137
+ v43[0] = wptype(2) * v4result[3]
138
+
139
+ v50[0] = wptype(2) * v5result[0]
140
+ v51[0] = wptype(2) * v5result[1]
141
+ v52[0] = wptype(2) * v5result[2]
142
+ v53[0] = wptype(2) * v5result[3]
143
+ v54[0] = wptype(2) * v5result[4]
144
+
145
+ kernel = getkernel(check_negation, suffix=dtype.__name__)
146
+
147
+ if register_kernels:
148
+ return
149
+
150
+ v2 = wp.array(randvals(rng, (1, 2), dtype), dtype=vec2, requires_grad=True, device=device)
151
+ v3 = wp.array(randvals(rng, (1, 3), dtype), dtype=vec3, requires_grad=True, device=device)
152
+ v4 = wp.array(randvals(rng, (1, 4), dtype), dtype=vec4, requires_grad=True, device=device)
153
+ v5_np = randvals(rng, (1, 5), dtype)
154
+ v5 = wp.array(v5_np, dtype=vec5, requires_grad=True, device=device)
155
+
156
+ v2out = wp.zeros(1, dtype=vec2, device=device)
157
+ v3out = wp.zeros(1, dtype=vec3, device=device)
158
+ v4out = wp.zeros(1, dtype=vec4, device=device)
159
+ v5out = wp.zeros(1, dtype=vec5, device=device)
160
+ v20 = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
161
+ v21 = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
162
+ v30 = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
163
+ v31 = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
164
+ v32 = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
165
+ v40 = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
166
+ v41 = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
167
+ v42 = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
168
+ v43 = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
169
+ v50 = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
170
+ v51 = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
171
+ v52 = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
172
+ v53 = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
173
+ v54 = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
174
+
175
+ tape = wp.Tape()
176
+ with tape:
177
+ wp.launch(
178
+ kernel,
179
+ dim=1,
180
+ inputs=[v2, v3, v4, v5],
181
+ outputs=[v2out, v3out, v4out, v5out, v20, v21, v30, v31, v32, v40, v41, v42, v43, v50, v51, v52, v53, v54],
182
+ device=device,
183
+ )
184
+
185
+ if dtype in np_float_types:
186
+ for i, l in enumerate([v20, v21, v30, v31, v32, v40, v41, v42, v43, v50, v51, v52, v53, v54]):
187
+ tape.backward(loss=l)
188
+ allgrads = np.concatenate([tape.gradients[v].numpy()[0] for v in [v2, v3, v4, v5]])
189
+ expected_grads = np.zeros_like(allgrads)
190
+ expected_grads[i] = -2
191
+ assert_np_equal(allgrads, expected_grads, tol=tol)
192
+ tape.zero()
193
+
194
+ assert_np_equal(v2out.numpy()[0], -v2.numpy()[0], tol=tol)
195
+ assert_np_equal(v3out.numpy()[0], -v3.numpy()[0], tol=tol)
196
+ assert_np_equal(v4out.numpy()[0], -v4.numpy()[0], tol=tol)
197
+ assert_np_equal(v5out.numpy()[0], -v5.numpy()[0], tol=tol)
198
+
199
+
200
+ def test_subtraction_unsigned(test, device, dtype, register_kernels=False):
201
+ wptype = wp._src.types.np_dtype_to_warp_type[np.dtype(dtype)]
202
+ vec2 = wp._src.types.vector(length=2, dtype=wptype)
203
+ vec3 = wp._src.types.vector(length=3, dtype=wptype)
204
+ vec4 = wp._src.types.vector(length=4, dtype=wptype)
205
+ vec5 = wp._src.types.vector(length=5, dtype=wptype)
206
+
207
+ def check_subtraction_unsigned():
208
+ wp.expect_eq(vec2(wptype(3), wptype(4)) - vec2(wptype(1), wptype(2)), vec2(wptype(2), wptype(2)))
209
+ wp.expect_eq(
210
+ vec3(wptype(3), wptype(4), wptype(4)) - vec3(wptype(1), wptype(2), wptype(3)),
211
+ vec3(wptype(2), wptype(2), wptype(1)),
212
+ )
213
+ wp.expect_eq(
214
+ vec4(wptype(3), wptype(4), wptype(4), wptype(5)) - vec4(wptype(1), wptype(2), wptype(3), wptype(4)),
215
+ vec4(wptype(2), wptype(2), wptype(1), wptype(1)),
216
+ )
217
+ wp.expect_eq(
218
+ vec5(wptype(3), wptype(4), wptype(4), wptype(5), wptype(4))
219
+ - vec5(wptype(1), wptype(2), wptype(3), wptype(4), wptype(4)),
220
+ vec5(wptype(2), wptype(2), wptype(1), wptype(1), wptype(0)),
221
+ )
222
+
223
+ kernel = getkernel(check_subtraction_unsigned, suffix=dtype.__name__)
224
+
225
+ if register_kernels:
226
+ return
227
+
228
+ wp.launch(kernel, dim=1, inputs=[], outputs=[], device=device)
229
+
230
+
231
+ def test_subtraction(test, device, dtype, register_kernels=False):
232
+ rng = np.random.default_rng(123)
233
+
234
+ tol = {
235
+ np.float16: 5.0e-3,
236
+ np.float32: 1.0e-6,
237
+ np.float64: 1.0e-8,
238
+ }.get(dtype, 0)
239
+
240
+ wptype = wp._src.types.np_dtype_to_warp_type[np.dtype(dtype)]
241
+ vec2 = wp._src.types.vector(length=2, dtype=wptype)
242
+ vec3 = wp._src.types.vector(length=3, dtype=wptype)
243
+ vec4 = wp._src.types.vector(length=4, dtype=wptype)
244
+ vec5 = wp._src.types.vector(length=5, dtype=wptype)
245
+
246
+ def check_subtraction(
247
+ s2: wp.array(dtype=vec2),
248
+ s3: wp.array(dtype=vec3),
249
+ s4: wp.array(dtype=vec4),
250
+ s5: wp.array(dtype=vec5),
251
+ v2: wp.array(dtype=vec2),
252
+ v3: wp.array(dtype=vec3),
253
+ v4: wp.array(dtype=vec4),
254
+ v5: wp.array(dtype=vec5),
255
+ v20: wp.array(dtype=wptype),
256
+ v21: wp.array(dtype=wptype),
257
+ v30: wp.array(dtype=wptype),
258
+ v31: wp.array(dtype=wptype),
259
+ v32: wp.array(dtype=wptype),
260
+ v40: wp.array(dtype=wptype),
261
+ v41: wp.array(dtype=wptype),
262
+ v42: wp.array(dtype=wptype),
263
+ v43: wp.array(dtype=wptype),
264
+ v50: wp.array(dtype=wptype),
265
+ v51: wp.array(dtype=wptype),
266
+ v52: wp.array(dtype=wptype),
267
+ v53: wp.array(dtype=wptype),
268
+ v54: wp.array(dtype=wptype),
269
+ ):
270
+ v2result = v2[0] - s2[0]
271
+ v3result = v3[0] - s3[0]
272
+ v4result = v4[0] - s4[0]
273
+ v5result = v5[0] - s5[0]
274
+
275
+ # multiply outputs by 2 so there's something to backpropagate:
276
+ v20[0] = wptype(2) * v2result[0]
277
+ v21[0] = wptype(2) * v2result[1]
278
+
279
+ v30[0] = wptype(2) * v3result[0]
280
+ v31[0] = wptype(2) * v3result[1]
281
+ v32[0] = wptype(2) * v3result[2]
282
+
283
+ v40[0] = wptype(2) * v4result[0]
284
+ v41[0] = wptype(2) * v4result[1]
285
+ v42[0] = wptype(2) * v4result[2]
286
+ v43[0] = wptype(2) * v4result[3]
287
+
288
+ v50[0] = wptype(2) * v5result[0]
289
+ v51[0] = wptype(2) * v5result[1]
290
+ v52[0] = wptype(2) * v5result[2]
291
+ v53[0] = wptype(2) * v5result[3]
292
+ v54[0] = wptype(2) * v5result[4]
293
+
294
+ kernel = getkernel(check_subtraction, suffix=dtype.__name__)
295
+
296
+ if register_kernels:
297
+ return
298
+
299
+ s2 = wp.array(randvals(rng, (1, 2), dtype), dtype=vec2, requires_grad=True, device=device)
300
+ s3 = wp.array(randvals(rng, (1, 3), dtype), dtype=vec3, requires_grad=True, device=device)
301
+ s4 = wp.array(randvals(rng, (1, 4), dtype), dtype=vec4, requires_grad=True, device=device)
302
+ s5 = wp.array(randvals(rng, (1, 5), dtype), dtype=vec5, requires_grad=True, device=device)
303
+ v2 = wp.array(randvals(rng, (1, 2), dtype), dtype=vec2, requires_grad=True, device=device)
304
+ v3 = wp.array(randvals(rng, (1, 3), dtype), dtype=vec3, requires_grad=True, device=device)
305
+ v4 = wp.array(randvals(rng, (1, 4), dtype), dtype=vec4, requires_grad=True, device=device)
306
+ v5 = wp.array(randvals(rng, (1, 5), dtype), dtype=vec5, requires_grad=True, device=device)
307
+ v20 = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
308
+ v21 = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
309
+ v30 = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
310
+ v31 = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
311
+ v32 = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
312
+ v40 = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
313
+ v41 = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
314
+ v42 = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
315
+ v43 = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
316
+ v50 = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
317
+ v51 = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
318
+ v52 = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
319
+ v53 = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
320
+ v54 = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
321
+ tape = wp.Tape()
322
+ with tape:
323
+ wp.launch(
324
+ kernel,
325
+ dim=1,
326
+ inputs=[s2, s3, s4, s5, v2, v3, v4, v5],
327
+ outputs=[v20, v21, v30, v31, v32, v40, v41, v42, v43, v50, v51, v52, v53, v54],
328
+ device=device,
329
+ )
330
+
331
+ assert_np_equal(v20.numpy()[0], 2 * (v2.numpy()[0, 0] - s2.numpy()[0, 0]), tol=tol)
332
+ assert_np_equal(v21.numpy()[0], 2 * (v2.numpy()[0, 1] - s2.numpy()[0, 1]), tol=tol)
333
+
334
+ assert_np_equal(v30.numpy()[0], 2 * (v3.numpy()[0, 0] - s3.numpy()[0, 0]), tol=tol)
335
+ assert_np_equal(v31.numpy()[0], 2 * (v3.numpy()[0, 1] - s3.numpy()[0, 1]), tol=tol)
336
+ assert_np_equal(v32.numpy()[0], 2 * (v3.numpy()[0, 2] - s3.numpy()[0, 2]), tol=tol)
337
+
338
+ assert_np_equal(v40.numpy()[0], 2 * (v4.numpy()[0, 0] - s4.numpy()[0, 0]), tol=2 * tol)
339
+ assert_np_equal(v41.numpy()[0], 2 * (v4.numpy()[0, 1] - s4.numpy()[0, 1]), tol=2 * tol)
340
+ assert_np_equal(v42.numpy()[0], 2 * (v4.numpy()[0, 2] - s4.numpy()[0, 2]), tol=2 * tol)
341
+ assert_np_equal(v43.numpy()[0], 2 * (v4.numpy()[0, 3] - s4.numpy()[0, 3]), tol=2 * tol)
342
+
343
+ assert_np_equal(v50.numpy()[0], 2 * (v5.numpy()[0, 0] - s5.numpy()[0, 0]), tol=tol)
344
+ assert_np_equal(v51.numpy()[0], 2 * (v5.numpy()[0, 1] - s5.numpy()[0, 1]), tol=tol)
345
+ assert_np_equal(v52.numpy()[0], 2 * (v5.numpy()[0, 2] - s5.numpy()[0, 2]), tol=tol)
346
+ assert_np_equal(v53.numpy()[0], 2 * (v5.numpy()[0, 3] - s5.numpy()[0, 3]), tol=tol)
347
+ assert_np_equal(v54.numpy()[0], 2 * (v5.numpy()[0, 4] - s5.numpy()[0, 4]), tol=tol)
348
+
349
+ if dtype in np_float_types:
350
+ for i, l in enumerate([v20, v21, v30, v31, v32, v40, v41, v42, v43, v50, v51, v52, v53, v54]):
351
+ tape.backward(loss=l)
352
+ sgrads = np.concatenate([tape.gradients[v].numpy()[0] for v in [s2, s3, s4, s5]])
353
+ expected_grads = np.zeros_like(sgrads)
354
+
355
+ expected_grads[i] = -2
356
+ assert_np_equal(sgrads, expected_grads, tol=10 * tol)
357
+
358
+ allgrads = np.concatenate([tape.gradients[v].numpy()[0] for v in [v2, v3, v4, v5]])
359
+ expected_grads = np.zeros_like(allgrads)
360
+
361
+ # d/dv v/s = 1/s
362
+ expected_grads[i] = 2
363
+ assert_np_equal(allgrads, expected_grads, tol=tol)
364
+
365
+ tape.zero()
366
+
367
+
368
+ def test_length(test, device, dtype, register_kernels=False):
369
+ rng = np.random.default_rng(123)
370
+
371
+ tol = {
372
+ np.float16: 5.0e-3,
373
+ np.float32: 1.0e-6,
374
+ np.float64: 1.0e-7,
375
+ }.get(dtype, 0)
376
+
377
+ wptype = wp._src.types.np_dtype_to_warp_type[np.dtype(dtype)]
378
+ vec2 = wp._src.types.vector(length=2, dtype=wptype)
379
+ vec3 = wp._src.types.vector(length=3, dtype=wptype)
380
+ vec4 = wp._src.types.vector(length=4, dtype=wptype)
381
+ vec5 = wp._src.types.vector(length=5, dtype=wptype)
382
+
383
+ def check_length(
384
+ v2: wp.array(dtype=vec2),
385
+ v3: wp.array(dtype=vec3),
386
+ v4: wp.array(dtype=vec4),
387
+ v5: wp.array(dtype=vec5),
388
+ l2: wp.array(dtype=wptype),
389
+ l3: wp.array(dtype=wptype),
390
+ l4: wp.array(dtype=wptype),
391
+ l5: wp.array(dtype=wptype),
392
+ l22: wp.array(dtype=wptype),
393
+ l23: wp.array(dtype=wptype),
394
+ l24: wp.array(dtype=wptype),
395
+ l25: wp.array(dtype=wptype),
396
+ ):
397
+ l2[0] = wptype(2) * wp.length(v2[0])
398
+ l3[0] = wptype(2) * wp.length(v3[0])
399
+ l4[0] = wptype(2) * wp.length(v4[0])
400
+ l5[0] = wptype(2) * wp.length(v5[0])
401
+
402
+ l22[0] = wptype(2) * wp.length_sq(v2[0])
403
+ l23[0] = wptype(2) * wp.length_sq(v3[0])
404
+ l24[0] = wptype(2) * wp.length_sq(v4[0])
405
+ l25[0] = wptype(2) * wp.length_sq(v5[0])
406
+
407
+ kernel = getkernel(check_length, suffix=dtype.__name__)
408
+
409
+ if register_kernels:
410
+ return
411
+
412
+ v2 = wp.array(randvals(rng, (1, 2), dtype), dtype=vec2, requires_grad=True, device=device)
413
+ v3 = wp.array(randvals(rng, (1, 3), dtype), dtype=vec3, requires_grad=True, device=device)
414
+ v4 = wp.array(randvals(rng, (1, 4), dtype), dtype=vec4, requires_grad=True, device=device)
415
+ v5 = wp.array(randvals(rng, (1, 5), dtype), dtype=vec5, requires_grad=True, device=device)
416
+
417
+ l2 = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
418
+ l3 = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
419
+ l4 = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
420
+ l5 = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
421
+
422
+ l22 = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
423
+ l23 = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
424
+ l24 = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
425
+ l25 = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
426
+
427
+ tape = wp.Tape()
428
+ with tape:
429
+ wp.launch(kernel, dim=1, inputs=[v2, v3, v4, v5], outputs=[l2, l3, l4, l5, l22, l23, l24, l25], device=device)
430
+
431
+ assert_np_equal(l2.numpy()[0], 2 * np.linalg.norm(v2.numpy()), tol=10 * tol)
432
+ assert_np_equal(l3.numpy()[0], 2 * np.linalg.norm(v3.numpy()), tol=10 * tol)
433
+ assert_np_equal(l4.numpy()[0], 2 * np.linalg.norm(v4.numpy()), tol=10 * tol)
434
+ assert_np_equal(l5.numpy()[0], 2 * np.linalg.norm(v5.numpy()), tol=10 * tol)
435
+
436
+ assert_np_equal(l22.numpy()[0], 2 * np.linalg.norm(v2.numpy()) ** 2, tol=10 * tol)
437
+ assert_np_equal(l23.numpy()[0], 2 * np.linalg.norm(v3.numpy()) ** 2, tol=10 * tol)
438
+ assert_np_equal(l24.numpy()[0], 2 * np.linalg.norm(v4.numpy()) ** 2, tol=10 * tol)
439
+ assert_np_equal(l25.numpy()[0], 2 * np.linalg.norm(v5.numpy()) ** 2, tol=10 * tol)
440
+
441
+ tape.backward(loss=l2)
442
+ grad = tape.gradients[v2].numpy()[0]
443
+ expected_grad = 2 * v2.numpy()[0] / np.linalg.norm(v2.numpy())
444
+ assert_np_equal(grad, expected_grad, tol=10 * tol)
445
+ tape.zero()
446
+
447
+ tape.backward(loss=l3)
448
+ grad = tape.gradients[v3].numpy()[0]
449
+ expected_grad = 2 * v3.numpy()[0] / np.linalg.norm(v3.numpy())
450
+ assert_np_equal(grad, expected_grad, tol=10 * tol)
451
+ tape.zero()
452
+
453
+ tape.backward(loss=l4)
454
+ grad = tape.gradients[v4].numpy()[0]
455
+ expected_grad = 2 * v4.numpy()[0] / np.linalg.norm(v4.numpy())
456
+ assert_np_equal(grad, expected_grad, tol=10 * tol)
457
+ tape.zero()
458
+
459
+ tape.backward(loss=l5)
460
+ grad = tape.gradients[v5].numpy()[0]
461
+ expected_grad = 2 * v5.numpy()[0] / np.linalg.norm(v5.numpy())
462
+ assert_np_equal(grad, expected_grad, tol=10 * tol)
463
+ tape.zero()
464
+
465
+ tape.backward(loss=l22)
466
+ grad = tape.gradients[v2].numpy()[0]
467
+ expected_grad = 4 * v2.numpy()[0]
468
+ assert_np_equal(grad, expected_grad, tol=10 * tol)
469
+ tape.zero()
470
+
471
+ tape.backward(loss=l23)
472
+ grad = tape.gradients[v3].numpy()[0]
473
+ expected_grad = 4 * v3.numpy()[0]
474
+ assert_np_equal(grad, expected_grad, tol=10 * tol)
475
+ tape.zero()
476
+
477
+ tape.backward(loss=l24)
478
+ grad = tape.gradients[v4].numpy()[0]
479
+ expected_grad = 4 * v4.numpy()[0]
480
+ assert_np_equal(grad, expected_grad, tol=10 * tol)
481
+ tape.zero()
482
+
483
+ tape.backward(loss=l25)
484
+ grad = tape.gradients[v5].numpy()[0]
485
+ expected_grad = 4 * v5.numpy()[0]
486
+ assert_np_equal(grad, expected_grad, tol=10 * tol)
487
+ tape.zero()
488
+
489
+
490
+ def test_normalize(test, device, dtype, register_kernels=False):
491
+ rng = np.random.default_rng(123)
492
+
493
+ tol = {
494
+ np.float16: 5.0e-3,
495
+ np.float32: 1.0e-6,
496
+ np.float64: 1.0e-8,
497
+ }.get(dtype, 0)
498
+
499
+ wptype = wp._src.types.np_dtype_to_warp_type[np.dtype(dtype)]
500
+ vec2 = wp._src.types.vector(length=2, dtype=wptype)
501
+ vec3 = wp._src.types.vector(length=3, dtype=wptype)
502
+ vec4 = wp._src.types.vector(length=4, dtype=wptype)
503
+ vec5 = wp._src.types.vector(length=5, dtype=wptype)
504
+
505
+ def check_normalize(
506
+ v2: wp.array(dtype=vec2),
507
+ v3: wp.array(dtype=vec3),
508
+ v4: wp.array(dtype=vec4),
509
+ v5: wp.array(dtype=vec5),
510
+ n20: wp.array(dtype=wptype),
511
+ n21: wp.array(dtype=wptype),
512
+ n30: wp.array(dtype=wptype),
513
+ n31: wp.array(dtype=wptype),
514
+ n32: wp.array(dtype=wptype),
515
+ n40: wp.array(dtype=wptype),
516
+ n41: wp.array(dtype=wptype),
517
+ n42: wp.array(dtype=wptype),
518
+ n43: wp.array(dtype=wptype),
519
+ n50: wp.array(dtype=wptype),
520
+ n51: wp.array(dtype=wptype),
521
+ n52: wp.array(dtype=wptype),
522
+ n53: wp.array(dtype=wptype),
523
+ n54: wp.array(dtype=wptype),
524
+ ):
525
+ n2 = wptype(2) * wp.normalize(v2[0])
526
+ n3 = wptype(2) * wp.normalize(v3[0])
527
+ n4 = wptype(2) * wp.normalize(v4[0])
528
+ n5 = wptype(2) * wp.normalize(v5[0])
529
+
530
+ n20[0] = n2[0]
531
+ n21[0] = n2[1]
532
+
533
+ n30[0] = n3[0]
534
+ n31[0] = n3[1]
535
+ n32[0] = n3[2]
536
+
537
+ n40[0] = n4[0]
538
+ n41[0] = n4[1]
539
+ n42[0] = n4[2]
540
+ n43[0] = n4[3]
541
+
542
+ n50[0] = n5[0]
543
+ n51[0] = n5[1]
544
+ n52[0] = n5[2]
545
+ n53[0] = n5[3]
546
+ n54[0] = n5[4]
547
+
548
+ def check_normalize_alt(
549
+ v2: wp.array(dtype=vec2),
550
+ v3: wp.array(dtype=vec3),
551
+ v4: wp.array(dtype=vec4),
552
+ v5: wp.array(dtype=vec5),
553
+ n20: wp.array(dtype=wptype),
554
+ n21: wp.array(dtype=wptype),
555
+ n30: wp.array(dtype=wptype),
556
+ n31: wp.array(dtype=wptype),
557
+ n32: wp.array(dtype=wptype),
558
+ n40: wp.array(dtype=wptype),
559
+ n41: wp.array(dtype=wptype),
560
+ n42: wp.array(dtype=wptype),
561
+ n43: wp.array(dtype=wptype),
562
+ n50: wp.array(dtype=wptype),
563
+ n51: wp.array(dtype=wptype),
564
+ n52: wp.array(dtype=wptype),
565
+ n53: wp.array(dtype=wptype),
566
+ n54: wp.array(dtype=wptype),
567
+ ):
568
+ n2 = wptype(2) * v2[0] / wp.length(v2[0])
569
+ n3 = wptype(2) * v3[0] / wp.length(v3[0])
570
+ n4 = wptype(2) * v4[0] / wp.length(v4[0])
571
+ n5 = wptype(2) * v5[0] / wp.length(v5[0])
572
+
573
+ n20[0] = n2[0]
574
+ n21[0] = n2[1]
575
+
576
+ n30[0] = n3[0]
577
+ n31[0] = n3[1]
578
+ n32[0] = n3[2]
579
+
580
+ n40[0] = n4[0]
581
+ n41[0] = n4[1]
582
+ n42[0] = n4[2]
583
+ n43[0] = n4[3]
584
+
585
+ n50[0] = n5[0]
586
+ n51[0] = n5[1]
587
+ n52[0] = n5[2]
588
+ n53[0] = n5[3]
589
+ n54[0] = n5[4]
590
+
591
+ normalize_kernel = getkernel(check_normalize, suffix=dtype.__name__)
592
+ normalize_alt_kernel = getkernel(check_normalize_alt, suffix=dtype.__name__)
593
+
594
+ if register_kernels:
595
+ return
596
+
597
+ # I've already tested the things I'm using in check_normalize_alt, so I'll just
598
+ # make sure the two are giving the same results/gradients
599
+ v2 = wp.array(randvals(rng, (1, 2), dtype), dtype=vec2, requires_grad=True, device=device)
600
+ v3 = wp.array(randvals(rng, (1, 3), dtype), dtype=vec3, requires_grad=True, device=device)
601
+ v4 = wp.array(randvals(rng, (1, 4), dtype), dtype=vec4, requires_grad=True, device=device)
602
+ v5 = wp.array(randvals(rng, (1, 5), dtype), dtype=vec5, requires_grad=True, device=device)
603
+
604
+ n20 = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
605
+ n21 = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
606
+ n30 = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
607
+ n31 = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
608
+ n32 = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
609
+ n40 = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
610
+ n41 = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
611
+ n42 = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
612
+ n43 = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
613
+ n50 = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
614
+ n51 = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
615
+ n52 = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
616
+ n53 = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
617
+ n54 = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
618
+
619
+ n20_alt = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
620
+ n21_alt = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
621
+ n30_alt = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
622
+ n31_alt = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
623
+ n32_alt = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
624
+ n40_alt = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
625
+ n41_alt = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
626
+ n42_alt = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
627
+ n43_alt = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
628
+ n50_alt = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
629
+ n51_alt = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
630
+ n52_alt = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
631
+ n53_alt = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
632
+ n54_alt = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
633
+
634
+ outputs0 = [
635
+ n20,
636
+ n21,
637
+ n30,
638
+ n31,
639
+ n32,
640
+ n40,
641
+ n41,
642
+ n42,
643
+ n43,
644
+ n50,
645
+ n51,
646
+ n52,
647
+ n53,
648
+ n54,
649
+ ]
650
+ tape0 = wp.Tape()
651
+ with tape0:
652
+ wp.launch(normalize_kernel, dim=1, inputs=[v2, v3, v4, v5], outputs=outputs0, device=device)
653
+
654
+ outputs1 = [
655
+ n20_alt,
656
+ n21_alt,
657
+ n30_alt,
658
+ n31_alt,
659
+ n32_alt,
660
+ n40_alt,
661
+ n41_alt,
662
+ n42_alt,
663
+ n43_alt,
664
+ n50_alt,
665
+ n51_alt,
666
+ n52_alt,
667
+ n53_alt,
668
+ n54_alt,
669
+ ]
670
+ tape1 = wp.Tape()
671
+ with tape1:
672
+ wp.launch(
673
+ normalize_alt_kernel,
674
+ dim=1,
675
+ inputs=[
676
+ v2,
677
+ v3,
678
+ v4,
679
+ v5,
680
+ ],
681
+ outputs=outputs1,
682
+ device=device,
683
+ )
684
+
685
+ for ncmp, ncmpalt in zip(outputs0, outputs1):
686
+ assert_np_equal(ncmp.numpy()[0], ncmpalt.numpy()[0], tol=10 * tol)
687
+
688
+ invecs = [v2, v2, v3, v3, v3, v4, v4, v4, v4, v5, v5, v5, v5, v5]
689
+ for ncmp, ncmpalt, v in zip(outputs0, outputs1, invecs):
690
+ tape0.backward(loss=ncmp)
691
+ tape1.backward(loss=ncmpalt)
692
+ assert_np_equal(tape0.gradients[v].numpy()[0], tape1.gradients[v].numpy()[0], tol=10 * tol)
693
+ tape0.zero()
694
+ tape1.zero()
695
+
696
+
697
+ def test_crossproduct(test, device, dtype, register_kernels=False):
698
+ rng = np.random.default_rng(123)
699
+
700
+ tol = {
701
+ np.float16: 5.0e-3,
702
+ np.float32: 1.0e-6,
703
+ np.float64: 1.0e-8,
704
+ }.get(dtype, 0)
705
+
706
+ wptype = wp._src.types.np_dtype_to_warp_type[np.dtype(dtype)]
707
+ vec3 = wp._src.types.vector(length=3, dtype=wptype)
708
+
709
+ def check_cross(
710
+ s3: wp.array(dtype=vec3),
711
+ v3: wp.array(dtype=vec3),
712
+ c0: wp.array(dtype=wptype),
713
+ c1: wp.array(dtype=wptype),
714
+ c2: wp.array(dtype=wptype),
715
+ ):
716
+ c = wp.cross(s3[0], v3[0])
717
+
718
+ # multiply outputs by 2 so we've got something to backpropagate:
719
+ c0[0] = wptype(2) * c[0]
720
+ c1[0] = wptype(2) * c[1]
721
+ c2[0] = wptype(2) * c[2]
722
+
723
+ kernel = getkernel(check_cross, suffix=dtype.__name__)
724
+
725
+ if register_kernels:
726
+ return
727
+
728
+ s3 = wp.array(randvals(rng, (1, 3), dtype), dtype=vec3, requires_grad=True, device=device)
729
+ v3 = wp.array(randvals(rng, (1, 3), dtype), dtype=vec3, requires_grad=True, device=device)
730
+ c0 = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
731
+ c1 = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
732
+ c2 = wp.zeros(1, dtype=wptype, requires_grad=True, device=device)
733
+ tape = wp.Tape()
734
+ with tape:
735
+ wp.launch(
736
+ kernel,
737
+ dim=1,
738
+ inputs=[
739
+ s3,
740
+ v3,
741
+ ],
742
+ outputs=[c0, c1, c2],
743
+ device=device,
744
+ )
745
+
746
+ result = 2 * np.cross(s3.numpy(), v3.numpy())[0]
747
+ assert_np_equal(c0.numpy()[0], result[0], tol=10 * tol)
748
+ assert_np_equal(c1.numpy()[0], result[1], tol=10 * tol)
749
+ assert_np_equal(c2.numpy()[0], result[2], tol=10 * tol)
750
+
751
+ if dtype in np_float_types:
752
+ # c.x = sy vz - sz vy
753
+ # c.y = sz vx - sx vz
754
+ # c.z = sx vy - sy vx
755
+
756
+ # ( d/dsx d/dsy d/dsz )c.x = ( 0 vz -vy )
757
+ # ( d/dsx d/dsy d/dsz )c.y = ( -vz 0 vx )
758
+ # ( d/dsx d/dsy d/dsz )c.z = ( vy -vx 0 )
759
+
760
+ # ( d/dvx d/dvy d/dvz )c.x = (0 -sz sy)
761
+ # ( d/dvx d/dvy d/dvz )c.y = (sz 0 -sx)
762
+ # ( d/dvx d/dvy d/dvz )c.z = (-sy sx 0)
763
+
764
+ tape.backward(loss=c0)
765
+ assert_np_equal(
766
+ tape.gradients[s3].numpy(), 2.0 * np.array([0, v3.numpy()[0, 2], -v3.numpy()[0, 1]]), tol=10 * tol
767
+ )
768
+ assert_np_equal(
769
+ tape.gradients[v3].numpy(), 2.0 * np.array([0, -s3.numpy()[0, 2], s3.numpy()[0, 1]]), tol=10 * tol
770
+ )
771
+ tape.zero()
772
+
773
+ tape.backward(loss=c1)
774
+ assert_np_equal(
775
+ tape.gradients[s3].numpy(), 2.0 * np.array([-v3.numpy()[0, 2], 0, v3.numpy()[0, 0]]), tol=10 * tol
776
+ )
777
+ assert_np_equal(
778
+ tape.gradients[v3].numpy(), 2.0 * np.array([s3.numpy()[0, 2], 0, -s3.numpy()[0, 0]]), tol=10 * tol
779
+ )
780
+ tape.zero()
781
+
782
+ tape.backward(loss=c2)
783
+ assert_np_equal(
784
+ tape.gradients[s3].numpy(), 2.0 * np.array([v3.numpy()[0, 1], -v3.numpy()[0, 0], 0]), tol=10 * tol
785
+ )
786
+ assert_np_equal(
787
+ tape.gradients[v3].numpy(), 2.0 * np.array([-s3.numpy()[0, 1], s3.numpy()[0, 0], 0]), tol=10 * tol
788
+ )
789
+ tape.zero()
790
+
791
+
792
+ @wp.kernel(module="unique")
793
+ def test_vector_mutation(expected: wp._src.types.vector(length=10, dtype=float)):
794
+ v = wp.vector(length=10, dtype=float)
795
+
796
+ # test element indexing
797
+ v[0] = 1.0
798
+
799
+ for i in range(1, 10):
800
+ v[i] = float(i) + 1.0
801
+
802
+ wp.expect_eq(v, expected)
803
+
804
+
805
+ Vec123 = wp.vec(123, dtype=wp.float16)
806
+
807
+
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)):
810
+ length = wp.static(len(v1))
811
+ wp.expect_eq(len(v1), 2)
812
+ out[0] = len(v1)
813
+
814
+ length = len(v2)
815
+ wp.expect_eq(wp.static(len(v2)), 3)
816
+ out[1] = len(v2)
817
+
818
+ length = len(v3)
819
+ wp.expect_eq(len(v3), 4)
820
+ out[2] = wp.static(len(v3))
821
+
822
+ length = wp.static(len(v4))
823
+ wp.expect_eq(wp.static(len(v4)), 123)
824
+ out[3] = wp.static(len(v4))
825
+
826
+ foo = wp.vec2()
827
+ length = len(foo)
828
+ wp.expect_eq(len(foo), 2)
829
+ out[4] = len(foo)
830
+
831
+
832
+ def test_vector_len(test, device):
833
+ v1 = wp.vec2()
834
+ v2 = wp.vec3()
835
+ v3 = wp.vec4()
836
+ v4 = Vec123()
837
+ out = wp.empty(5, dtype=int, device=device)
838
+ wp.launch(vector_len_kernel, dim=(1,), inputs=(v1, v2, v3, v4), outputs=(out,), device=device)
839
+
840
+ test.assertEqual(out.numpy()[0], 2)
841
+ test.assertEqual(out.numpy()[1], 3)
842
+ test.assertEqual(out.numpy()[2], 4)
843
+ test.assertEqual(out.numpy()[3], 123)
844
+ test.assertEqual(out.numpy()[4], 2)
845
+
846
+
847
+ @wp.kernel
848
+ def vec_extract_subscript(x: wp.array(dtype=wp.vec3), y: wp.array(dtype=float)):
849
+ tid = wp.tid()
850
+
851
+ a = x[tid]
852
+ b = a[0] + 2.0 * a[1] + 3.0 * a[2]
853
+ y[tid] = b
854
+
855
+
856
+ @wp.kernel
857
+ def vec_extract_attribute(x: wp.array(dtype=wp.vec3), y: wp.array(dtype=float)):
858
+ tid = wp.tid()
859
+
860
+ a = x[tid]
861
+ b = a.x + float(2.0) * a.y + 3.0 * a.z
862
+ y[tid] = b
863
+
864
+
865
+ def test_vec_extract(test, device):
866
+ def run(kernel):
867
+ x = wp.ones(1, dtype=wp.vec3, requires_grad=True, device=device)
868
+ y = wp.zeros(1, dtype=float, requires_grad=True, device=device)
869
+
870
+ tape = wp.Tape()
871
+ with tape:
872
+ wp.launch(kernel, 1, inputs=[x], outputs=[y], device=device)
873
+
874
+ y.grad = wp.ones_like(y)
875
+ tape.backward()
876
+
877
+ assert_np_equal(y.numpy(), np.array([6.0], dtype=float))
878
+ assert_np_equal(x.grad.numpy(), np.array([[1.0, 2.0, 3.0]], dtype=float))
879
+
880
+ run(vec_extract_subscript)
881
+ run(vec_extract_attribute)
882
+
883
+
884
+ @wp.kernel
885
+ def vec_assign_subscript(x: wp.array(dtype=float), y: wp.array(dtype=wp.vec3)):
886
+ i = wp.tid()
887
+
888
+ a = wp.vec3()
889
+ a[0] = 1.0 * x[i]
890
+ a[1] = 2.0 * x[i]
891
+ a[2] = 3.0 * x[i]
892
+ y[i] = a
893
+
894
+
895
+ @wp.kernel
896
+ def vec_assign_attribute(x: wp.array(dtype=float), y: wp.array(dtype=wp.vec3)):
897
+ i = wp.tid()
898
+
899
+ a = wp.vec3()
900
+ a.x = 1.0 * x[i]
901
+ a.y = 2.0 * x[i]
902
+ a.z = 3.0 * x[i]
903
+ y[i] = a
904
+
905
+
906
+ def test_vec_assign(test, device):
907
+ def run(kernel):
908
+ x = wp.ones(1, dtype=float, requires_grad=True, device=device)
909
+ y = wp.zeros(1, dtype=wp.vec3, requires_grad=True, device=device)
910
+
911
+ tape = wp.Tape()
912
+ with tape:
913
+ wp.launch(kernel, 1, inputs=[x], outputs=[y], device=device)
914
+
915
+ y.grad = wp.ones_like(y)
916
+ tape.backward()
917
+
918
+ assert_np_equal(y.numpy(), np.array([[1.0, 2.0, 3.0]], dtype=float))
919
+ assert_np_equal(x.grad.numpy(), np.array([6.0], dtype=float))
920
+
921
+ run(vec_assign_subscript)
922
+ run(vec_assign_attribute)
923
+
924
+
925
+ @wp.kernel
926
+ def vec_array_extract_subscript(x: wp.array2d(dtype=wp.vec3), y: wp.array2d(dtype=float)):
927
+ i, j = wp.tid()
928
+ a = x[i, j][0]
929
+ b = x[i, j][1]
930
+ c = x[i, j][2]
931
+ y[i, j] = 1.0 * a + 2.0 * b + 3.0 * c
932
+
933
+
934
+ @wp.kernel
935
+ def vec_array_extract_attribute(x: wp.array2d(dtype=wp.vec3), y: wp.array2d(dtype=float)):
936
+ i, j = wp.tid()
937
+ a = x[i, j].x
938
+ b = x[i, j].y
939
+ c = x[i, j].z
940
+ y[i, j] = 1.0 * a + 2.0 * b + 3.0 * c
941
+
942
+
943
+ def test_vec_array_extract(test, device):
944
+ def run(kernel):
945
+ x = wp.ones((1, 1), dtype=wp.vec3, requires_grad=True, device=device)
946
+ y = wp.zeros((1, 1), dtype=float, requires_grad=True, device=device)
947
+
948
+ tape = wp.Tape()
949
+ with tape:
950
+ wp.launch(kernel, (1, 1), inputs=[x], outputs=[y], device=device)
951
+
952
+ y.grad = wp.ones_like(y)
953
+ tape.backward()
954
+
955
+ assert_np_equal(y.numpy(), np.array([[6.0]], dtype=float))
956
+ assert_np_equal(x.grad.numpy(), np.array([[[1.0, 2.0, 3.0]]], dtype=float))
957
+
958
+ run(vec_array_extract_subscript)
959
+ run(vec_array_extract_attribute)
960
+
961
+
962
+ @wp.kernel
963
+ def vec_array_assign_subscript(x: wp.array2d(dtype=float), y: wp.array2d(dtype=wp.vec3)):
964
+ i, j = wp.tid()
965
+
966
+ y[i, j][0] = 1.0 * x[i, j]
967
+ y[i, j][1] = 2.0 * x[i, j]
968
+ y[i, j][2] = 3.0 * x[i, j]
969
+
970
+
971
+ @wp.kernel
972
+ def vec_array_assign_attribute(x: wp.array2d(dtype=float), y: wp.array2d(dtype=wp.vec3)):
973
+ i, j = wp.tid()
974
+
975
+ y[i, j].x = 1.0 * x[i, j]
976
+ y[i, j].y = 2.0 * x[i, j]
977
+ y[i, j].z = 3.0 * x[i, j]
978
+
979
+
980
+ def test_vec_array_assign(test, device):
981
+ def run(kernel):
982
+ x = wp.ones((1, 1), dtype=float, requires_grad=True, device=device)
983
+ y = wp.zeros((1, 1), dtype=wp.vec3, requires_grad=True, device=device)
984
+
985
+ tape = wp.Tape()
986
+ with tape:
987
+ wp.launch(kernel, (1, 1), inputs=[x], outputs=[y], device=device)
988
+
989
+ y.grad = wp.ones_like(y)
990
+ tape.backward()
991
+
992
+ assert_np_equal(y.numpy(), np.array([[[1.0, 2.0, 3.0]]], dtype=float))
993
+ # TODO: gradient propagation for in-place array assignment
994
+ # assert_np_equal(x.grad.numpy(), np.array([[6.0]], dtype=float))
995
+
996
+ run(vec_array_assign_subscript)
997
+ run(vec_array_assign_attribute)
998
+
999
+
1000
+ @wp.kernel(module="unique")
1001
+ def vec_add_inplace_subscript(x: wp.array(dtype=wp.vec3), y: wp.array(dtype=wp.vec3)):
1002
+ i = wp.tid()
1003
+
1004
+ a = wp.vec3()
1005
+ b = x[i]
1006
+
1007
+ a[0] += 1.0 * b[0]
1008
+ a[1] += 2.0 * b[1]
1009
+ a[2] += 3.0 * b[2]
1010
+
1011
+ y[i] = a
1012
+
1013
+
1014
+ @wp.kernel(module="unique")
1015
+ def vec_add_inplace_attribute(x: wp.array(dtype=wp.vec3), y: wp.array(dtype=wp.vec3)):
1016
+ i = wp.tid()
1017
+
1018
+ a = wp.vec3()
1019
+ b = x[i]
1020
+
1021
+ a.x += 1.0 * b.x
1022
+ a.y += 2.0 * b.y
1023
+ a.z += 3.0 * b.z
1024
+
1025
+ y[i] = a
1026
+
1027
+
1028
+ def test_vec_add_inplace(test, device):
1029
+ def run(kernel):
1030
+ x = wp.ones(1, dtype=wp.vec3, requires_grad=True, device=device)
1031
+ y = wp.zeros(1, dtype=wp.vec3, requires_grad=True, device=device)
1032
+
1033
+ tape = wp.Tape()
1034
+ with tape:
1035
+ wp.launch(kernel, 1, inputs=[x], outputs=[y], device=device)
1036
+
1037
+ y.grad = wp.ones_like(y)
1038
+ tape.backward()
1039
+
1040
+ assert_np_equal(y.numpy(), np.array([[1.0, 2.0, 3.0]], dtype=float))
1041
+ assert_np_equal(x.grad.numpy(), np.array([[1.0, 2.0, 3.0]], dtype=float))
1042
+
1043
+ run(vec_add_inplace_subscript)
1044
+ run(vec_add_inplace_attribute)
1045
+
1046
+
1047
+ @wp.kernel
1048
+ def vec_sub_inplace_subscript(x: wp.array(dtype=wp.vec3), y: wp.array(dtype=wp.vec3)):
1049
+ i = wp.tid()
1050
+
1051
+ a = wp.vec3()
1052
+ b = x[i]
1053
+
1054
+ a[0] -= 1.0 * b[0]
1055
+ a[1] -= 2.0 * b[1]
1056
+ a[2] -= 3.0 * b[2]
1057
+
1058
+ y[i] = a
1059
+
1060
+
1061
+ @wp.kernel
1062
+ def vec_sub_inplace_attribute(x: wp.array(dtype=wp.vec3), y: wp.array(dtype=wp.vec3)):
1063
+ i = wp.tid()
1064
+
1065
+ a = wp.vec3()
1066
+ b = x[i]
1067
+
1068
+ a.x -= 1.0 * b.x
1069
+ a.y -= 2.0 * b.y
1070
+ a.z -= 3.0 * b.z
1071
+
1072
+ y[i] = a
1073
+
1074
+
1075
+ def test_vec_sub_inplace(test, device):
1076
+ def run(kernel):
1077
+ x = wp.ones(1, dtype=wp.vec3, requires_grad=True, device=device)
1078
+ y = wp.zeros(1, dtype=wp.vec3, requires_grad=True, device=device)
1079
+
1080
+ tape = wp.Tape()
1081
+ with tape:
1082
+ wp.launch(kernel, 1, inputs=[x], outputs=[y], device=device)
1083
+
1084
+ y.grad = wp.ones_like(y)
1085
+ tape.backward()
1086
+
1087
+ assert_np_equal(y.numpy(), np.array([[-1.0, -2.0, -3.0]], dtype=float))
1088
+ assert_np_equal(x.grad.numpy(), np.array([[-1.0, -2.0, -3.0]], dtype=float))
1089
+
1090
+ run(vec_sub_inplace_subscript)
1091
+ run(vec_sub_inplace_attribute)
1092
+
1093
+
1094
+ @wp.kernel(module="unique")
1095
+ def vec_array_add_inplace(x: wp.array(dtype=wp.vec3), y: wp.array(dtype=wp.vec3)):
1096
+ i = wp.tid()
1097
+
1098
+ y[i] += x[i]
1099
+
1100
+
1101
+ def test_vec_array_add_inplace(test, device):
1102
+ x = wp.ones(1, dtype=wp.vec3, requires_grad=True, device=device)
1103
+ y = wp.zeros(1, dtype=wp.vec3, requires_grad=True, device=device)
1104
+
1105
+ tape = wp.Tape()
1106
+ with tape:
1107
+ wp.launch(vec_array_add_inplace, 1, inputs=[x], outputs=[y], device=device)
1108
+
1109
+ y.grad = wp.ones_like(y)
1110
+ tape.backward()
1111
+
1112
+ assert_np_equal(y.numpy(), np.array([[1.0, 1.0, 1.0]], dtype=float))
1113
+ assert_np_equal(x.grad.numpy(), np.array([[1.0, 1.0, 1.0]], dtype=float))
1114
+
1115
+
1116
+ @wp.kernel
1117
+ def vec_array_sub_inplace(x: wp.array(dtype=wp.vec3), y: wp.array(dtype=wp.vec3)):
1118
+ i = wp.tid()
1119
+
1120
+ y[i] -= x[i]
1121
+
1122
+
1123
+ def test_vec_array_sub_inplace(test, device):
1124
+ x = wp.ones(1, dtype=wp.vec3, requires_grad=True, device=device)
1125
+ y = wp.zeros(1, dtype=wp.vec3, requires_grad=True, device=device)
1126
+
1127
+ tape = wp.Tape()
1128
+ with tape:
1129
+ wp.launch(vec_array_sub_inplace, 1, inputs=[x], outputs=[y], device=device)
1130
+
1131
+ y.grad = wp.ones_like(y)
1132
+ tape.backward()
1133
+
1134
+ assert_np_equal(y.numpy(), np.array([[-1.0, -1.0, -1.0]], dtype=float))
1135
+ assert_np_equal(x.grad.numpy(), np.array([[-1.0, -1.0, -1.0]], dtype=float))
1136
+
1137
+
1138
+ @wp.kernel
1139
+ def scalar_vec_div(x: wp.array(dtype=wp.vec3), y: wp.array(dtype=wp.vec3)):
1140
+ i = wp.tid()
1141
+ y[i] = 1.0 / x[i]
1142
+
1143
+
1144
+ def test_scalar_vec_div(test, device):
1145
+ x = wp.array((wp.vec3(1.0, 2.0, 4.0),), dtype=wp.vec3, requires_grad=True, device=device)
1146
+ y = wp.ones(1, dtype=wp.vec3, requires_grad=True, device=device)
1147
+
1148
+ tape = wp.Tape()
1149
+ with tape:
1150
+ wp.launch(scalar_vec_div, 1, inputs=(x,), outputs=(y,), device=device)
1151
+
1152
+ y.grad = wp.ones_like(y)
1153
+ tape.backward()
1154
+
1155
+ assert_np_equal(y.numpy(), np.array(((1.0, 0.5, 0.25),), dtype=float))
1156
+ assert_np_equal(x.grad.numpy(), np.array(((-1.0, -0.25, -0.0625),), dtype=float))
1157
+
1158
+
1159
+ def test_vec_indexing_assign(test, device):
1160
+ @wp.func
1161
+ def fn():
1162
+ v = wp.vec4(1.0, 2.0, 3.0, 4.0)
1163
+
1164
+ v[0] = 123.0
1165
+ v[1] *= 2.0
1166
+
1167
+ wp.expect_eq(v[0], 123.0)
1168
+ wp.expect_eq(v[1], 4.0)
1169
+ wp.expect_eq(v[2], 3.0)
1170
+ wp.expect_eq(v[3], 4.0)
1171
+
1172
+ v[-1] = 123.0
1173
+ v[-2] *= 2.0
1174
+
1175
+ wp.expect_eq(v[-1], 123.0)
1176
+ wp.expect_eq(v[-2], 6.0)
1177
+ wp.expect_eq(v[-3], 4.0)
1178
+ wp.expect_eq(v[-4], 123.0)
1179
+
1180
+ @wp.kernel(module="unique")
1181
+ def kernel():
1182
+ fn()
1183
+
1184
+ wp.launch(kernel, 1, device=device)
1185
+ wp.synchronize()
1186
+ fn()
1187
+
1188
+
1189
+ def test_vec_slicing_assign(test, device):
1190
+ vec0 = wp.vec(0, float)
1191
+ vec1 = wp.vec(1, float)
1192
+ vec2 = wp.vec(2, float)
1193
+ vec3 = wp.vec(3, float)
1194
+ vec4 = wp.vec(4, float)
1195
+
1196
+ @wp.func
1197
+ def fn():
1198
+ v = wp.vec4(1.0, 2.0, 3.0, 4.0)
1199
+
1200
+ wp.expect_eq(v[:] == vec4(1.0, 2.0, 3.0, 4.0), True)
1201
+ wp.expect_eq(v[-123:123] == vec4(1.0, 2.0, 3.0, 4.0), True)
1202
+ wp.expect_eq(v[123:] == vec0(), True)
1203
+ wp.expect_eq(v[:-123] == vec0(), True)
1204
+ wp.expect_eq(v[::123] == vec1(1.0), True)
1205
+
1206
+ wp.expect_eq(v[1:] == vec3(2.0, 3.0, 4.0), True)
1207
+ wp.expect_eq(v[-2:] == vec2(3.0, 4.0), True)
1208
+ wp.expect_eq(v[:2] == vec2(1.0, 2.0), True)
1209
+ wp.expect_eq(v[:-1] == vec3(1.0, 2.0, 3.0), True)
1210
+ wp.expect_eq(v[::2] == vec2(1.0, 3.0), True)
1211
+ wp.expect_eq(v[1::2] == vec2(2.0, 4.0), True)
1212
+ wp.expect_eq(v[::-1] == vec4(4.0, 3.0, 2.0, 1.0), True)
1213
+ wp.expect_eq(v[::-2] == vec2(4.0, 2.0), True)
1214
+ wp.expect_eq(v[1::-2] == vec1(2.0), True)
1215
+
1216
+ v[1:] = vec3(5.0, 6.0, 7.0)
1217
+ wp.expect_eq(v == wp.vec4(1.0, 5.0, 6.0, 7.0), True)
1218
+
1219
+ v[-2:] = vec2(8.0, 9.0)
1220
+ wp.expect_eq(v == wp.vec4(1.0, 5.0, 8.0, 9.0), True)
1221
+
1222
+ v[:2] = vec2(10.0, 11.0)
1223
+ wp.expect_eq(v == wp.vec4(10.0, 11.0, 8.0, 9.0), True)
1224
+
1225
+ v[:-1] = vec3(12.0, 13.0, 14.0)
1226
+ wp.expect_eq(v == wp.vec4(12.0, 13.0, 14.0, 9.0), True)
1227
+
1228
+ v[::2] = vec2(15.0, 16.0)
1229
+ wp.expect_eq(v == wp.vec4(15.0, 13.0, 16.0, 9.0), True)
1230
+
1231
+ v[1::2] = vec2(17.0, 18.0)
1232
+ wp.expect_eq(v == wp.vec4(15.0, 17.0, 16.0, 18.0), True)
1233
+
1234
+ v[::-1] = vec4(19.0, 20.0, 21.0, 22.0)
1235
+ wp.expect_eq(v == wp.vec4(22.0, 21.0, 20.0, 19.0), True)
1236
+
1237
+ v[::-2] = vec2(23.0, 24.0)
1238
+ wp.expect_eq(v == wp.vec4(22.0, 24.0, 20.0, 23.0), True)
1239
+
1240
+ v[1::-2] = vec1(25.0)
1241
+ wp.expect_eq(v == wp.vec4(22.0, 25.0, 20.0, 23.0), True)
1242
+
1243
+ v[1:] += vec3(26.0, 27.0, 28.0)
1244
+ wp.expect_eq(v == wp.vec4(22.0, 51.0, 47.0, 51.0), True)
1245
+
1246
+ v[:-1] -= vec3(29.0, 30.0, 31.0)
1247
+ wp.expect_eq(v == wp.vec4(-7.0, 21.0, 16.0, 51.0), True)
1248
+
1249
+ v[:] %= vec4(32.0, 33.0, 34.0, 35.0)
1250
+ wp.expect_eq(v == wp.vec4(-7.0, 21.0, 16.0, 16.0), True)
1251
+
1252
+ @wp.kernel(module="unique")
1253
+ def kernel():
1254
+ fn()
1255
+
1256
+ wp.launch(kernel, 1, device=device)
1257
+ wp.synchronize()
1258
+ fn()
1259
+
1260
+
1261
+ def test_vec_assign_inplace_errors(test, device):
1262
+ @wp.kernel
1263
+ def kernel_1():
1264
+ v = wp.vec4(1.0, 2.0, 3.0, 4.0)
1265
+ v[1:] = wp.vec3d(wp.float64(5.0), wp.float64(6.0), wp.float64(7.0))
1266
+
1267
+ with test.assertRaisesRegex(
1268
+ ValueError,
1269
+ r"The provided vector is expected to be of length 3 with dtype float32.$",
1270
+ ):
1271
+ wp.launch(kernel_1, dim=1, device=device)
1272
+
1273
+ @wp.kernel
1274
+ def kernel_2():
1275
+ v = wp.vec4(1.0, 2.0, 3.0, 4.0)
1276
+ v[1:] = wp.float64(5.0)
1277
+
1278
+ with test.assertRaisesRegex(
1279
+ ValueError,
1280
+ r"The provided value is expected to be a vector of length 3, with dtype float32.$",
1281
+ ):
1282
+ wp.launch(kernel_2, dim=1, device=device)
1283
+
1284
+ @wp.kernel
1285
+ def kernel_3():
1286
+ v = wp.vec4(1.0, 2.0, 3.0, 4.0)
1287
+ v[1:] = wp.mat22(5.0, 6.0, 7.0, 8.0)
1288
+
1289
+ with test.assertRaisesRegex(
1290
+ ValueError,
1291
+ r"The provided value is expected to be a vector of length 3, with dtype float32.$",
1292
+ ):
1293
+ wp.launch(kernel_3, dim=1, device=device)
1294
+
1295
+ @wp.kernel
1296
+ def kernel_4():
1297
+ v = wp.vec4(1.0, 2.0, 3.0, 4.0)
1298
+ v[1:] = wp.vec2(5.0, 6.0)
1299
+
1300
+ with test.assertRaisesRegex(
1301
+ ValueError,
1302
+ r"The length of the provided vector \(2\) isn't compatible with the given slice \(expected 3\).$",
1303
+ ):
1304
+ wp.launch(kernel_4, dim=1, device=device)
1305
+
1306
+
1307
+ def test_vec_slicing_assign_backward(test, device):
1308
+ @wp.kernel(module="unique")
1309
+ def kernel(arr_x: wp.array(dtype=wp.vec2), arr_y: wp.array(dtype=wp.vec4)):
1310
+ i = wp.tid()
1311
+
1312
+ y = arr_y[i]
1313
+
1314
+ y[:2] = arr_x[i]
1315
+ y[1:-1] += arr_x[i][:2]
1316
+ y[3:1:-1] -= arr_x[i][0:]
1317
+
1318
+ arr_y[i] = y
1319
+
1320
+ x = wp.ones(1, dtype=wp.vec2, requires_grad=True, device=device)
1321
+ y = wp.zeros(1, dtype=wp.vec4, requires_grad=True, device=device)
1322
+
1323
+ tape = wp.Tape()
1324
+ with tape:
1325
+ wp.launch(kernel, 1, inputs=(x,), outputs=(y,), device=device)
1326
+
1327
+ y.grad = wp.ones_like(y)
1328
+ tape.backward()
1329
+
1330
+ assert_np_equal(y.numpy(), np.array(((1.0, 2.0, 0.0, -1.0),), dtype=float))
1331
+ assert_np_equal(x.grad.numpy(), np.array(((1.0, 1.0),), dtype=float))
1332
+
1333
+
1334
+ devices = get_test_devices()
1335
+
1336
+
1337
+ class TestVec(unittest.TestCase):
1338
+ def test_tpl_ops_with_anon(self):
1339
+ vec3i = wp.vec(3, dtype=int)
1340
+
1341
+ v = wp.vec3i(1, 2, 3)
1342
+ v += vec3i(2, 3, 4)
1343
+ v -= vec3i(3, 4, 5)
1344
+ self.assertSequenceEqual(v, (0, 1, 2))
1345
+
1346
+ v = vec3i(1, 2, 3)
1347
+ v += wp.vec3i(2, 3, 4)
1348
+ v -= wp.vec3i(3, 4, 5)
1349
+ self.assertSequenceEqual(v, (0, 1, 2))
1350
+
1351
+
1352
+ vec10 = wp._src.types.vector(length=10, dtype=float)
1353
+ add_kernel_test(
1354
+ TestVec,
1355
+ test_vector_mutation,
1356
+ dim=1,
1357
+ inputs=[vec10(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0)],
1358
+ devices=devices,
1359
+ )
1360
+
1361
+ for dtype in np_unsigned_int_types:
1362
+ add_function_test_register_kernel(
1363
+ TestVec,
1364
+ f"test_subtraction_unsigned_{dtype.__name__}",
1365
+ test_subtraction_unsigned,
1366
+ devices=devices,
1367
+ dtype=dtype,
1368
+ )
1369
+
1370
+ for dtype in np_signed_int_types + np_float_types:
1371
+ add_function_test_register_kernel(
1372
+ TestVec, f"test_negation_{dtype.__name__}", test_negation, devices=devices, dtype=dtype
1373
+ )
1374
+ add_function_test_register_kernel(
1375
+ TestVec, f"test_subtraction_{dtype.__name__}", test_subtraction, devices=devices, dtype=dtype
1376
+ )
1377
+
1378
+ for dtype in np_float_types:
1379
+ add_function_test_register_kernel(
1380
+ TestVec, f"test_crossproduct_{dtype.__name__}", test_crossproduct, devices=devices, dtype=dtype
1381
+ )
1382
+ add_function_test_register_kernel(
1383
+ TestVec, f"test_length_{dtype.__name__}", test_length, devices=devices, dtype=dtype
1384
+ )
1385
+ add_function_test_register_kernel(
1386
+ TestVec, f"test_normalize_{dtype.__name__}", test_normalize, devices=devices, dtype=dtype
1387
+ )
1388
+
1389
+ add_function_test(TestVec, "test_length_mismatch", test_length_mismatch, devices=devices)
1390
+ add_function_test(TestVec, "test_vector_len", test_vector_len, devices=devices)
1391
+ add_function_test(TestVec, "test_vec_extract", test_vec_extract, devices=devices)
1392
+ add_function_test(TestVec, "test_vec_assign", test_vec_assign, devices=devices)
1393
+ add_function_test(TestVec, "test_vec_array_extract", test_vec_array_extract, devices=devices)
1394
+ add_function_test(TestVec, "test_vec_array_assign", test_vec_array_assign, devices=devices)
1395
+ add_function_test(TestVec, "test_vec_add_inplace", test_vec_add_inplace, devices=devices)
1396
+ add_function_test(TestVec, "test_vec_sub_inplace", test_vec_sub_inplace, devices=devices)
1397
+ add_function_test(TestVec, "test_vec_array_add_inplace", test_vec_array_add_inplace, devices=devices)
1398
+ add_function_test(TestVec, "test_vec_array_sub_inplace", test_vec_array_sub_inplace, devices=devices)
1399
+ add_function_test(TestVec, "test_scalar_vec_div", test_scalar_vec_div, devices=devices)
1400
+ add_function_test(TestVec, "test_vec_indexing_assign", test_vec_indexing_assign, devices=devices)
1401
+ add_function_test(TestVec, "test_vec_slicing_assign", test_vec_slicing_assign, devices=devices)
1402
+ add_function_test(TestVec, "test_vec_assign_inplace_errors", test_vec_assign_inplace_errors, devices=devices)
1403
+ add_function_test(TestVec, "test_vec_slicing_assign_backward", test_vec_slicing_assign_backward, devices=devices)
1404
+
1405
+
1406
+ if __name__ == "__main__":
1407
+ wp.clear_kernel_cache()
1408
+ unittest.main(verbosity=2, failfast=True)