Returns a copy of operand with a slice replaced by update at a
runtime-determined position. This is the write counterpart of
prim_dynamic_slice(): dynamic slice reads a block from an array,
while dynamic update slice writes a block into an array.
Arguments
- operand
(
arrayish)
Arrayish value of any data type.- update
(
arrayish)
The values to write at the specified position. Must have the same data type and number of dimensions asoperand, withnv_shape(update) <= nv_shape(operand)per dimension.- ...
(
arrayishof integer type)
Scalar start indices, one per dimension ofoperand. Each must be a scalar array.
Value
arrayish
Has the same data type and shape as operand.
It is ambiguous if the input is ambiguous.
StableHLO
Lowers to stablehlo::hlo_dynamic_update_slice().
Out Of Bounds Behavior
Start indices are clamped before the slice is extracted:
adjusted_start_indices = clamp(1, start_indices, nv_shape(operand) - slice_sizes + 1).
This means that out-of-bounds indices will not cause an error, but
the effective start position may differ from the requested one.
Examples
# 1-D: overwrite two elements starting at position 2
x <- nv_array(1:5)
update <- nv_array(c(10L, 20L))
start <- nv_scalar(2L)
prim_dynamic_update_slice(x, update, start)
#> AnvlArray
#> 1
#> 10
#> 20
#> 4
#> 5
#> [ CPUi32{5} ]
# 2-D: write a 2x2 block into a 3x4 matrix
x <- nv_array(matrix(0L, nrow = 3, ncol = 4))
update <- nv_array(matrix(c(1L, 2L, 3L, 4L), nrow = 2, ncol = 2))
row_start <- nv_scalar(2L)
col_start <- nv_scalar(3L)
prim_dynamic_update_slice(x, update, row_start, col_start)
#> AnvlArray
#> 0 0 0 0
#> 0 0 1 3
#> 0 0 2 4
#> [ CPUi32{3,4} ]