Skip to contents

Computes the inverse of a square matrix. Note that as of MLX 0.30.0, this runs on the CPU.

Usage

mlx_inv(x, device = NULL)

Arguments

x

An mlx array.

device

Execution target for APIs that expose a one-off device or stream override. Supply "gpu", "cpu", or an mlx_stream created via mlx_new_stream(). Ordinary array operations use the current mlx_device() instead.

Value

The inverse of x.

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