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(). Default: mlx_default_device().

Value

A list of mlx arrays matching the number of inputs.

Examples

xs <- as_mlx(1:3)
ys <- as_mlx(1:2)
grids <- mlx_meshgrid(xs, ys, indexing = "xy")
lapply(grids, as.matrix)
#> [[1]]
#>      [,1] [,2] [,3]
#> [1,]    1    2    3
#> [2,]    1    2    3
#> 
#> [[2]]
#>      [,1] [,2] [,3]
#> [1,]    1    1    1
#> [2,]    2    2    2
#>