warp-lang 1.3.2__py3-none-manylinux2014_aarch64.whl → 1.4.0__py3-none-manylinux2014_aarch64.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 (107) hide show
  1. warp/__init__.py +6 -0
  2. warp/autograd.py +59 -6
  3. warp/bin/warp.so +0 -0
  4. warp/build_dll.py +8 -10
  5. warp/builtins.py +126 -4
  6. warp/codegen.py +435 -53
  7. warp/config.py +1 -1
  8. warp/context.py +678 -403
  9. warp/dlpack.py +2 -0
  10. warp/examples/benchmarks/benchmark_cloth.py +10 -0
  11. warp/examples/core/example_render_opengl.py +12 -10
  12. warp/examples/fem/example_adaptive_grid.py +251 -0
  13. warp/examples/fem/example_apic_fluid.py +1 -1
  14. warp/examples/fem/example_diffusion_3d.py +2 -2
  15. warp/examples/fem/example_magnetostatics.py +1 -1
  16. warp/examples/fem/example_streamlines.py +1 -0
  17. warp/examples/fem/utils.py +23 -4
  18. warp/examples/sim/example_cloth.py +50 -6
  19. warp/fem/__init__.py +2 -0
  20. warp/fem/adaptivity.py +493 -0
  21. warp/fem/field/field.py +2 -1
  22. warp/fem/field/nodal_field.py +18 -26
  23. warp/fem/field/test.py +4 -4
  24. warp/fem/field/trial.py +4 -4
  25. warp/fem/geometry/__init__.py +1 -0
  26. warp/fem/geometry/adaptive_nanogrid.py +843 -0
  27. warp/fem/geometry/nanogrid.py +55 -28
  28. warp/fem/space/__init__.py +1 -1
  29. warp/fem/space/nanogrid_function_space.py +69 -35
  30. warp/fem/utils.py +113 -107
  31. warp/jax_experimental.py +28 -15
  32. warp/native/array.h +0 -1
  33. warp/native/builtin.h +103 -6
  34. warp/native/bvh.cu +2 -0
  35. warp/native/cuda_util.cpp +14 -0
  36. warp/native/cuda_util.h +2 -0
  37. warp/native/error.cpp +4 -2
  38. warp/native/exports.h +99 -17
  39. warp/native/mat.h +97 -0
  40. warp/native/mesh.cpp +36 -0
  41. warp/native/mesh.cu +51 -0
  42. warp/native/mesh.h +1 -0
  43. warp/native/quat.h +43 -0
  44. warp/native/spatial.h +6 -0
  45. warp/native/vec.h +74 -0
  46. warp/native/warp.cpp +2 -1
  47. warp/native/warp.cu +10 -3
  48. warp/native/warp.h +8 -1
  49. warp/paddle.py +382 -0
  50. warp/sim/__init__.py +1 -0
  51. warp/sim/collide.py +519 -0
  52. warp/sim/integrator_euler.py +18 -5
  53. warp/sim/integrator_featherstone.py +5 -5
  54. warp/sim/integrator_vbd.py +1026 -0
  55. warp/sim/model.py +49 -23
  56. warp/stubs.py +459 -0
  57. warp/tape.py +2 -0
  58. warp/tests/aux_test_dependent.py +1 -0
  59. warp/tests/aux_test_name_clash1.py +32 -0
  60. warp/tests/aux_test_name_clash2.py +32 -0
  61. warp/tests/aux_test_square.py +1 -0
  62. warp/tests/test_array.py +222 -0
  63. warp/tests/test_async.py +3 -3
  64. warp/tests/test_atomic.py +6 -0
  65. warp/tests/test_closest_point_edge_edge.py +93 -1
  66. warp/tests/test_codegen.py +62 -15
  67. warp/tests/test_codegen_instancing.py +1457 -0
  68. warp/tests/test_collision.py +486 -0
  69. warp/tests/test_compile_consts.py +3 -28
  70. warp/tests/test_dlpack.py +170 -0
  71. warp/tests/test_examples.py +22 -8
  72. warp/tests/test_fast_math.py +10 -4
  73. warp/tests/test_fem.py +64 -0
  74. warp/tests/test_func.py +46 -0
  75. warp/tests/test_implicit_init.py +49 -0
  76. warp/tests/test_jax.py +58 -0
  77. warp/tests/test_mat.py +84 -0
  78. warp/tests/test_mesh_query_point.py +188 -0
  79. warp/tests/test_module_hashing.py +40 -0
  80. warp/tests/test_multigpu.py +3 -3
  81. warp/tests/test_overwrite.py +8 -0
  82. warp/tests/test_paddle.py +852 -0
  83. warp/tests/test_print.py +89 -0
  84. warp/tests/test_quat.py +111 -0
  85. warp/tests/test_reload.py +31 -1
  86. warp/tests/test_scalar_ops.py +2 -0
  87. warp/tests/test_static.py +412 -0
  88. warp/tests/test_streams.py +64 -3
  89. warp/tests/test_struct.py +4 -4
  90. warp/tests/test_torch.py +24 -0
  91. warp/tests/test_triangle_closest_point.py +137 -0
  92. warp/tests/test_types.py +1 -1
  93. warp/tests/test_vbd.py +386 -0
  94. warp/tests/test_vec.py +143 -0
  95. warp/tests/test_vec_scalar_ops.py +139 -0
  96. warp/tests/test_volume.py +30 -0
  97. warp/tests/unittest_suites.py +12 -0
  98. warp/tests/unittest_utils.py +9 -5
  99. warp/thirdparty/dlpack.py +3 -1
  100. warp/types.py +157 -34
  101. warp/utils.py +37 -14
  102. {warp_lang-1.3.2.dist-info → warp_lang-1.4.0.dist-info}/METADATA +10 -8
  103. {warp_lang-1.3.2.dist-info → warp_lang-1.4.0.dist-info}/RECORD +106 -94
  104. warp/tests/test_point_triangle_closest_point.py +0 -143
  105. {warp_lang-1.3.2.dist-info → warp_lang-1.4.0.dist-info}/LICENSE.md +0 -0
  106. {warp_lang-1.3.2.dist-info → warp_lang-1.4.0.dist-info}/WHEEL +0 -0
  107. {warp_lang-1.3.2.dist-info → warp_lang-1.4.0.dist-info}/top_level.txt +0 -0
