macro_rules! try_with_rational_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) => { ... };
}Available on crate feature
exact only.Expand description
Fallibly dispatch a runtime dimension to a concrete exact rational matrix.
The macro creates a zero RationalMatrix with the selected const-generic
dimension, then evaluates the supplied closure body. Dimensions 0..=8 are
supported on stable Rust. The closure may fill the matrix through
RationalMatrix::set or replace it with a value built by
RationalMatrix::try_from_fn.
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_RATIONAL_MATRIX_DISPATCH_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_rational_matrix!(requested, |mut matrix| -> Result<
DeterminantSign,
LaError,
> {
for index in 0..requested {
matrix.set(index, index, BigRational::from_integer(1.into()))?;
}
Ok(matrix.det_sign())
})?;
assert_eq!(sign, DeterminantSign::Positive);