pub fn solve<B: Backend, T: LinalgScalar>(
a: &Array<B, T>,
b: &Array<B, T>,
) -> Array<B, T>Expand description
Solves a x = b for x, as jnp.linalg.solve: b of shape [n] is a
vector (the result is [..., n]), otherwise a batch of matrices
[..., n, k] whose batch dimensions broadcast with a’s. The solve
uses the LU factorization of a; singular matrices give infinities or
NaNs.
JAX differentiates the solve implicitly (custom_linear_solve); ruxla
differentiates through the factorization, which gives the same
derivatives.
§Panics
Panics if a is not a batch of square matrices or the shapes do not
match.
§Examples
use ruxla_core::{Array, Native, jnp};
let a = Array::<Native, f64>::from_vec(vec![2.0, 1.0, 1.0, 3.0], [2, 2]);
let b = Array::<Native, f64>::from_vec(vec![3.0, 5.0], [2]);
let x = jnp::linalg::solve(&a, &b).to_vec();
assert!((x[0] - 0.8).abs() < 1e-12 && (x[1] - 1.4).abs() < 1e-12);