warp.tile_view#
- warp.tile_view( ) Tile[Any, tuple[int, ...]]#
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
shapeis omitted, entries inoffsetmap from left to right to the dimensions oft. Integer entries select and remove dimensions; for example,wp.tile_view(t, offset=(i,))on an(M, N)tile returns rowiwithshape=(N,). Pythonsliceentries select ranges and retain dimensions, with each extent determined by its slice. Omitted trailing dimensions are retained in full. Tile subscript syntax such ast[2:4, ::-1]produces this form.When
shapeis provided,offsetgives the origin of a rectangular view andshapegives its extent. In this form, suppliedoffsetentries must be integers; slices are not allowed.
- Parameters:
t – Input tile to take a view of
offset – Integer indices, Python
sliceobjects, or a mix describing the part oftto view. Integer entries may be runtime values; constant integer entries must lie within the corresponding dimension oft. 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 ast[-1, :]for negative integer indexing.shape – Extent of the view, with one entry per dimension of
t. Entries must be compile-time constants, and for every dimensiond,offset[d] + shape[d]must not exceedt.shape[d]. Only valid whenoffsetcontains no slices.
- Returns:
A non-owning tile that aliases
t, with dimensions given byshape, by the inferred slice extents, or by the source dimensions thatoffsetdid not name.
Example
@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())
[[ 0. 1. 2. 3.] [ 4. 5. 6. 7.] [100. 101. 102. 103.] [104. 105. 106. 107.]]