From 6bec56c4cce9d47d59f895005c28ee6a546dc1e4 Mon Sep 17 00:00:00 2001 From: Ignacia Piccardo Date: Fri, 3 Jul 2026 12:40:36 +0100 Subject: [PATCH 1/3] Cap fixed-rank ID after QR/SVD nullification --- src/rsrs/rsrs_factors/commutative_factors.rs | 15 +++++++++++---- src/utils/linear_algebra.rs | 19 ++++++++++++++++++- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/rsrs/rsrs_factors/commutative_factors.rs b/src/rsrs/rsrs_factors/commutative_factors.rs index 595460e..a020196 100644 --- a/src/rsrs/rsrs_factors/commutative_factors.rs +++ b/src/rsrs/rsrs_factors/commutative_factors.rs @@ -19,8 +19,8 @@ use crate::utils::{ row_perm, row_subs, }, linear_algebra::{ - block_extraction_into, streaming_chunk_rows, BlockExtractionMethod, - NormalEquationAccumulator, + block_extraction_into, fixed_rank_relative_tol, streaming_chunk_rows, + BlockExtractionMethod, NormalEquationAccumulator, NullMethod, }, memory::{matrix_bytes, trace_memory_event, trace_memory_growth}, }; @@ -536,6 +536,7 @@ where where StandardNormal: Distribution, Standard: Distribution, + Real: num::NumCast, LuDecomposition, 2>>: MatrixLuDecomposition, QrDecomposition, 2>>: @@ -582,6 +583,12 @@ where }; return (None, Times::Id(id_times)); } + let fixed_rank_accuracy = |rank: usize| match id_options.null_method { + NullMethod::Svd | NullMethod::Qr => { + Accuracy::MinRank(fixed_rank_relative_tol::(), rank) + } + NullMethod::Projection => Accuracy::FixedRank(rank), + }; let id_sketch = match rank_par { BoxType::Full(tol) => { // for a box that hasn't been merged yet it @@ -605,7 +612,7 @@ where .r_mut() .into_subview([0, 0], null_shape) .into_id_alloc_no_skel( - Accuracy::FixedRank(loc_rank), + fixed_rank_accuracy(loc_rank), id_options.qr_method.clone(), TransMode::Trans, ) @@ -619,7 +626,7 @@ where .r_mut() .into_subview([0, 0], null_shape) .into_id_alloc_no_skel( - Accuracy::FixedRank((*rank).min(max_rank)), + fixed_rank_accuracy((*rank).min(max_rank)), id_options.qr_method.clone(), TransMode::Trans, ) diff --git a/src/utils/linear_algebra.rs b/src/utils/linear_algebra.rs index e8c0e84..42a4528 100644 --- a/src/utils/linear_algebra.rs +++ b/src/utils/linear_algebra.rs @@ -1,4 +1,4 @@ -use num::{Float, One, Zero}; +use num::{Float, NumCast, One, Zero}; use rlst::dense::linalg::{lu::MatrixLu, null_space::Method}; pub use rlst::prelude::*; use serde::Deserialize; @@ -93,6 +93,17 @@ pub fn add_diagonal( } } +pub fn fixed_rank_relative_tol() -> Real +where + Real: NumCast, +{ + if std::mem::size_of::>() <= std::mem::size_of::() { + NumCast::from(1e-5f64).unwrap() + } else { + NumCast::from(1e-10f64).unwrap() + } +} + fn normal_equation_scale(normal: &DynamicArray) -> Real { let shape = normal.shape(); let view = normal.r(); @@ -421,4 +432,10 @@ mod tests { .iter() .all(|entry| Float::abs(*entry) <= f64::EPSILON)); } + + #[test] + fn fixed_rank_relative_tol_depends_on_precision() { + assert_eq!(fixed_rank_relative_tol::(), 1e-5f32); + assert_eq!(fixed_rank_relative_tol::(), 1e-10f64); + } } From 0b0b008e01883da9be6b0c4ca666ff22a8af806b Mon Sep 17 00:00:00 2001 From: Ignacia Piccardo Date: Fri, 3 Jul 2026 15:12:47 +0100 Subject: [PATCH 2/3] Pin rlst revision with MinRank support --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index f258460..99ff60f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,7 @@ itertools = "0.14.*" rand = { version = "0.8.5", features = ["alloc"] } rand_chacha = "0.3.*" num = "0.4.*" -rlst = { git = "https://github.com/ignacia-fp/rlst.git", branch = "extend_abstract_operator", features = [ +rlst = { git = "https://github.com/ignacia-fp/rlst.git", rev = "90da192c9563edf4b54a3728819f80ad093f4296", features = [ "enable_tracing", "mpi", ] } From 99f621fcf86c2d534cca542861ab923a619e6e12 Mon Sep 17 00:00:00 2001 From: Ignacia Piccardo Date: Fri, 3 Jul 2026 16:00:24 +0100 Subject: [PATCH 3/3] Use branch-based rlst dependency --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 99ff60f..f258460 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,7 @@ itertools = "0.14.*" rand = { version = "0.8.5", features = ["alloc"] } rand_chacha = "0.3.*" num = "0.4.*" -rlst = { git = "https://github.com/ignacia-fp/rlst.git", rev = "90da192c9563edf4b54a3728819f80ad093f4296", features = [ +rlst = { git = "https://github.com/ignacia-fp/rlst.git", branch = "extend_abstract_operator", features = [ "enable_tracing", "mpi", ] }