warp.tile\_view =============== .. currentmodule:: warp._src.lang .. function:: tile_view(t: Tile[Any, tuple[int, ...]], offset: tuple, shape: tuple[int, ...] = ...) -> Tile[Any, tuple[int, ...]] .. wp-function-tags:: :kernel: true :python: false :differentiable: false Return a view of a tile. The view aliases the source tile: writing through it modifies ``t``. Taking a view requires shared storage, but the view itself is non-owning and allocates no additional storage. Two forms are supported: * When ``shape`` is omitted, entries in ``offset`` map from left to right to the dimensions of ``t``. Integer entries select and remove dimensions; for example, ``wp.tile_view(t, offset=(i,))`` on an ``(M, N)`` tile returns row ``i`` with ``shape=(N,)``. Python ``slice`` entries select ranges and retain dimensions, with each extent determined by its slice. Omitted trailing dimensions are retained in full. Tile subscript syntax such as ``t[2:4, ::-1]`` produces this form. * When ``shape`` is provided, ``offset`` gives the origin of a rectangular view and ``shape`` gives its extent. In this form, supplied ``offset`` entries must be integers; slices are not allowed. :param t: Input tile to take a view of :param offset: Integer indices, Python ``slice`` objects, or a mix describing the part of ``t`` to view. Integer entries may be runtime values; constant integer entries must lie within the corresponding dimension of ``t``. Runtime integer bounds are checked in debug mode; in all modes, out-of-range values are invalid. Slice bounds and steps must be compile-time constants; negative bounds and steps are supported. Use subscript syntax such as ``t[-1, :]`` for negative integer indexing. :param shape: Extent of the view, with one entry per dimension of ``t``. Entries must be compile-time constants, and for every dimension ``d``, ``offset[d] + shape[d]`` must not exceed ``t.shape[d]``. Only valid when ``offset`` contains no slices. :returns: A non-owning tile that aliases ``t``, with dimensions given by ``shape``, by the inferred slice extents, or by the source dimensions that ``offset`` did not name. .. rubric:: Example .. testcode:: @wp.kernel def replace_rows(a: wp.array2d[float], out: wp.array2d[float]): t = wp.tile_load(a, shape=(4, 4)) # the view aliases t, so writing through it updates t rows = wp.tile_view(t, offset=(2, 0), shape=(2, 4)) values = wp.tile_arange(100.0, 108.0, 1.0, dtype=float) wp.tile_assign(rows, wp.tile_reshape(values, shape=(2, 4))) wp.tile_store(out, t) a = wp.array(np.arange(16, dtype=np.float32).reshape(4, 4), dtype=float) out = wp.zeros((4, 4), dtype=float) wp.launch_tiled(replace_rows, dim=1, inputs=[a], outputs=[out], block_dim=8) print(out.numpy()) .. testoutput:: [[ 0. 1. 2. 3.] [ 4. 5. 6. 7.] [100. 101. 102. 103.] [104. 105. 106. 107.]]