Skip to contents

mlx_meshgrid() mirrors mlx.core.meshgrid(), returning coordinate arrays suitable for vectorised evaluation on MLX devices.

Usage

mlx_meshgrid(..., sparse = FALSE, indexing = c("xy", "ij"), device = NULL)

Arguments

...

One or more arrays (or a single list) convertible via as_mlx() representing coordinate vectors.

sparse

Logical flag producing broadcast-friendly outputs when TRUE.

indexing

Either "xy" (Cartesian) or "ij" (matrix) indexing.

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

A list of mlx arrays matching the number of inputs.

Examples

xs <- as_mlx(1:3)
ys <- as_mlx(1:2)
mlx_meshgrid(xs, ys, indexing = "xy")
#> [[1]]
#> mlx array [2 x 3]
#>   dtype: float32
#>   device: gpu
#>   values:
#>      [,1] [,2] [,3]
#> [1,]    1    2    3
#> [2,]    1    2    3
#> 
#> [[2]]
#> mlx array [2 x 3]
#>   dtype: float32
#>   device: gpu
#>   values:
#>      [,1] [,2] [,3]
#> [1,]    1    1    1
#> [2,]    2    2    2
#>