Skip to contents

mlx_zeros_like() mirrors mlx.core.zeros_like(): it creates a zero-filled array matching the source array's shape. Optionally override the dtype or device.

Usage

mlx_zeros_like(x, dtype = NULL, device = NULL)

Arguments

x

An mlx array.

dtype

Optional MLX dtype override. Defaults to the source array's dtype.

device

Execution target: supply "gpu", "cpu", or an mlx_stream created via mlx_new_stream(). Defaults to the current mlx_default_device() unless noted otherwise (helpers that act on an existing array typically reuse that array's device or stream).

Value

An mlx array of zeros matching x.

Examples

base <- mlx_ones(c(2, 2))
mlx_zeros_like(base)
#> mlx array [2 x 2]
#>   dtype: float32
#>   device: gpu
#>   values:
#>      [,1] [,2]
#> [1,]    0    0
#> [2,]    0    0