pub struct Scaling<T: Real = f64> {
pub row: Vec<T>,
pub col: Vec<T>,
}Expand description
Row and column factors: A' = diag(row) · A · diag(col) (invariants
(S8), (S9)).
Fields§
§row: Vec<T>r_i, one per row.
col: Vec<T>c_j, one per column.
Implementations§
Source§impl<T: Real> Scaling<T>
impl<T: Real> Scaling<T>
Sourcepub fn compute(a: &CscMatrix<T>, policy: Equilibration) -> Self
pub fn compute(a: &CscMatrix<T>, policy: Equilibration) -> Self
The factors of a under policy (Algorithms G, R, I).
use xingo_sparse::{CscMatrix, Col, Equilibration, Row, Scaling};
let a = CscMatrix::from_triplets(2, 2, &[
(Row(0), Col(0), 1e-3), (Row(1), Col(0), 4.0), (Row(1), Col(1), 1e3),
])
.unwrap();
let policy = Equilibration::Geometric { max_iters: 4, power_of_two: true };
let s = Scaling::compute(&a, policy);
assert!(s.spread(&a) < 1e6); // the spread of `a` itself is 1e3 / 1e-3
let mut b = a.clone();
s.apply(&mut b);
s.unapply(&mut b);
assert_eq!(a, b); // (S8): powers of two round-trip exactlySourcepub fn apply(&self, a: &mut CscMatrix<T>)
pub fn apply(&self, a: &mut CscMatrix<T>)
A ← diag(row) · A · diag(col) in place.
§Panics
If the factor lengths do not match the dimensions of a.
Sourcepub fn unapply(&self, a: &mut CscMatrix<T>)
pub fn unapply(&self, a: &mut CscMatrix<T>)
A ← diag(row)⁻¹ · A · diag(col)⁻¹ in place: the inverse of
Scaling::apply, exactly so for powers of two ((S8)).
§Panics
If the factor lengths do not match the dimensions of a.
Sourcepub fn spread(&self, a: &CscMatrix<T>) -> T
pub fn spread(&self, a: &CscMatrix<T>) -> T
The spread max|a'| / min|a'| over the nonzeros of the scaled
matrix a' = diag(row) · a · diag(col) (a itself is not
modified); one when a has no nonzeros.
§Panics
If the factor lengths do not match the dimensions of a.
Sourcepub fn check_invariants(&self) -> Result<(), SparseError>
pub fn check_invariants(&self) -> Result<(), SparseError>
Checks (S9): every factor finite and positive.
Trait Implementations§
impl<T: PartialEq + Real> StructuralPartialEq for Scaling<T>
Auto Trait Implementations§
impl<T> Freeze for Scaling<T>
impl<T> RefUnwindSafe for Scaling<T>where
T: RefUnwindSafe,
impl<T> Send for Scaling<T>where
T: Send,
impl<T> Sync for Scaling<T>where
T: Sync,
impl<T> Unpin for Scaling<T>where
T: Unpin,
impl<T> UnsafeUnpin for Scaling<T>
impl<T> UnwindSafe for Scaling<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more