Skip to main content

qdwh

Function qdwh 

Source
pub fn qdwh<B: Backend, T: LinalgScalar>(
    x: &Array<B, T>,
    max_iterations: Option<usize>,
    eps: Option<f64>,
    dynamic_shape: Option<(I32<B>, I32<B>)>,
) -> (Array<B, T>, Array<B, T>, I32<B>, Bool<B>)
Expand description

The polar decomposition x = u h of a full-rank matrix (m x n with m >= n) by the QR-based dynamically weighted Halley iteration, as lax.linalg.qdwh: (u, h, num_iters, is_converged) with u (m x n) having orthonormal columns and h (n x n) Hermitian positive semidefinite. The iteration follows JAX’s (jax._src.tpu.linalg.qdwh): the scaling by 1 / sqrt(|x|_1 |x|_inf), the weights of the steps computed in advance from the lower bound eps of the smallest singular value (QR steps while c > 100, then Cholesky steps), Halley’s steps until |u_k - u_{k-1}|_F <= (5 eps)^(1/3) within max_iterations (10 by default), and a Newton-Schulz refinement. eps defaults to the machine epsilon of T. With dynamic_shape (m, n), x is a matrix padded from its true shape m x n (which may be traced values), as in JAX: the entries outside are taken as zeros and stay zeros. (JAX’s unused is_hermitian is left out.)

§Examples

use ruxla_core::{Array, Native, jnp, lax::linalg::qdwh};

let x = Array::<Native, f64>::from_vec(vec![3.0, 1.0, 1.0, 2.0, 0.0, 1.0], [3, 2]);
let (u, h, _, converged) = qdwh(&x, None, None, None);
assert!(converged.value());
let back = jnp::matmul(&u, &h).to_vec();
for (got, expected) in back.iter().zip(x.to_vec()) {
    assert!((got - expected).abs() < 1e-12);
}

§Panics

Panics if x is not a matrix with at least as many rows as columns.