use pounce_common::types::{Index, Number};
pub trait TSymScalingMethod {
fn compute_sym_t_scaling_factors(
&mut self,
n: Index,
nnz: Index,
airn: &[Index],
ajcn: &[Index],
a: &[Number],
scaling_factors: &mut [Number],
) -> bool;
}
#[derive(Debug, Default, Clone, Copy)]
pub struct IdentityScalingMethod;
impl TSymScalingMethod for IdentityScalingMethod {
fn compute_sym_t_scaling_factors(
&mut self,
n: Index,
_nnz: Index,
_airn: &[Index],
_ajcn: &[Index],
_a: &[Number],
scaling_factors: &mut [Number],
) -> bool {
debug_assert_eq!(scaling_factors.len(), n as usize);
for s in scaling_factors.iter_mut() {
*s = 1.0;
}
true
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn identity_writes_unit_factors() {
let mut method = IdentityScalingMethod;
let irn = [1, 2, 2];
let jcn = [1, 1, 2];
let vals = [2.0, 1.0, 3.0];
let mut s = vec![0.0; 2];
assert!(method.compute_sym_t_scaling_factors(2, 3, &irn, &jcn, &vals, &mut s));
assert_eq!(s, &[1.0, 1.0]);
}
}