Computes the inverse of a square matrix. Note that as of MLX 0.30.0, this runs on the CPU.
Arguments
- x
An mlx array.
- device
Execution target for APIs that expose a one-off device or stream override. Supply
"gpu","cpu", or anmlx_streamcreated viamlx_new_stream(). Ordinary array operations use the currentmlx_device()instead.
Details
As of MLX 0.31.1, this operation only runs on CPU. Run it inside
with_device() or local_device(), or pass device = "cpu".
Examples
A <- mlx_matrix(c(4, 7, 2, 6), 2, 2)
A_inv <- mlx_inv(A, device = "cpu")
# Verify: A %*% A_inv should be identity
A %*% A_inv
#> mlx array [2 x 2]
#> dtype: float32
#> values:
#> [,1] [,2]
#> [1,] 1.000000e+00 0
#> [2,] 4.768372e-07 1