Skip to contents

Always returns an R array using the MLX shape. One-dimensional MLX inputs become 1-D arrays (with dim set to their length) instead of plain vectors.

Usage

# S3 method for class 'mlx'
as.array(x, ...)

Arguments

x

An mlx array.

...

Additional arguments; ignored.

Value

An R array with the same shape as the MLX input.

Details

MLX does not support float64 operations on GPU. When this function creates a float64 array or converts one back to R, Rmlx temporarily switches only that internal creation or layout work to CPU. Later operations on the returned array still use the current mlx_device().

Examples

x <- mlx_matrix(1:8, 2, 4)
as.array(x)
#>      [,1] [,2] [,3] [,4]
#> [1,]    1    3    5    7
#> [2,]    2    4    6    8

v <- as_mlx(1:3)
as.array(v)  # 1-D array with dim 3
#> [1] 1 2 3