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

Data type string. Supported types include:

  • Floating point: "float32", "float64"

  • Integer: "int8", "int16", "int32", "int64", "uint8", "uint16", "uint32", "uint64"

  • Other: "bool", "complex64"

Not all functions support all types. See individual function documentation.

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: cpu
#>   values:
#>      [,1] [,2]
#> [1,]    0    0
#> [2,]    0    0