warp.tile_astype#
- warp.tile_astype( ) Tile[Any, tuple[int, ...]]#
Return a tile converted to a different scalar type.
Floating-point values converted to integers are truncated toward zero when the truncated value is representable by the destination type.
Gradients only propagate when both the source and destination types are floating-point; a conversion involving an integer type contributes no gradient.
- Parameters:
t – Input tile, whose element type must be a scalar
dtype – Scalar data type of the returned tile
- Returns:
A new tile with the same shape as
t, holding the converted values.
Example
@wp.kernel def truncate_values(a: wp.array[float], out: wp.array[int]): t = wp.tile_load(a, shape=4) i = wp.tile_astype(t, dtype=wp.int32) wp.tile_store(out, i) a = wp.array([-1.7, -0.5, 0.5, 2.7], dtype=float) out = wp.zeros(4, dtype=int) wp.launch_tiled(truncate_values, dim=1, inputs=[a], outputs=[out], block_dim=2) print(out.numpy())
[-1 0 0 2]