Skip to main content

try_with_interval_matrix

Macro try_with_interval_matrix 

Source
macro_rules! try_with_interval_matrix {
    ($dim:expr, |$matrix:ident| -> $ret:ty $body:block $(,)?) => { ... };
    ($dim:expr, |mut $matrix:ident| -> $ret:ty $body:block $(,)?) => { ... };
    (@arm $d:literal, $matrix:ident, $ret:ty, $body:block) => { ... };
    (@arm_mut $d:literal, $matrix:ident, $ret:ty, $body:block) => { ... };
}
Expand description

Fallibly dispatch a runtime dimension to a concrete interval matrix.

The macro creates a zero IntervalMatrix with the selected const-generic dimension, then evaluates the closure body. Supported dimensions run from 0 through MAX_INTERVAL_MATRIX_DIM. Unsupported dimensions return LaError::UnsupportedDimension converted through From<LaError>. The body may mutate or consume captured values. It is not evaluated for unsupported dimensions.

§Errors

Returns LaError::UnsupportedDimension (converted through From<LaError>) when the requested dimension is greater than MAX_INTERVAL_MATRIX_DIM. The closure body may return any other error representable by its declared Result type.

§Examples

use la_stack::prelude::*;

let requested = 3usize;
let sign = try_with_interval_matrix!(requested, |mut matrix| -> Result<
    IntervalDeterminantSign,
    LaError,
> {
    for index in 0..requested {
        matrix.set(index, index, Interval::ONE)?;
    }
    matrix.det_sign()
})?;
assert_eq!(sign, IntervalDeterminantSign::Positive);