pub struct Qr<T: Real = f64, K: DenseKernel<T> = NaiveDense> {
q: DenseBlock<T>,
r: DenseBlock<T>,
kernel: K,
opts: QrOptions,
}Expand description
Thin QR A = QR, Q ∈ R^{m×n} explicit with orthonormal columns, R ∈ R^{n×n} upper triangular with r_jj > 0, m ≥ n, full column rank
(Chapter 12.3: Algorithms F, I, D, C, E, R).
use xingo_statla::{MatRef, Qr, QrOptions};
// A = [1 0; 1 1; 1 2] (column-major), b = (1, 2, 4).
let a = [1.0, 1.0, 1.0, 0.0, 1.0, 2.0];
let mut f = Qr::factor(MatRef::new(3, 2, 3, &a)?, &QrOptions::default())?;
let mut x = [0.0; 2];
let res = f.solve_least_squares(&[1.0, 2.0, 4.0], &mut x)?;
assert!((x[0] - 5.0 / 6.0).abs() < 1e-14 && (x[1] - 1.5).abs() < 1e-14);
assert!((res - (1.0f64 / 6.0).sqrt()).abs() < 1e-14);
f.insert_row(3, &[1.0, 3.0])?; // a fourth observation
f.delete_row(0)?; // and the first leaves
assert_eq!((f.nrows(), f.ncols()), (3, 2));
assert!(f.check_invariants(16.0).is_ok());Fields§
§q: DenseBlock<T>§r: DenseBlock<T>§kernel: K§opts: QrOptionsImplementations§
Source§impl<T: Real> Qr<T, NaiveDense>
impl<T: Real> Qr<T, NaiveDense>
Sourcepub fn factor(a: MatRef<'_, T>, opts: &QrOptions) -> Result<Self, StatlaError>
pub fn factor(a: MatRef<'_, T>, opts: &QrOptions) -> Result<Self, StatlaError>
Householder QR of A (m ≥ n), Q formed explicitly.
§Errors
StatlaError::InvalidArgument (m < n, invalid options),
StatlaError::NonFinite, StatlaError::RankDeficient.
Source§impl<T: Real, K: DenseKernel<T>> Qr<T, K>
impl<T: Real, K: DenseKernel<T>> Qr<T, K>
Sourcepub fn factor_with(
a: MatRef<'_, T>,
kernel: K,
opts: &QrOptions,
) -> Result<Self, StatlaError>
pub fn factor_with( a: MatRef<'_, T>, kernel: K, opts: &QrOptions, ) -> Result<Self, StatlaError>
Sourcepub fn insert_row(&mut self, i: usize, w: &[T]) -> Result<(), StatlaError>
pub fn insert_row(&mut self, i: usize, w: &[T]) -> Result<(), StatlaError>
Insert the row w (length n) before row i (i = m appends)
(Algorithm I).
§Errors
StatlaError::Dimension, StatlaError::InvalidArgument,
StatlaError::NonFinite; unchanged on error (Q3).
Sourcepub fn delete_row(&mut self, i: usize) -> Result<(), StatlaError>
pub fn delete_row(&mut self, i: usize) -> Result<(), StatlaError>
Delete row i (requires m > n) (Algorithm D).
§Errors
StatlaError::InvalidArgument, StatlaError::RankDeficient
(with column = i: the rows left are rank deficient); unchanged on
error (Q3).
Sourcepub fn insert_col(&mut self, j: usize, c: &[T]) -> Result<(), StatlaError>
pub fn insert_col(&mut self, j: usize, c: &[T]) -> Result<(), StatlaError>
Insert the column c (length m) before column j (requires m > n) (Algorithm C).
§Errors
StatlaError::Dimension, StatlaError::InvalidArgument,
StatlaError::NonFinite, StatlaError::RankDeficient;
unchanged on error.
Sourcepub fn delete_col(&mut self, j: usize) -> Result<(), StatlaError>
pub fn delete_col(&mut self, j: usize) -> Result<(), StatlaError>
Sourcepub fn rank1_update(&mut self, u: &[T], v: &[T]) -> Result<(), StatlaError>
pub fn rank1_update(&mut self, u: &[T], v: &[T]) -> Result<(), StatlaError>
A ← A + u vᵀ (u of length m, v of length n) (Algorithm
R).
§Errors
StatlaError::Dimension, StatlaError::NonFinite,
StatlaError::RankDeficient (the result lost rank); unchanged on
error.
Sourcepub fn solve_least_squares(
&self,
b: &[T],
x: &mut [T],
) -> Result<T, StatlaError>
pub fn solve_least_squares( &self, b: &[T], x: &mut [T], ) -> Result<T, StatlaError>
x = argmin ‖A x − b‖ (x ← R⁻¹ Qᵀ b); returns ‖b − Q Qᵀ b‖,
the residual norm.
§Errors
Sourcepub fn to_cholesky(&self) -> Result<Cholesky<T, K>, StatlaError>where
K: Clone,
pub fn to_cholesky(&self) -> Result<Cholesky<T, K>, StatlaError>where
K: Clone,
The Q-less view: a Cholesky of AᵀA holding a copy of R
(with the default CholOptions).
§Errors
Sourcefn check_shape(&self) -> Result<(), &'static str>
fn check_shape(&self) -> Result<(), &'static str>
The shape part of (Q2): consistent blocks, R upper triangular with
finite entries and positive diagonal, Q finite. O(mn).