pub trait SparseScaling<R: Runtime> {
// Required methods
fn row_norms<T: Element + Default + Copy>(
&self,
norm: NormType,
) -> Result<Tensor<R>>;
fn col_norms<T: Element + Default + Copy>(
&self,
norm: NormType,
) -> Result<Tensor<R>>;
fn scale_rows<T: Element + Default + Copy + Mul<Output = T>>(
&self,
scales: &[T],
) -> Result<Self>
where Self: Sized;
fn scale_cols<T: Element + Default + Copy + Mul<Output = T>>(
&self,
scales: &[T],
) -> Result<Self>
where Self: Sized;
fn equilibrate<T: Element + Default + Copy + Float>(
&self,
) -> Result<(Self, Vec<T>, Vec<T>)>
where Self: Sized;
}Expand description
Sparse matrix scaling and equilibration operations
These utilities improve numerical stability for sparse linear systems, particularly important for ODE/DAE Jacobians which may be badly scaled.
§Example
// Create a sample CSC matrix
// Equilibrate a badly-scaled matrix
let (scaled, row_scales, col_scales) = csc.equilibrate::<f64>()?;
// Scaling factors can be applied to solve Ax = b
// becomes (R A C)(C⁻¹x) = RbRequired Methods§
Sourcefn scale_rows<T: Element + Default + Copy + Mul<Output = T>>(
&self,
scales: &[T],
) -> Result<Self>where
Self: Sized,
fn scale_rows<T: Element + Default + Copy + Mul<Output = T>>(
&self,
scales: &[T],
) -> Result<Self>where
Self: Sized,
Sourcefn scale_cols<T: Element + Default + Copy + Mul<Output = T>>(
&self,
scales: &[T],
) -> Result<Self>where
Self: Sized,
fn scale_cols<T: Element + Default + Copy + Mul<Output = T>>(
&self,
scales: &[T],
) -> Result<Self>where
Self: Sized,
Sourcefn equilibrate<T: Element + Default + Copy + Float>(
&self,
) -> Result<(Self, Vec<T>, Vec<T>)>where
Self: Sized,
fn equilibrate<T: Element + Default + Copy + Float>(
&self,
) -> Result<(Self, Vec<T>, Vec<T>)>where
Self: Sized,
Equilibrate the matrix for better numerical stability.
Computes row and column scalings to make all row and column infinity-norms approximately 1. Uses iterative scaling: row-scale, then column-scale, then row-scale again (one iteration is usually sufficient).
§Returns
Tuple of:
- Scaled matrix (same sparsity pattern)
- Row scales
`[nrows]` - Column scales
`[ncols]`
To undo the scaling on the solution:
- If solving Ax = b, the scaled system is (RAC) * (C⁻¹x) = Rb
- After solving, recover x = C * scaled_x
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.