Skip to contents

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.

Usage

prim_dynamic_update_slice(operand, update, ...)

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 as operand, with nv_shape(update) <= nv_shape(operand) per dimension.

...

(arrayish of integer type)
Scalar start indices, one per dimension of operand. 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.

Implemented Rules

  • stablehlo

  • quickr

  • reverse

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} ]