warp-lang 1.4.0__py3-none-win_amd64.whl → 1.4.2__py3-none-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of warp-lang might be problematic. Click here for more details.

warp/bin/warp-clang.dll CHANGED
Binary file
warp/bin/warp.dll CHANGED
Binary file
warp/builtins.py CHANGED
@@ -1497,7 +1497,8 @@ add_builtin(
1497
1497
  doc="""Apply the transform to a point ``point`` treating the homogeneous coordinate as w=1.
1498
1498
 
1499
1499
  The transformation is applied treating ``point`` as a column vector, e.g.: ``y = mat*point``.
1500
- Note this is in contrast to some libraries, notably USD, which applies transforms to row vectors, ``y^T = point^T*mat^T``.
1500
+
1501
+ This is in contrast to some libraries, notably USD, which applies transforms to row vectors, ``y^T = point^T*mat^T``.
1501
1502
  If the transform is coming from a library that uses row-vectors, then users should transpose the transformation
1502
1503
  matrix before calling this method.""",
1503
1504
  )
@@ -1515,8 +1516,9 @@ add_builtin(
1515
1516
  group="Vector Math",
1516
1517
  doc="""Apply the transform to a vector ``vec`` treating the homogeneous coordinate as w=0.
1517
1518
 
1518
- The transformation is applied treating ``vec`` as a column vector, e.g.: ``y = mat*vec``
1519
- note this is in contrast to some libraries, notably USD, which applies transforms to row vectors, ``y^T = vec^T*mat^T``.
1519
+ The transformation is applied treating ``vec`` as a column vector, e.g.: ``y = mat*vec``.
1520
+
1521
+ This is in contrast to some libraries, notably USD, which applies transforms to row vectors, ``y^T = vec^T*mat^T``.
1520
1522
  If the transform is coming from a library that uses row-vectors, then users should transpose the transformation
1521
1523
  matrix before calling this method.""",
1522
1524
  )
@@ -2758,7 +2760,6 @@ add_builtin(
2758
2760
  "rand_init",
2759
2761
  input_types={"seed": int},
2760
2762
  value_type=uint32,
2761
- export=False,
2762
2763
  group="Random",
2763
2764
  doc="Initialize a new random number generator given a user-defined seed. Returns a 32-bit integer representing the RNG state.",
2764
2765
  )
