Skip to contents

mlx_array() is a low-level constructor that skips as_mlx()'s type inference and dimension guessing. Supply the raw payload vector plus an explicit shape and it pipes the data straight into MLX.

Usage

mlx_array(
  data,
  dim,
  dtype = NULL,
  device = mlx_default_device(),
  allow_scalar = FALSE
)

Arguments

data

Numeric, logical, or complex vector supplying the payload. Any dimension attributes are ignored; pass dim explicitly.

dim

Integer vector of array dimensions (product must equal length(data)).

dtype

Optional MLX dtype. Defaults to "float32" for numeric input, "bool" for logical, and "complex64" for complex.

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).

allow_scalar

Logical; set TRUE to permit dim = integer(0) so scalar payloads can be represented. When enabled, data must be length 1 and the resulting array is dimensionless.

Value

An mlx array with the requested shape.

Examples

payload <- runif(6)
mlx_array(payload, dim = c(2, 3))
#> mlx array [2 x 3]
#>   dtype: float32
#>   device: gpu
#>   values:
#>            [,1]      [,2]      [,3]
#> [1,] 0.67176682 0.9970691 0.5185567
#> [2,] 0.05861411 0.1490355 0.8461201