warp.tile_reshape#
- warp.tile_reshape( ) Tile[Any, tuple[int, ...]]#
Return a view of a tile with a new shape.
The view aliases the source tile, so writing through it modifies
t. Taking the view requires shared storage, but the view itself is non-owning and allocates no additional storage.Elements keep their order in memory, which for a row-major layout matches
numpy.reshape().- Parameters:
t – Input tile to reshape. Must be contiguous in memory, not a strided or reversed view. Copy it into a new tile with
tile_assign()first if needed.shape – New shape, whose total number of elements must match
t. Entries must be compile-time constants; at most one may be-1, which is inferred from the others.
- Returns:
A non-owning tile that aliases
twith the requested shape.
Example
@wp.kernel def reshape_matrix(a: wp.array2d[float], out: wp.array2d[float]): t = wp.tile_load(a, shape=(2, 4)) r = wp.tile_reshape(t, shape=(4, -1)) wp.tile_store(out, r) a = wp.array(np.arange(1, 9, dtype=np.float32).reshape(2, 4), dtype=float) out = wp.zeros((4, 2), dtype=float) wp.launch_tiled(reshape_matrix, dim=1, inputs=[a], outputs=[out], block_dim=4) print(out.numpy())
[[1. 2.] [3. 4.] [5. 6.] [7. 8.]]