warp.tile_randf#

warp.tile_randf(
shape: tuple[int, ...],
rng: uint32,
storage: str,
) Tile[Any, tuple[int, ...]]#
  • Kernel

Generate a tile of random floats.

param shape:

Shape of the output tile

param rng:

Random number generator state, typically from warp.rand_init

param storage:

The storage location for the tile: "register" for registers (default) or "shared" for shared memory.

returns:

A tile of random floats in the range [0, 1) with the specified shape

Example:

TILE_M, TILE_N = 2, 2
M, N = 2, 2
seed = 42

@wp.kernel
def rand_kernel(seed: int, x: wp.array2d(dtype=float)):
    i, j = wp.tid()
    rng = wp.rand_init(seed, i * TILE_M + j)
    t = wp.tile_randf(shape=(TILE_M, TILE_N), rng=rng)
    wp.tile_store(x, t, offset=(i * TILE_M, j * TILE_N))

x = wp.zeros(shape=(M * TILE_M, N * TILE_N), dtype=float)
wp.launch_tiled(rand_kernel, dim=[M, N], inputs=[seed, x], block_dim=32)
print(x.numpy())
[[0.1859147  0.41986287 0.7774631  0.00414598]
 [0.41634446 0.3073818  0.4827178  0.53220683]
 [0.9400381  0.73490226 0.26666623 0.9250764 ]
 [0.51194566 0.57261354 0.26992965 0.8481429 ]]
warp.tile_randf(
shape: int32,
rng: uint32,
storage: str,
) Tile[Any, tuple[int, ...]]
  • Kernel

warp.tile_randf(
shape: tuple[int, ...],
rng: uint32,
min: float32,
max: float32,
storage: str,
) Tile[Any, tuple[int, ...]]
  • Kernel

Generate a tile of random floats within a specified range.

param shape:

Shape of the output tile

param rng:

Random number generator state, typically from warp.rand_init

param min:

Minimum value (inclusive) for random floats

param max:

Maximum value (exclusive) for random floats

param storage:

The storage location for the tile: "register" for registers (default) or "shared" for shared memory.

returns:

A tile of random floats in the range [min, max) with the specified shape

Example:

TILE_M, TILE_N = 2, 2
M, N = 2, 2
seed = 42

@wp.kernel
def rand_range_kernel(seed: int, x: wp.array2d(dtype=float)):
    i, j = wp.tid()
    rng = wp.rand_init(seed, i * TILE_M + j)
    t = wp.tile_randf(shape=(TILE_M, TILE_N), rng=rng, min=-5.0, max=5.0)
    wp.tile_store(x, t, offset=(i * TILE_M, j * TILE_N))

x = wp.zeros(shape=(M * TILE_M, N * TILE_N), dtype=float)
wp.launch_tiled(rand_range_kernel, dim=[M, N], inputs=[seed, x], block_dim=32)
print(x.numpy())
[[-3.140853   -0.80137134  2.7746308  -4.95854   ]
 [-0.83655536 -1.9261819  -0.17282188  0.32206833]
 [ 4.400381    2.3490226  -2.3333378   4.2507644 ]
 [ 0.11945665  0.7261354  -2.3007035   3.481429  ]]
warp.tile_randf(
shape: int32,
rng: uint32,
min: float32,
max: float32,
storage: str,
) Tile[Any, tuple[int, ...]]
  • Kernel