Skip to contents

Wrapper around mlx.core.slice_update() that replaces a contiguous strided region with value.

Usage

mlx_slice_update(x, value, start, stop, strides = NULL)

Arguments

x

An mlx array.

value

Replacement mlx (or coercible) array. Must broadcast to the slice determined by start, stop, and strides.

start

Integer vector (0-indexed) giving the starting index for each axis.

stop

Integer vector (exclusive) giving the stopping index for each axis.

strides

Optional integer vector of strides (defaults to ones).

Value

An mlx array with the specified slice replaced.

Examples

x <- as_mlx(matrix(1:9, 3, 3))
replacement <- as_mlx(matrix(100:103, nrow = 2))
updated <- mlx_slice_update(x, replacement, start = c(0L, 1L), stop = c(2L, 3L))
as.matrix(updated)
#>      [,1] [,2] [,3]
#> [1,]    1  100  102
#> [2,]    2  101  103
#> [3,]    3    6    9