原文
a <- as_mlx(matrix(1:6, 2, 3))
b <- as_mlx(matrix(1:6, 3, 2))
# rbind, cbind, transpose
rbind(a, t(b))
#> mlx array [4 x 3]
#> dtype: float32
#> device: gpu
#> values:
#> [,1] [,2] [,3]
#> [1,] 1 3 5
#> [2,] 2 4 6
#> [3,] 1 2 3
#> [4,] 4 5 6
cbind(a, t(b))
#> mlx array [2 x 6]
#> dtype: float32
#> device: gpu
#> values:
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] 1 3 5 1 2 3
#> [2,] 2 4 6 4 5 6
# Matrix algebra
a %*% b
#> mlx array [2 x 2]
#> dtype: float32
#> device: gpu
#> values:
#> [,1] [,2]
#> [1,] 22 49
#> [2,] 28 64
# Reductions
sum(a)
#> mlx array []
#> dtype: float32
#> device: gpu
#> values:
#> [1] 21
colMeans(a)
#> mlx array [3]
#> dtype: float32
#> device: gpu
#> values:
#> [1] 1.5 3.5 5.5
# Cumulative operations flatten column-major
cumsum(a)
#> mlx array [6]
#> dtype: float32
#> device: gpu
#> values:
#> [1] 1 3 6 10 15 21
qr_res <- qr(a)
svd_res <- svd(a)
chol_res <- chol(a[, 1:2])
fft_res <- fft(a)
crossprod_res <- crossprod(a, b[1:2, ])
solve_res <- solve(a[, 1:2], b[1:2, ])