@@ -2767,7 +2768,6 @@ add_builtin(
2767
2768
  "rand_init",
2768
2769
  input_types={"seed": int, "offset": int},
2769
2770
  value_type=uint32,
2770
- export=False,
2771
2771
  group="Random",
2772
2772
  doc="""Initialize a new random number generator given a user-defined seed and an offset.
2773
2773
 
@@ -2779,7 +2779,6 @@ add_builtin(
2779
2779
  "randi",
2780
2780
  input_types={"state": uint32},
2781
2781
  value_type=int,
2782
- export=False,
2783
2782
  group="Random",
2784
2783
  doc="Return a random integer in the range [0, 2^32).",
2785
2784
  )
@@ -2787,7 +2786,6 @@ add_builtin(
2787
2786
  "randi",
2788
2787
  input_types={"state": uint32, "low": int, "high": int},
2789
2788
  value_type=int,
2790
- export=False,
2791
2789
  group="Random",
2792
2790
  doc="Return a random integer between [low, high).",
2793
2791
  )
@@ -2795,7 +2793,6 @@ add_builtin(
2795
2793
  "randf",
2796
2794
  input_types={"state": uint32},
2797
2795
  value_type=float,
2798
- export=False,
2799
2796
  group="Random",
2800
2797
  doc="Return a random float between [0.0, 1.0).",
2801
2798
  )
@@ -2803,24 +2800,17 @@ add_builtin(
2803
2800
  "randf",
2804
2801
  input_types={"state": uint32, "low": float, "high": float},
2805
2802
  value_type=float,
2806
- export=False,
2807
2803
  group="Random",
2808
2804
  doc="Return a random float between [low, high).",
2809
2805
  )
2810
2806
  add_builtin(
2811
- "randn",
2812
- input_types={"state": uint32},
2813
- value_type=float,
2814
- export=False,
2815
- group="Random",
2816
- doc="Sample a normal distribution.",
2807
+ "randn", input_types={"state": uint32}, value_type=float, group="Random", doc="Sample a normal distribution."
2817
2808
  )
2818
2809
 
2819
2810
  add_builtin(
2820
2811
  "sample_cdf",
2821
2812
  input_types={"state": uint32, "cdf": array(dtype=float)},
2822
2813
  value_type=int,
2823
- export=False,
2824
2814
  group="Random",
2825
2815
  doc="Inverse-transform sample a cumulative distribution function.",
2826
2816
  )
@@ -2828,7 +2818,6 @@ add_builtin(
2828
2818
  "sample_triangle",
2829
2819
  input_types={"state": uint32},
2830
2820
  value_type=vec2,
2831
- export=False,
2832
2821
  group="Random",
2833
2822
  doc="Uniformly sample a triangle. Returns sample barycentric coordinates.",
2834
2823
  )
@@ -2836,7 +2825,6 @@ add_builtin(
2836
2825
  "sample_unit_ring",
2837
2826
  input_types={"state": uint32},
2838
2827
  value_type=vec2,
2839
- export=False,
2840
2828
  group="Random",
2841
2829
  doc="Uniformly sample a ring in the xy plane.",
2842
2830
  )
@@ -2844,7 +2832,6 @@ add_builtin(
2844
2832
  "sample_unit_disk",
2845
2833
  input_types={"state": uint32},
2846
2834
  value_type=vec2,
2847
- export=False,
2848
2835
  group="Random",
2849
2836
  doc="Uniformly sample a disk in the xy plane.",
2850
2837
  )
@@ -2852,7 +2839,6 @@ add_builtin(
2852
2839
  "sample_unit_sphere_surface",
2853
2840
  input_types={"state": uint32},
2854
2841
  value_type=vec3,
2855
- export=False,
2856
2842
  group="Random",
2857
2843
  doc="Uniformly sample a unit sphere surface.",
2858
2844
  )
@@ -2860,7 +2846,6 @@ add_builtin(
2860
2846
  "sample_unit_sphere",
2861
2847
  input_types={"state": uint32},
2862
2848
  value_type=vec3,
2863
- export=False,
2864
2849
  group="Random",
2865
2850
  doc="Uniformly sample a unit sphere.",
2866
2851
  )
@@ -2868,7 +2853,6 @@ add_builtin(
2868
2853
  "sample_unit_hemisphere_surface",
2869
2854
  input_types={"state": uint32},
2870
2855
  value_type=vec3,
2871
- export=False,
2872
2856
  group="Random",
2873
2857
  doc="Uniformly sample a unit hemisphere surface.",
2874
2858
  )
@@ -2876,7 +2860,6 @@ add_builtin(
2876
2860
  "sample_unit_hemisphere",
2877
2861
  input_types={"state": uint32},
2878
2862
  value_type=vec3,
2879
- export=False,
2880
2863
  group="Random",
2881
2864
  doc="Uniformly sample a unit hemisphere.",
2882
2865
  )
@@ -2884,7 +2867,6 @@ add_builtin(
2884
2867
  "sample_unit_square",
2885
2868
  input_types={"state": uint32},
2886
2869
  value_type=vec2,
2887
- export=False,
2888
2870
  group="Random",
2889
2871
  doc="Uniformly sample a unit square.",
2890
2872
  )
@@ -2892,7 +2874,6 @@ add_builtin(
2892
2874
  "sample_unit_cube",
2893
2875
  input_types={"state": uint32},
2894
2876
  value_type=vec3,
2895
- export=False,
2896
2877
  group="Random",
2897
2878
  doc="Uniformly sample a unit cube.",
2898
2879
  )
@@ -2901,7 +2882,6 @@ add_builtin(
2901
2882
  "poisson",
2902
2883
  input_types={"state": uint32, "lam": float},
2903
2884
  value_type=uint32,
2904
- export=False,
2905
2885
  group="Random",
2906
2886
  doc="""Generate a random sample from a Poisson distribution.
2907
2887
 
@@ -3189,7 +3169,8 @@ def address_value_func(arg_types: Mapping[str, type], arg_values: Mapping[str, A
3189
3169
  for array_type in array_types:
3190
3170
  add_builtin(
3191
3171
  "address",
3192
- input_types={"arr": array_type(dtype=Any), "i": int, "j": int, "k": int, "l": int},
3172
+ input_types={"arr": array_type(dtype=Any), "i": Int, "j": Int, "k": Int, "l": Int},
3173
+ constraint=sametypes,
3193
3174
  defaults={"j": None, "k": None, "l": None},
3194
3175
  hidden=True,
3195
3176
  value_func=address_value_func,
@@ -3233,8 +3214,9 @@ def view_value_func(arg_types: Mapping[str, type], arg_values: Mapping[str, Any]
3233
3214
  for array_type in array_types:
3234
3215
  add_builtin(
3235
3216
  "view",
3236
- input_types={"arr": array_type(dtype=Any), "i": int, "j": int, "k": int},
3217
+ input_types={"arr": array_type(dtype=Any), "i": Int, "j": Int, "k": Int},
3237
3218
  defaults={"j": None, "k": None},
3219
+ constraint=sametypes,
3238
3220
  hidden=True,
3239
3221
  value_func=view_value_func,
3240
3222
  group="Utility",
@@ -3276,7 +3258,8 @@ def array_store_value_func(arg_types: Mapping[str, type], arg_values: Mapping[st
3276
3258
  for array_type in array_types:
3277
3259
  add_builtin(
3278
3260
  "array_store",
3279
- input_types={"arr": array_type(dtype=Any), "i": int, "value": Any},
3261
+ input_types={"arr": array_type(dtype=Any), "i": Int, "value": Any},
3262
+ constraint=sametypes,
3280
3263
  hidden=True,
3281
3264
  value_func=array_store_value_func,
3282
3265
  skip_replay=True,
@@ -3284,7 +3267,8 @@ for array_type in array_types:
3284
3267
  )
3285
3268
  add_builtin(
3286
3269
  "array_store",
3287
- input_types={"arr": array_type(dtype=Any), "i": int, "j": int, "value": Any},
3270
+ input_types={"arr": array_type(dtype=Any), "i": Int, "j": Int, "value": Any},
3271
+ constraint=sametypes,
3288
3272
  hidden=True,
3289
3273
  value_func=array_store_value_func,
3290
3274
  skip_replay=True,
@@ -3292,7 +3276,8 @@ for array_type in array_types:
3292
3276
  )
3293
3277
  add_builtin(
3294
3278
  "array_store",
3295
- input_types={"arr": array_type(dtype=Any), "i": int, "j": int, "k": int, "value": Any},
3279
+ input_types={"arr": array_type(dtype=Any), "i": Int, "j": Int, "k": Int, "value": Any},
3280
+ constraint=sametypes,
3296
3281
  hidden=True,
3297
3282
  value_func=array_store_value_func,
3298
3283
  skip_replay=True,
@@ -3300,7 +3285,8 @@ for array_type in array_types:
3300
3285
  )
3301
3286
  add_builtin(
3302
3287
  "array_store",
3303
- input_types={"arr": array_type(dtype=Any), "i": int, "j": int, "k": int, "l": int, "value": Any},
3288
+ input_types={"arr": array_type(dtype=Any), "i": Int, "j": Int, "k": Int, "l": Int, "value": Any},
3289
+ constraint=sametypes,
3304
3290
  hidden=True,
3305
3291
  value_func=array_store_value_func,
3306
3292
  skip_replay=True,
@@ -3352,6 +3338,11 @@ add_builtin(
3352
3338
  )
3353
3339
 
3354
3340
 
3341
+ def atomic_op_constraint(arg_types: Mapping[str, Any]):
3342
+ idx_types = tuple(arg_types[x] for x in "ijkl" if arg_types.get(x, None) is not None)
3343
+ return all(types_equal(idx_types[0], t) for t in idx_types[1:]) and arg_types["arr"].ndim == len(idx_types)
3344
+
3345
+
3355
3346
  def atomic_op_value_func(arg_types: Mapping[str, type], arg_values: Mapping[str, Any]):
3356
3347
  if arg_types is None:
3357
3348
  return Any
@@ -3396,7 +3387,8 @@ for array_type in array_types:
3396
3387
  add_builtin(
3397
3388
  "atomic_add",
3398
3389
  hidden=hidden,
3399
- input_types={"arr": array_type(dtype=Any), "i": int, "value": Any},
3390
+ input_types={"arr": array_type(dtype=Any), "i": Int, "value": Any},
3391
+ constraint=atomic_op_constraint,
3400
3392
  value_func=atomic_op_value_func,
3401
3393
  doc="Atomically add ``value`` onto ``arr[i]`` and return the old value.",
3402
3394
  group="Utility",
@@ -3405,7 +3397,8 @@ for array_type in array_types:
3405
3397
  add_builtin(
3406
3398
  "atomic_add",
3407
3399
  hidden=hidden,
3408
- input_types={"arr": array_type(dtype=Any), "i": int, "j": int, "value": Any},
3400
+ input_types={"arr": array_type(dtype=Any), "i": Int, "j": Int, "value": Any},
3401
+ constraint=atomic_op_constraint,
3409
3402
  value_func=atomic_op_value_func,
3410
3403
  doc="Atomically add ``value`` onto ``arr[i,j]`` and return the old value.",
3411
3404
  group="Utility",
@@ -3414,7 +3407,8 @@ for array_type in array_types:
3414
3407
  add_builtin(
3415
3408
  "atomic_add",
3416
3409
  hidden=hidden,
3417
- input_types={"arr": array_type(dtype=Any), "i": int, "j": int, "k": int, "value": Any},
3410
+ input_types={"arr": array_type(dtype=Any), "i": Int, "j": Int, "k": Int, "value": Any},
3411
+ constraint=atomic_op_constraint,
3418
3412
  value_func=atomic_op_value_func,
3419
3413
  doc="Atomically add ``value`` onto ``arr[i,j,k]`` and return the old value.",
3420
3414
  group="Utility",
@@ -3423,7 +3417,8 @@ for array_type in array_types:
3423
3417
  add_builtin(
3424
3418
  "atomic_add",
3425
3419
  hidden=hidden,
3426
- input_types={"arr": array_type(dtype=Any), "i": int, "j": int, "k": int, "l": int, "value": Any},
3420
+ input_types={"arr": array_type(dtype=Any), "i": Int, "j": Int, "k": Int, "l": Int, "value": Any},
3421
+ constraint=atomic_op_constraint,
3427
3422
  value_func=atomic_op_value_func,
3428
3423
  doc="Atomically add ``value`` onto ``arr[i,j,k,l]`` and return the old value.",
3429
3424
  group="Utility",
@@ -3433,7 +3428,8 @@ for array_type in array_types:
3433
3428
  add_builtin(
3434
3429
  "atomic_sub",
3435
3430
  hidden=hidden,
3436
- input_types={"arr": array_type(dtype=Any), "i": int, "value": Any},
3431
+ input_types={"arr": array_type(dtype=Any), "i": Int, "value": Any},
3432
+ constraint=atomic_op_constraint,
3437
3433
  value_func=atomic_op_value_func,
3438
3434
  doc="Atomically subtract ``value`` onto ``arr[i]`` and return the old value.",
3439
3435
  group="Utility",
@@ -3442,7 +3438,8 @@ for array_type in array_types:
3442
3438
  add_builtin(
3443
3439
  "atomic_sub",
3444
3440
  hidden=hidden,
3445
- input_types={"arr": array_type(dtype=Any), "i": int, "j": int, "value": Any},
3441
+ input_types={"arr": array_type(dtype=Any), "i": Int, "j": Int, "value": Any},
3442
+ constraint=atomic_op_constraint,
3446
3443
  value_func=atomic_op_value_func,
3447
3444
  doc="Atomically subtract ``value`` onto ``arr[i,j]`` and return the old value.",
3448
3445
  group="Utility",
@@ -3451,7 +3448,8 @@ for array_type in array_types:
3451
3448
  add_builtin(
3452
3449
  "atomic_sub",
3453
3450
  hidden=hidden,
3454
- input_types={"arr": array_type(dtype=Any), "i": int, "j": int, "k": int, "value": Any},
3451
+ input_types={"arr": array_type(dtype=Any), "i": Int, "j": Int, "k": Int, "value": Any},
3452
+ constraint=atomic_op_constraint,
3455
3453
  value_func=atomic_op_value_func,
3456
3454
  doc="Atomically subtract ``value`` onto ``arr[i,j,k]`` and return the old value.",
3457
3455
  group="Utility",
@@ -3460,7 +3458,8 @@ for array_type in array_types:
3460
3458
  add_builtin(
3461
3459
  "atomic_sub",
3462
3460
  hidden=hidden,
3463
- input_types={"arr": array_type(dtype=Any), "i": int, "j": int, "k": int, "l": int, "value": Any},
3461
+ input_types={"arr": array_type(dtype=Any), "i": Int, "j": Int, "k": Int, "l": Int, "value": Any},
3462
+ constraint=atomic_op_constraint,
3464
3463
  value_func=atomic_op_value_func,
3465
3464
  doc="Atomically subtract ``value`` onto ``arr[i,j,k,l]`` and return the old value.",
3466
3465
  group="Utility",
@@ -3470,44 +3469,48 @@ for array_type in array_types:
3470
3469
  add_builtin(
3471
3470
  "atomic_min",
3472
3471
  hidden=hidden,
3473
- input_types={"arr": array_type(dtype=Any), "i": int, "value": Any},
3472
+ input_types={"arr": array_type(dtype=Any), "i": Int, "value": Any},
3473
+ constraint=atomic_op_constraint,
3474
3474
  value_func=atomic_op_value_func,
3475
3475
  doc="""Compute the minimum of ``value`` and ``arr[i]``, atomically update the array, and return the old value.
3476
3476
 
3477
- .. note:: The operation is only atomic on a per-component basis for vectors and matrices.""",
3477
+ The operation is only atomic on a per-component basis for vectors and matrices.""",
3478
3478
  group="Utility",
3479
3479
  skip_replay=True,
3480
3480
  )
3481
3481
  add_builtin(
3482
3482
  "atomic_min",
3483
3483
  hidden=hidden,
3484
- input_types={"arr": array_type(dtype=Any), "i": int, "j": int, "value": Any},
3484
+ input_types={"arr": array_type(dtype=Any), "i": Int, "j": Int, "value": Any},
3485
+ constraint=atomic_op_constraint,
3485
3486
  value_func=atomic_op_value_func,
3486
3487
  doc="""Compute the minimum of ``value`` and ``arr[i,j]``, atomically update the array, and return the old value.
3487
3488
 
3488
- .. note:: The operation is only atomic on a per-component basis for vectors and matrices.""",
3489
+ The operation is only atomic on a per-component basis for vectors and matrices.""",
3489
3490
  group="Utility",
3490
3491
  skip_replay=True,
3491
3492
  )
3492
3493
  add_builtin(
3493
3494
  "atomic_min",
3494
3495
  hidden=hidden,
3495
- input_types={"arr": array_type(dtype=Any), "i": int, "j": int, "k": int, "value": Any},
3496
+ input_types={"arr": array_type(dtype=Any), "i": Int, "j": Int, "k": Int, "value": Any},
3497
+ constraint=atomic_op_constraint,
3496
3498
  value_func=atomic_op_value_func,
3497
3499
  doc="""Compute the minimum of ``value`` and ``arr[i,j,k]``, atomically update the array, and return the old value.
3498
3500
 
3499
- .. note:: The operation is only atomic on a per-component basis for vectors and matrices.""",
3501
+ The operation is only atomic on a per-component basis for vectors and matrices.""",
3500
3502
  group="Utility",
3501
3503
  skip_replay=True,
3502
3504
  )
3503
3505
  add_builtin(
3504
3506
  "atomic_min",
3505
3507
  hidden=hidden,
3506
- input_types={"arr": array_type(dtype=Any), "i": int, "j": int, "k": int, "l": int, "value": Any},
3508
+ input_types={"arr": array_type(dtype=Any), "i": Int, "j": Int, "k": Int, "l": Int, "value": Any},
3509
+ constraint=atomic_op_constraint,
3507
3510
  value_func=atomic_op_value_func,
3508
3511
  doc="""Compute the minimum of ``value`` and ``arr[i,j,k,l]``, atomically update the array, and return the old value.
3509
3512
 
3510
- .. note:: The operation is only atomic on a per-component basis for vectors and matrices.""",
3513
+ The operation is only atomic on a per-component basis for vectors and matrices.""",
3511
3514
  group="Utility",
3512
3515
  skip_replay=True,
3513
3516
  )
@@ -3515,44 +3518,48 @@ for array_type in array_types:
3515
3518
  add_builtin(
3516
3519
  "atomic_max",
3517
3520
  hidden=hidden,
3518
- input_types={"arr": array_type(dtype=Any), "i": int, "value": Any},
3521
+ input_types={"arr": array_type(dtype=Any), "i": Int, "value": Any},
3522
+ constraint=atomic_op_constraint,
3519
3523
  value_func=atomic_op_value_func,
3520
3524
  doc="""Compute the maximum of ``value`` and ``arr[i]``, atomically update the array, and return the old value.
3521
3525
 
3522
- .. note:: The operation is only atomic on a per-component basis for vectors and matrices.""",
3526
+ The operation is only atomic on a per-component basis for vectors and matrices.""",
3523
3527
  group="Utility",
3524
3528
  skip_replay=True,
3525
3529
  )
3526
3530
  add_builtin(
3527
3531
  "atomic_max",
3528
3532
  hidden=hidden,
3529
- input_types={"arr": array_type(dtype=Any), "i": int, "j": int, "value": Any},
3533
+ input_types={"arr": array_type(dtype=Any), "i": Int, "j": Int, "value": Any},
3534
+ constraint=atomic_op_constraint,
3530
3535
  value_func=atomic_op_value_func,
3531
3536
  doc="""Compute the maximum of ``value`` and ``arr[i,j]``, atomically update the array, and return the old value.
3532
3537
 
3533
- .. note:: The operation is only atomic on a per-component basis for vectors and matrices.""",
3538
+ The operation is only atomic on a per-component basis for vectors and matrices.""",
3534
3539
  group="Utility",
3535
3540
  skip_replay=True,
3536
3541
  )
3537
3542
  add_builtin(
3538
3543
  "atomic_max",
3539
3544
  hidden=hidden,
3540
- input_types={"arr": array_type(dtype=Any), "i": int, "j": int, "k": int, "value": Any},
3545
+ input_types={"arr": array_type(dtype=Any), "i": Int, "j": Int, "k": Int, "value": Any},
3546
+ constraint=atomic_op_constraint,
3541
3547
  value_func=atomic_op_value_func,
3542
3548
  doc="""Compute the maximum of ``value`` and ``arr[i,j,k]``, atomically update the array, and return the old value.
3543
3549
 
3544
- .. note:: The operation is only atomic on a per-component basis for vectors and matrices.""",
3550
+ The operation is only atomic on a per-component basis for vectors and matrices.""",
3545
3551
  group="Utility",
3546
3552
  skip_replay=True,
3547
3553
  )
3548
3554
  add_builtin(
3549
3555
  "atomic_max",
3550
3556
  hidden=hidden,
3551
- input_types={"arr": array_type(dtype=Any), "i": int, "j": int, "k": int, "l": int, "value": Any},
3557
+ input_types={"arr": array_type(dtype=Any), "i": Int, "j": Int, "k": Int, "l": Int, "value": Any},
3558
+ constraint=atomic_op_constraint,
3552
3559
  value_func=atomic_op_value_func,
3553
3560
  doc="""Compute the maximum of ``value`` and ``arr[i,j,k,l]``, atomically update the array, and return the old value.
3554
3561
 
3555
- .. note:: The operation is only atomic on a per-component basis for vectors and matrices.""",
3562
+ The operation is only atomic on a per-component basis for vectors and matrices.""",
3556
3563
  group="Utility",
3557
3564
  skip_replay=True,
3558
3565
  )
@@ -4317,13 +4324,12 @@ add_builtin(
4317
4324
  value_type=Any,
4318
4325
  doc="""Evaluates a static Python expression and replaces it with its result.
4319
4326
 
4320
- See the `codegen.html#static-expressions <section on code generation>`_ for more details.
4327
+ See the :ref:`code generation guide <static_expressions>` for more details.
4321
4328
 
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).""",
4329
+ 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,
4330
+ which includes constant variables and variables captured in the current closure in which the function or kernel is implemented.
4331
+ 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
4332
+ (excluding Warp arrays since they cannot be created in a Warp kernel at the moment).""",
4327
4333
  group="Code Generation",
4328
4334
  )
4329
4335
 
warp/codegen.py CHANGED
@@ -777,6 +777,9 @@ def func_match_args(func, arg_types, kwarg_types):
777
777
 
778
778
 
779
779
  def get_arg_type(arg: Union[Var, Any]):
780
+ if isinstance(arg, str):
781
+ return str
782
+
780
783
  if isinstance(arg, Sequence):
781
784
  return tuple(get_arg_type(x) for x in arg)
782
785
 
@@ -936,7 +939,9 @@ class Adjoint:
936
939
 
937
940
  adj.return_var = None # return type for function or kernel
938
941
  adj.loop_symbols = [] # symbols at the start of each loop
939
- adj.loop_const_iter_symbols = set() # iteration variables (constant) for static loops
942
+ adj.loop_const_iter_symbols = (
943
+ set()
944
+ ) # constant iteration variables for static loops (mutating them does not raise an error)
940
945
 
941
946
  # blocks
942
947
  adj.blocks = [Block()]
@@ -1846,7 +1851,7 @@ class Adjoint:
1846
1851
  # detect symbols with conflicting definitions (assigned inside the for loop)
1847
1852
  for items in symbols.items():
1848
1853
  sym = items[0]
1849
- if adj.loop_const_iter_symbols is not None and sym in adj.loop_const_iter_symbols:
1854
+ if adj.is_constant_iter_symbol(sym):
1850
1855
  # ignore constant overwriting in for-loops if it is a loop iterator
1851
1856
  # (it is no problem to unroll static loops multiple times in sequence)
1852
1857
  continue
@@ -1997,12 +2002,11 @@ class Adjoint:
1997
2002
  )
1998
2003
  return range_call
1999
2004
 
2000
- def begin_record_constant_iter_symbols(adj):
2001
- if adj.loop_const_iter_symbols is None:
2002
- adj.loop_const_iter_symbols = set()
2005
+ def record_constant_iter_symbol(adj, sym):
2006
+ adj.loop_const_iter_symbols.add(sym)
2003
2007
 
2004
- def end_record_constant_iter_symbols(adj):
2005
- adj.loop_const_iter_symbols = None
2008
+ def is_constant_iter_symbol(adj, sym):
2009
+ return sym in adj.loop_const_iter_symbols
2006
2010
 
2007
2011
  def emit_For(adj, node):
2008
2012
  # try and unroll simple range() statements that use constant args
@@ -2010,9 +2014,8 @@ class Adjoint:
2010
2014
 
2011
2015
  if isinstance(unroll_range, range):
2012
2016
  const_iter_sym = node.target.id
2013
- if adj.loop_const_iter_symbols is not None:
2014
- # prevent constant conflicts in `materialize_redefinitions()`
2015
- adj.loop_const_iter_symbols.add(const_iter_sym)
2017
+ # prevent constant conflicts in `materialize_redefinitions()`
2018
+ adj.record_constant_iter_symbol(const_iter_sym)
2016
2019
 
2017
2020
  # unroll static for-loop
2018
2021
  for i in unroll_range:
@@ -2033,7 +2036,6 @@ class Adjoint:
2033
2036
  iter = adj.eval(node.iter)
2034
2037
 
2035
2038
  adj.symbols[node.target.id] = adj.begin_for(iter)
2036
- adj.begin_record_constant_iter_symbols()
2037
2039
 
2038
2040
  # for loops should be side-effect free, here we store a copy
2039
2041
  adj.loop_symbols.append(adj.symbols.copy())
@@ -2044,7 +2046,6 @@ class Adjoint:
2044
2046
 
2045
2047
  adj.materialize_redefinitions(adj.loop_symbols[-1])
2046
2048
  adj.loop_symbols.pop()
2047
- adj.end_record_constant_iter_symbols()
2048
2049
 
2049
2050
  adj.end_for(iter)
2050
2051
 
@@ -2547,7 +2548,10 @@ class Adjoint:
2547
2548
  if warp.config.verify_autograd_array_access:
2548
2549
  target.mark_write(kernel_name=kernel_name, filename=filename, lineno=lineno)
2549
2550
  else:
2550
- print(f"Warning: in-place op {node.op} is not differentiable")
2551
+ if warp.config.verbose:
2552
+ print(f"Warning: in-place op {node.op} is not differentiable")
2553
+ make_new_assign_statement()
2554
+ return
2551
2555
 
2552
2556
  # TODO
2553
2557
  elif type_is_vector(target_type) or type_is_quaternion(target_type) or type_is_matrix(target_type):
warp/config.py CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
  from typing import Optional
9
9
 
10
- version: str = "1.4.0"
10
+ version: str = "1.4.2"
11
11
  """Warp version string"""
12
12
 
13
13
  verify_fp: bool = False
warp/context.py CHANGED
@@ -6,7 +6,6 @@
6
6
  # license agreement from NVIDIA CORPORATION is strictly prohibited.
7
7
 
8
8
  import ast
9
- import builtins
10
9
  import ctypes
11
10
  import functools
12
11
  import hashlib
@@ -22,7 +21,6 @@ import typing
22
21
  import weakref
23
22
  from copy import copy as shallowcopy
24
23
  from pathlib import Path
25
- from struct import pack as struct_pack
26
24
  from typing import Any, Callable, Dict, List, Mapping, Optional, Sequence, Tuple, Union
27
25
 
28
26
  import numpy as np
@@ -1251,6 +1249,7 @@ def add_builtin(
1251
1249
  key,
1252
1250
  input_types=arg_types,
1253
1251
  value_type=return_type,
1252
+ value_func=value_func if return_type is Any else None,
1254
1253
  export_func=export_func,
1255
1254
  dispatch_func=dispatch_func,
1256
1255
  doc=doc,
@@ -1487,30 +1486,16 @@ class ModuleHasher:
1487
1486
  # hash referenced constants
1488
1487
  for name, value in constants.items():
1489
1488
  ch.update(bytes(name, "utf-8"))
1490
- # hash the referenced object
1491
- if isinstance(value, builtins.bool):
1492
- # This needs to come before the check for `int` since all boolean
1493
- # values are also instances of `int`.
1494
- ch.update(struct_pack("?", value))
1495
- elif isinstance(value, int):
1496
- ch.update(struct_pack("<q", value))
1497
- elif isinstance(value, float):
1498
- ch.update(struct_pack("<d", value))
1499
- elif isinstance(value, warp.types.float16):
1500
- # float16 is a special case
1501
- p = ctypes.pointer(ctypes.c_float(value.value))
1502
- ch.update(p.contents)
1503
- elif isinstance(value, tuple(warp.types.scalar_types)):
1504
- p = ctypes.pointer(value._type_(value.value))
1505
- ch.update(p.contents)
1506
- elif isinstance(value, ctypes.Array):
1507
- ch.update(bytes(value))
1508
- else:
1509
- raise RuntimeError(f"Invalid constant type: {type(value)}")
1489
+ ch.update(self.get_constant_bytes(value))
1510
1490
 
1511
1491
  # hash wp.static() expressions that were evaluated at declaration time
1512
1492
  for k, v in adj.static_expressions.items():
1513
- ch.update(bytes(f"{k} = {v}", "utf-8"))
1493
+ ch.update(bytes(k, "utf-8"))
1494
+ if isinstance(v, Function):
1495
+ if v not in self.functions_in_progress:
1496
+ ch.update(self.hash_function(v))
1497
+ else:
1498
+ ch.update(self.get_constant_bytes(v))
1514
1499
 
1515
1500
  # hash referenced types
1516
1501
  for t in types.keys():
@@ -1523,6 +1508,24 @@ class ModuleHasher:
1523
1508
 
1524
1509
  return ch.digest()
1525
1510
 
1511
+ def get_constant_bytes(self, value):
1512
+ if isinstance(value, int):
1513
+ # this also handles builtins.bool
1514
+ return bytes(ctypes.c_int(value))
1515
+ elif isinstance(value, float):
1516
+ return bytes(ctypes.c_float(value))
1517
+ elif isinstance(value, warp.types.float16):
1518
+ # float16 is a special case
1519
+ return bytes(ctypes.c_float(value.value))
1520
+ elif isinstance(value, tuple(warp.types.scalar_and_bool_types)):
1521
+ return bytes(value._type_(value.value))
1522
+ elif hasattr(value, "_wp_scalar_type_"):
1523
+ return bytes(value)
1524
+ elif isinstance(value, warp.codegen.StructInstance):
1525
+ return bytes(value._ctype)
1526
+ else:
1527
+ raise TypeError(f"Invalid constant type: {type(value)}")
1528
+
1526
1529
  def get_module_hash(self):
1527
1530
  return self.module_hash
1528
1531
 
@@ -199,9 +199,10 @@ class Example:
199
199
 
200
200
  # creates a grid of particles
201
201
  def particle_grid(self, dim_x, dim_y, dim_z, lower, radius, jitter):
202
+ rng = np.random.default_rng(42)
202
203
  points = np.meshgrid(np.linspace(0, dim_x, dim_x), np.linspace(0, dim_y, dim_y), np.linspace(0, dim_z, dim_z))
203
204
  points_t = np.array((points[0], points[1], points[2])).T * radius * 2.0 + np.array(lower)
204
- points_t = points_t + np.random.rand(*points_t.shape) * radius * jitter
205
+ points_t = points_t + rng.random(size=points_t.shape) * radius * jitter
205
206
 
206
207
  return points_t.reshape((-1, 3))
207
208
 
@@ -98,11 +98,11 @@ class Example:
98
98
 
99
99
  for _ in range(self.query_count):
100
100
  # random offset
101
- p = wp.vec3(rng.random(3) * 0.5 - 0.5) * 5.0
101
+ p = wp.vec3(rng.random(size=3) * 0.5 - 0.5) * 5.0
102
102
 
103
103
  # random orientation
104
- axis = wp.normalize(wp.vec3(rng.random(3) * 0.5 - 0.5))
105
- angle = float(np.random.rand(1)[0])
104
+ axis = wp.normalize(wp.vec3(rng.random(size=3) * 0.5 - 0.5))
105
+ angle = rng.random()
106
106
 
107
107
  q = wp.quat_from_axis_angle(wp.normalize(axis), angle)
108
108