#[derive(Debug, Clone)]
pub struct LowRankConfig {
pub rank: usize,
pub max_iterations: usize,
pub tolerance: f64,
pub normalize: bool,
pub error_threshold: f64,
pub min_dimension: usize,
}
impl LowRankConfig {
pub fn new(rank: usize) -> Self {
LowRankConfig {
rank,
..Default::default()
}
}
pub fn with_tolerance(mut self, tol: f64) -> Self {
self.tolerance = tol;
self
}
pub fn with_error_threshold(mut self, threshold: f64) -> Self {
self.error_threshold = threshold;
self
}
pub fn with_max_iterations(mut self, max_iter: usize) -> Self {
self.max_iterations = max_iter;
self
}
pub fn with_min_dimension(mut self, min_dim: usize) -> Self {
self.min_dimension = min_dim;
self
}
}
impl Default for LowRankConfig {
fn default() -> Self {
LowRankConfig {
rank: 4,
max_iterations: 100,
tolerance: 1e-6,
normalize: true,
error_threshold: 0.1,
min_dimension: 32,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_low_rank_config_default() {
let cfg = LowRankConfig::default();
assert_eq!(cfg.rank, 4);
assert_eq!(cfg.max_iterations, 100);
assert!((cfg.tolerance - 1e-6).abs() < 1e-15);
assert!(cfg.normalize);
assert!((cfg.error_threshold - 0.1).abs() < 1e-15);
assert_eq!(cfg.min_dimension, 32);
}
#[test]
fn test_low_rank_config_builder() {
let cfg = LowRankConfig::new(8)
.with_tolerance(1e-4)
.with_error_threshold(0.05)
.with_max_iterations(50)
.with_min_dimension(16);
assert_eq!(cfg.rank, 8);
assert!((cfg.tolerance - 1e-4).abs() < 1e-15);
assert!((cfg.error_threshold - 0.05).abs() < 1e-15);
assert_eq!(cfg.max_iterations, 50);
assert_eq!(cfg.min_dimension, 16);
}
}