warp.tile\_randf ================ .. currentmodule:: warp._src.lang .. function:: tile_randf(shape: tuple[int, ...], rng: uint32, storage: str = "register") -> Tile[Any, tuple[int, ...]] .. wp-function-tags:: :kernel: true :python: false :differentiable: false Generate a tile of random floats. Each element is drawn with :func:`~warp.randf` using ``rng``. Values are deterministic for a fixed kernel, device, and ``block_dim`` given the same ``rng``, but are not portable across ``block_dim`` values or between CPU and GPU (see :ref:`CPU Tile Semantics `). The call leaves ``rng`` unchanged, so two calls with the same ``rng`` in the same thread produce identical tiles. Pass a different ``rng`` (for example a :func:`~warp.rand_init` offset that is unique per block) to get different values. :param shape: Shape of the output tile. Must be a compile-time constant. :param rng: Random number generator state, typically from :func:`~warp.rand_init`. :param storage: The storage location for the tile: ``"register"`` for registers or ``"shared"`` for shared memory. Must be a compile-time constant. :returns: A tile of ``float32`` elements with the requested shape, each in ``[0, 1)``. .. rubric:: Example .. testcode:: :skipif: wp.get_device() == "cpu" or wp.get_cuda_device_count() == 0 TILE_M, TILE_N = 2, 2 M, N = 2, 2 seed = 42 @wp.kernel def generate_random_floats(seed: int, x: wp.array2d[float]): i, j = wp.tid() # one distinct RNG offset per block rng = wp.rand_init(seed, i * N + 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(generate_random_floats, dim=[M, N], inputs=[seed], outputs=[x], block_dim=8) print(x.numpy()) .. testoutput:: [[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 ]] The values above are those produced on a CUDA device; a CPU launch of the same kernel generates a different sequence. .. function:: tile_randf(shape: int32, rng: uint32, storage: str = "register") -> Tile[Any, tuple[int, ...]] :noindex: .. wp-function-tags:: :kernel: true :python: false :differentiable: false Generate a tile of random floats. Overload for 1D tiles: ``shape`` is the number of elements, equivalent to passing ``(shape,)``. See the overload taking a tuple-valued ``shape`` argument for usage details and an example. .. function:: tile_randf(shape: tuple[int, ...], rng: uint32, min: float32, max: float32, storage: str = "register") -> Tile[Any, tuple[int, ...]] :noindex: .. wp-function-tags:: :kernel: true :python: false :differentiable: false Generate a tile of random floats in the range ``[min, max)``. See the overload without ``min`` and ``max`` for reproducibility details and a usage example. :param shape: Shape of the output tile. Must be a compile-time constant. :param rng: Random number generator state, typically from :func:`~warp.rand_init`. :param min: Minimum value (inclusive). Must be a compile-time floating-point constant; it is interpreted at ``float32`` precision. :param max: Maximum value (exclusive). Must be a compile-time floating-point constant that remains greater than ``min`` after both are converted to ``float32``. :param storage: The storage location for the tile: ``"register"`` for registers or ``"shared"`` for shared memory. Must be a compile-time constant. :returns: A tile of ``float32`` elements with the requested shape, each in ``[min, max)``. .. function:: tile_randf(shape: int32, rng: uint32, min: float32, max: float32, storage: str = "register") -> Tile[Any, tuple[int, ...]] :noindex: .. wp-function-tags:: :kernel: true :python: false :differentiable: false Generate a tile of random floats in the range ``[min, max)``. Overload for 1D tiles: ``shape`` is the number of elements, equivalent to passing ``(shape,)``. See the overload taking a tuple-valued ``shape`` argument with ``min`` and ``max`` for usage details and an example.