Solve triangular systems with mlx arrays
Usage
mlx_solve_triangular(a, b, upper = FALSE, device = NULL)
backsolve(r, x, k = NULL, upper.tri = TRUE, transpose = FALSE, ...)
# Default S3 method
backsolve(r, x, k = NULL, upper.tri = TRUE, transpose = FALSE, ...)
# S3 method for class 'mlx'
backsolve(
r,
x,
k = NULL,
upper.tri = TRUE,
transpose = FALSE,
...,
device = NULL
)Arguments
- a
An mlx triangular matrix.
- b
Right-hand side matrix or vector.
- upper
Logical; if
TRUE,ais upper triangular, otherwise lower.- 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.- r
Triangular system matrix passed to
backsolve().- x
Right-hand side supplied to
backsolve().- k
Number of columns of
rto use.- upper.tri
Logical; indicates if
ris upper triangular.- transpose
Logical; if
TRUE, solvet(r) %*% x = b.- ...
Additional arguments forwarded to the corresponding base R implementation for signature compatibility.
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(2, 1, 0, 3), 2, 2)
b <- mlx_matrix(c(1, 5), 2, 1)
mlx_solve_triangular(a, b, upper = FALSE, device = "cpu")
#> mlx array [2 x 1]
#> dtype: float32
#> values:
#> [,1]
#> [1,] 0.5
#> [2,] 1.5