warp/__init__.py CHANGED
@@ -99,11 +99,17 @@ from warp.jax import device_from_jax, device_to_jax
99
99
 
100
100
  from warp.dlpack import from_dlpack, to_dlpack
101
101
 
102
+ from warp.paddle import from_paddle, to_paddle
103
+ from warp.paddle import dtype_from_paddle, dtype_to_paddle
104
+ from warp.paddle import device_from_paddle, device_to_paddle
105
+ from warp.paddle import stream_from_paddle
106
+
102
107
  from warp.build import clear_kernel_cache
103
108
 
104
109
  from warp.constants import *
105
110
 
106
111
  from . import builtins
112
+ from warp.builtins import static
107
113
 
108
114
  import warp.config as config
109
115
 
warp/autograd.py CHANGED
@@ -17,7 +17,7 @@ __all__ = [
17
17
  "jacobian_fd",
18
18
  "gradcheck",
19
19
  "gradcheck_tape",
20
- "plot_kernel_jacobians",
20
+ "jacobian_plot",
21
21
  ]
22
22
 
23
23
 
@@ -182,7 +182,7 @@ def gradcheck(
182
182
  else:
183
183
  print(FontColors.OKGREEN + f"Gradient check for kernel {function.key} passed" + FontColors.ENDC)
184
184
  if plot_relative_error:
185
- plot_kernel_jacobians(
185
+ jacobian_plot(
186
186
  relative_error_jacs,
187
187
  function,
188
188
  inputs,
@@ -190,7 +190,7 @@ def gradcheck(
190
190
  title=f"{function.key} kernel Jacobian relative error",
191
191
  )
192
192
  if plot_absolute_error:
193
- plot_kernel_jacobians(
193
+ jacobian_plot(
194
194
  absolute_error_jacs,
195
195
  function,
196
196
  inputs,
@@ -307,7 +307,7 @@ def infer_device(xs: list):
307
307
  return wp.get_preferred_device()
308
308
 
309
309
 
310
- def plot_kernel_jacobians(
310
+ def jacobian_plot(
311
311
  jacobians: Dict[Tuple[int, int], wp.array],
312
312
  kernel: wp.Kernel,
313
313
  inputs: Sequence,
@@ -515,6 +515,59 @@ def plot_kernel_jacobians(
515
515
  return fig
516
516
 
517
517
 
518
+ def plot_kernel_jacobians(
519
+ jacobians: Dict[Tuple[int, int], wp.array],
520
+ kernel: wp.Kernel,
521
+ inputs: Sequence,
522
+ outputs: Sequence,
523
+ show_plot=True,
524
+ show_colorbar=True,
525
+ scale_colors_per_submatrix=False,
526
+ title: str = None,
527
+ colormap: str = "coolwarm",
528
+ log_scale=False,
529
+ ):
530
+ """
531
+ Visualizes the Jacobians computed by :func:`jacobian` or :func:`jacobian_fd` in a combined image plot.
532
+ Requires the ``matplotlib`` package to be installed.
533
+
534
+ Note:
535
+ This function is deprecated and will be removed in a future Warp version. Please call :func:`jacobian_plot` instead.
536
+
537
+ Args:
538
+ jacobians: A dictionary of Jacobians, where the keys are tuples of input and output indices, and the values are the Jacobian matrices.
539
+ kernel: The Warp kernel function, decorated with the ``@wp.kernel`` decorator.
540
+ inputs: List of input variables.
541
+ outputs: List of output variables.
542
+ show_plot: If True, displays the plot via ``plt.show()``.
543
+ show_colorbar: If True, displays a colorbar next to the plot (or a colorbar next to every submatrix if ).
544
+ scale_colors_per_submatrix: If True, considers the minimum and maximum of each Jacobian submatrix separately for color scaling. Otherwise, uses the global minimum and maximum of all Jacobians.
545
+ title: The title of the plot (optional).
546
+ colormap: The colormap to use for the plot.
547
+ log_scale: If True, uses a logarithmic scale for the matrix values shown in the image plot.
548
+
549
+ Returns:
550
+ The created Matplotlib figure.
551
+ """
552
+ wp.utils.warn(
553
+ "The function `plot_kernel_jacobians` is deprecated and will be removed in a future Warp version. Please call `jacobian_plot` instead.",
554
+ DeprecationWarning,
555
+ stacklevel=3,
556
+ )
557
+ return jacobian_plot(
558
+ jacobians,
559
+ kernel,
560
+ inputs,
561
+ outputs,
562
+ show_plot=show_plot,
563
+ show_colorbar=show_colorbar,
564
+ scale_colors_per_submatrix=scale_colors_per_submatrix,
565
+ title=title,
566
+ colormap=colormap,
567
+ log_scale=log_scale,
568
+ )
569
+
570
+
518
571
  def scalarize_array_1d(arr):
519
572
  # convert array to 1D array with scalar dtype
520
573
  if arr.dtype in wp.types.scalar_types:
@@ -638,7 +691,7 @@ def jacobian(
638
691
  jacobians[input_i, output_i] = jacobian
639
692
 
640
693
  if plot_jacobians:
641
- plot_kernel_jacobians(
694
+ jacobian_plot(
642
695
  jacobians,
643
696
  kernel,
644
697
  inputs,
@@ -753,7 +806,7 @@ def jacobian_fd(
753
806
  jacobians[input_i, output_i] = jacobian
754
807
 
755
808
  if plot_jacobians:
756
- plot_kernel_jacobians(
809
+ jacobian_plot(
757
810
  jacobians,
758
811
  kernel,
759
812
  inputs,
warp/bin/warp.so CHANGED
Binary file
warp/build_dll.py CHANGED
@@ -32,13 +32,12 @@ def run_cmd(cmd):
32
32
  print(cmd)
33
33
 
34
34
  try:
35
- return subprocess.check_output(cmd, shell=True)
35
+ return subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True)
36
36
  except subprocess.CalledProcessError as e:
37
- if e.stdout:
38
- print(e.stdout.decode())
39
- if e.stderr:
40
- print(e.stderr.decode())
41
- raise (e)
37
+ print("Command failed with exit code:", e.returncode)
38
+ print("Command output was:")
39
+ print(e.output.decode())
40
+ raise e
42
41
 
43
42
 
44
43
  # cut-down version of vcvars64.bat that allows using
@@ -157,7 +156,6 @@ def build_dll_for_arch(args, dll_path, cpp_paths, cu_path, libs, arch, mode=None
157
156
 
158
157
  warp_home_path = pathlib.Path(__file__).parent
159
158
  warp_home = warp_home_path.resolve()
160
- nanovdb_home = warp_home_path.parent / "_build/host-deps/nanovdb/include"
161
159
 
162
160
  # output stale, rebuild
163
161
  if args.verbose:
@@ -246,7 +244,7 @@ def build_dll_for_arch(args, dll_path, cpp_paths, cu_path, libs, arch, mode=None
246
244
  iter_dbg = "_ITERATOR_DEBUG_LEVEL=2"
247
245
  debug = "_DEBUG"
248
246
 
249
- cpp_flags = f'/nologo /std:c++17 /GR- {runtime} /D "{debug}" /D "{cuda_enabled}" /D "{cutlass_enabled}" /D "{cuda_compat_enabled}" /D "{iter_dbg}" /I"{native_dir}" /I"{nanovdb_home}" {includes} '
247
+ cpp_flags = f'/nologo /std:c++17 /GR- {runtime} /D "{debug}" /D "{cuda_enabled}" /D "{cutlass_enabled}" /D "{cuda_compat_enabled}" /D "{iter_dbg}" /I"{native_dir}" {includes} '
250
248
 
251
249
  if args.mode == "debug":
252
250
  cpp_flags += "/Zi /Od /D WP_ENABLE_DEBUG=1"
@@ -275,10 +273,10 @@ def build_dll_for_arch(args, dll_path, cpp_paths, cu_path, libs, arch, mode=None
275
273
  cu_out = cu_path + ".o"
276
274
 
277
275
  if mode == "debug":
278
- cuda_cmd = f'"{cuda_home}/bin/nvcc" --compiler-options=/MT,/Zi,/Od -g -G -O0 -DNDEBUG -D_ITERATOR_DEBUG_LEVEL=0 -I"{native_dir}" -I"{nanovdb_home}" -line-info {" ".join(nvcc_opts)} -DWP_ENABLE_CUDA=1 -D{cutlass_enabled} {cutlass_includes} -o "{cu_out}" -c "{cu_path}"'
276
+ cuda_cmd = f'"{cuda_home}/bin/nvcc" --compiler-options=/MT,/Zi,/Od -g -G -O0 -DNDEBUG -D_ITERATOR_DEBUG_LEVEL=0 -I"{native_dir}" -line-info {" ".join(nvcc_opts)} -DWP_ENABLE_CUDA=1 -D{cutlass_enabled} {cutlass_includes} -o "{cu_out}" -c "{cu_path}"'
279
277
 
280
278
  elif mode == "release":
281
- cuda_cmd = f'"{cuda_home}/bin/nvcc" -O3 {" ".join(nvcc_opts)} -I"{native_dir}" -I"{nanovdb_home}" -DNDEBUG -DWP_ENABLE_CUDA=1 -D{cutlass_enabled} {cutlass_includes} -o "{cu_out}" -c "{cu_path}"'
279
+ cuda_cmd = f'"{cuda_home}/bin/nvcc" -O3 {" ".join(nvcc_opts)} -I"{native_dir}" -DNDEBUG -DWP_ENABLE_CUDA=1 -D{cutlass_enabled} {cutlass_includes} -o "{cu_out}" -c "{cu_path}"'
282
280
 
283
281
  with ScopedTimer("build_cuda", active=args.verbose):
284
282
  run_cmd(cuda_cmd)
warp/builtins.py CHANGED
@@ -1533,7 +1533,7 @@ add_builtin(
1533
1533
 
1534
1534
  def spatial_vector_value_func(arg_types: Mapping[str, type], arg_values: Mapping[str, Any]):
1535
1535
  if arg_types is None:
1536
- return spatial_vector(dtype=Float)
1536
+ return vector(length=6, dtype=Float)
1537
1537
 
1538
1538
  dtype = arg_values.get("dtype", None)
1539
1539
 
@@ -2758,6 +2758,7 @@ add_builtin(
2758
2758
  "rand_init",
2759
2759
  input_types={"seed": int},
2760
2760
  value_type=uint32,
2761
+ export=False,
2761
2762
  group="Random",
2762
2763
  doc="Initialize a new random number generator given a user-defined seed. Returns a 32-bit integer representing the RNG state.",
2763
2764
  )
@@ -2766,6 +2767,7 @@ add_builtin(
2766
2767
  "rand_init",
2767
2768
  input_types={"seed": int, "offset": int},
2768
2769
  value_type=uint32,
2770
+ export=False,
2769
2771
  group="Random",
2770
2772
  doc="""Initialize a new random number generator given a user-defined seed and an offset.
2771
2773
 
@@ -2777,6 +2779,7 @@ add_builtin(
2777
2779
  "randi",
2778
2780
  input_types={"state": uint32},
2779
2781
  value_type=int,
2782
+ export=False,
2780
2783
  group="Random",
2781
2784
  doc="Return a random integer in the range [0, 2^32).",
2782
2785
  )
@@ -2784,6 +2787,7 @@ add_builtin(
2784
2787
  "randi",
2785
2788
  input_types={"state": uint32, "low": int, "high": int},
2786
2789
  value_type=int,
2790
+ export=False,
2787
2791
  group="Random",
2788
2792
  doc="Return a random integer between [low, high).",
2789
2793
  )
@@ -2791,6 +2795,7 @@ add_builtin(
2791
2795
  "randf",
2792
2796
  input_types={"state": uint32},
2793
2797
  value_type=float,
2798
+ export=False,
2794
2799
  group="Random",
2795
2800
  doc="Return a random float between [0.0, 1.0).",
2796
2801
  )
@@ -2798,17 +2803,24 @@ add_builtin(
2798
2803
  "randf",
2799
2804
  input_types={"state": uint32, "low": float, "high": float},
2800
2805
  value_type=float,
2806
+ export=False,
2801
2807
  group="Random",
2802
2808
  doc="Return a random float between [low, high).",
2803
2809
  )
2804
2810
  add_builtin(
2805
- "randn", input_types={"state": uint32}, value_type=float, group="Random", doc="Sample a normal distribution."
2811
+ "randn",
2812
+ input_types={"state": uint32},
2813
+ value_type=float,
2814
+ export=False,
2815
+ group="Random",
2816
+ doc="Sample a normal distribution.",
2806
2817
  )
2807
2818
 
2808
2819
  add_builtin(
2809
2820
  "sample_cdf",
2810
2821
  input_types={"state": uint32, "cdf": array(dtype=float)},
2811
2822
  value_type=int,
2823
+ export=False,
2812
2824
  group="Random",
2813
2825
  doc="Inverse-transform sample a cumulative distribution function.",
2814
2826
  )
@@ -2816,6 +2828,7 @@ add_builtin(
2816
2828
  "sample_triangle",
2817
2829
  input_types={"state": uint32},
2818
2830
  value_type=vec2,
2831
+ export=False,
2819
2832
  group="Random",
2820
2833
  doc="Uniformly sample a triangle. Returns sample barycentric coordinates.",
2821
2834
  )
@@ -2823,6 +2836,7 @@ add_builtin(
2823
2836
  "sample_unit_ring",
2824
2837
  input_types={"state": uint32},
2825
2838
  value_type=vec2,
2839
+ export=False,
2826
2840
  group="Random",
2827
2841
  doc="Uniformly sample a ring in the xy plane.",
2828
2842
  )
@@ -2830,6 +2844,7 @@ add_builtin(
2830
2844
  "sample_unit_disk",
2831
2845
  input_types={"state": uint32},
2832
2846
  value_type=vec2,
2847
+ export=False,
2833
2848
  group="Random",
2834
2849
  doc="Uniformly sample a disk in the xy plane.",
2835
2850
  )
@@ -2837,6 +2852,7 @@ add_builtin(
2837
2852
  "sample_unit_sphere_surface",
2838
2853
  input_types={"state": uint32},
2839
2854
  value_type=vec3,
2855
+ export=False,
2840
2856
  group="Random",
2841
2857
  doc="Uniformly sample a unit sphere surface.",
2842
2858
  )
@@ -2844,6 +2860,7 @@ add_builtin(
2844
2860
  "sample_unit_sphere",
2845
2861
  input_types={"state": uint32},
2846
2862
  value_type=vec3,
2863
+ export=False,
2847
2864
  group="Random",
2848
2865
  doc="Uniformly sample a unit sphere.",
2849
2866
  )
@@ -2851,6 +2868,7 @@ add_builtin(
2851
2868
  "sample_unit_hemisphere_surface",
2852
2869
  input_types={"state": uint32},
2853
2870
  value_type=vec3,
2871
+ export=False,
2854
2872
  group="Random",
2855
2873
  doc="Uniformly sample a unit hemisphere surface.",
2856
2874
  )
@@ -2858,6 +2876,7 @@ add_builtin(
2858
2876
  "sample_unit_hemisphere",
2859
2877
  input_types={"state": uint32},
2860
2878
  value_type=vec3,
2879
+ export=False,
2861
2880
  group="Random",
2862
2881
  doc="Uniformly sample a unit hemisphere.",
2863
2882
  )
@@ -2865,6 +2884,7 @@ add_builtin(
2865
2884
  "sample_unit_square",
2866
2885
  input_types={"state": uint32},
2867
2886
  value_type=vec2,
2887
+ export=False,
2868
2888
  group="Random",
2869
2889
  doc="Uniformly sample a unit square.",
2870
2890
  )
@@ -2872,6 +2892,7 @@ add_builtin(
2872
2892
  "sample_unit_cube",
2873
2893
  input_types={"state": uint32},
2874
2894
  value_type=vec3,
2895
+ export=False,
2875
2896
  group="Random",
2876
2897
  doc="Uniformly sample a unit cube.",
2877
2898
  )
@@ -2880,6 +2901,7 @@ add_builtin(
2880
2901
  "poisson",
2881
2902
  input_types={"state": uint32, "lam": float},
2882
2903
  value_type=uint32,
2904
+ export=False,
2883
2905
  group="Random",
2884
2906
  doc="""Generate a random sample from a Poisson distribution.
2885
2907
 
@@ -3639,6 +3661,30 @@ add_builtin(
3639
3661
  )
3640
3662
 
3641
3663
 
3664
+ def vector_assign_value_func(arg_types: Mapping[str, type], arg_values: Mapping[str, Any]):
3665
+ vec_type = arg_types["a"]
3666
+ return vec_type
3667
+
3668
+
3669
+ # implements vector[index] = value
3670
+ add_builtin(
3671
+ "assign",
3672
+ input_types={"a": vector(length=Any, dtype=Scalar), "i": int, "value": Scalar},
3673
+ value_func=vector_assign_value_func,
3674
+ hidden=True,
3675
+ group="Utility",
3676
+ )
3677
+
3678
+ # implements quaternion[index] = value
3679
+ add_builtin(
3680
+ "assign",
3681
+ input_types={"a": quaternion(dtype=Scalar), "i": int, "value": Scalar},
3682
+ value_func=vector_assign_value_func,
3683
+ hidden=True,
3684
+ group="Utility",
3685
+ )
3686
+
3687
+
3642
3688
  def matrix_index_row_value_func(arg_types: Mapping[str, type], arg_values: Mapping[str, Any]):
3643
3689
  mat_type = arg_types["a"]
3644
3690
  row_type = mat_type._wp_row_type_
@@ -3646,7 +3692,7 @@ def matrix_index_row_value_func(arg_types: Mapping[str, type], arg_values: Mappi
3646
3692
  return Reference(row_type)
3647
3693
 
3648
3694
 
3649
- # implements matrix[i] = row
3695
+ # implements &matrix[i] = row
3650
3696
  add_builtin(
3651
3697
  "index",
3652
3698
  input_types={"a": matrix(shape=(Any, Any), dtype=Scalar), "i": int},
@@ -3664,7 +3710,7 @@ def matrix_index_value_func(arg_types: Mapping[str, type], arg_values: Mapping[s
3664
3710
  return Reference(value_type)
3665
3711
 
3666
3712
 
3667
- # implements matrix[i,j] = scalar
3713
+ # implements &matrix[i,j] = scalar
3668
3714
  add_builtin(
3669
3715
  "index",
3670
3716
  input_types={"a": matrix(shape=(Any, Any), dtype=Scalar), "i": int, "j": int},
@@ -3674,6 +3720,41 @@ add_builtin(
3674
3720
  skip_replay=True,
3675
3721
  )
3676
3722
 
3723
+
3724
+ def matrix_assign_value_func(arg_types: Mapping[str, type], arg_values: Mapping[str, Any]):
3725
+ mat_type = arg_types["a"]
3726
+ return mat_type
3727
+
3728
+
3729
+ def matrix_vector_sametype(arg_types: Mapping[str, Any]):
3730
+ mat_size = arg_types["a"]._shape_[0]
3731
+ vec_size = arg_types["value"]._length_
3732
+ mat_type = arg_types["a"]._type_
3733
+ vec_type = arg_types["value"]._type_
3734
+ return mat_size == vec_size and mat_type == vec_type
3735
+
3736
+
3737
+ # implements matrix[i,j] = scalar
3738
+ add_builtin(
3739
+ "assign",
3740
+ input_types={"a": matrix(shape=(Any, Any), dtype=Scalar), "i": int, "j": int, "value": Scalar},
3741
+ value_func=matrix_assign_value_func,
3742
+ hidden=True,
3743
+ group="Utility",
3744
+ )
3745
+
3746
+
3747
+ # implements matrix[i] = vector
3748
+ add_builtin(
3749
+ "assign",
3750
+ input_types={"a": matrix(shape=(Any, Any), dtype=Scalar), "i": int, "value": vector(length=Any, dtype=Scalar)},
3751
+ constraint=matrix_vector_sametype,
3752
+ value_func=matrix_assign_value_func,
3753
+ hidden=True,
3754
+ group="Utility",
3755
+ )
3756
+
3757
+
3677
3758
  for t in scalar_types + vector_types + (bool,):
3678
3759
  if "vec" in t.__name__ or "mat" in t.__name__:
3679
3760
  continue
@@ -4107,6 +4188,14 @@ add_builtin(
4107
4188
  doc="Modulo operation using truncated division.",
4108
4189
  group="Operators",
4109
4190
  )
4191
+ add_builtin(
4192
+ "mod",
4193
+ input_types={"a": vector(length=Any, dtype=Scalar), "b": vector(length=Any, dtype=Scalar)},
4194
+ constraint=sametypes,
4195
+ value_func=sametypes_create_value_func(Scalar),
4196
+ doc="Modulo operation using truncated division.",
4197
+ group="Operators",
4198
+ )
4110
4199
 
4111
4200
  add_builtin(
4112
4201
  "div",
@@ -4218,3 +4307,36 @@ for t in int_types:
4218
4307
 
4219
4308
 
4220
4309
  add_builtin("unot", input_types={"a": array(dtype=Any)}, value_type=builtins.bool, doc="", group="Operators")
4310
+
4311
+ # ---------------------------------
4312
+ # Code Generation
4313
+
4314
+ add_builtin(
4315
+ "static",
4316
+ input_types={"expr": Any},
4317
+ value_type=Any,
4318
+ doc="""Evaluates a static Python expression and replaces it with its result.
4319
+
4320
+ See the `codegen.html#static-expressions <section on code generation>`_ for more details.
4321
+
4322
+ Note:
4323
+ The inner expression must only reference variables that are available from the current scope where the Warp kernel or function containing the expression is defined,
4324
+ which includes constant variables and variables captured in the current closure in which the function or kernel is implemented.
4325
+ The return type of the expression must be either a Warp function, a string, or a type that is supported inside Warp kernels and functions
4326
+ (excluding Warp arrays since they cannot be created in a Warp kernel at the moment).""",
4327
+ group="Code Generation",
4328
+ )
4329
+
4330
+
4331
+ def static(expr):
4332
+ """
4333
+ Evaluates a static expression and replaces the expression with its result.
4334
+
4335
+ Args:
4336
+ expr: A Python expression to evaluate. Must return a non-null value which must be either a Warp function, a string, or a type that is supported inside Warp kernels and functions (excluding Warp arrays since they cannot be created in a Warp kernel at the moment).
4337
+
4338
+ Note:
4339
+ The inner expression must only reference variables that are available from the current scope where the Warp kernel or function containing the expression is defined,
4340
+ which includes constant variables and variables captured in the current closure in which the function or kernel is implemented.
4341
+ """
4342
+ return expr