Report factor value bytes and preserve overflow-safe reduction limits

This commit is contained in:
Preetinder Kalsi authored and Irakli Kourtis committed 2026-10-15 14:00:56 -04:00
1 parent c7d0a82079
commit a530a0d914
7 files changed
+80 -12

No files matched your search

+24
View File
@@ -76,6 +76,14 @@ pub enum Error {
pub type Result<T> = std::result::Result<T, Error>;
impl Error {
/// Factor-value bytes alone; indices and numeric workspace need additional memory.
pub(crate) fn factor_limit(entries: usize, limit: usize) -> Error {
let bytes = entries as u128 * std::mem::size_of::<f64>() as u128;
Error::Limit(format!(
"the factorization needs {entries} entries ({bytes} bytes of factor values alone; indices and workspace are additional); the limit is {limit} entries (refine less or raise max_factor_entries)"
))
}
/// A kernel error, naming the element.
pub fn element(label: u32, source: fieldcraft_fem::Error) -> Error {
Error::Element { label, source }
@@ -112,3 +120,19 @@ impl Default for Limits {
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn factor_limit_estimates_bytes_without_allocating_the_factor() {
for (entries, bytes) in [(467_000_000, "3736000000"), (2_000_000_000, "16000000000")] {
let e = Error::factor_limit(entries, 400_000_000).to_string();
assert!(e.contains(&format!("{entries} entries ({bytes} bytes of factor values alone")), "{e}");
assert!(e.contains("indices and workspace are additional"), "{e}");
assert!(e.contains("limit is 400000000 entries"), "{e}");
assert!(e.contains("raise max_factor_entries"), "{e}");
}
}
}