macro_rules! try_with_stack_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 stack-allocated matrix.
The macro creates a zero matrix with type Matrix<N> for the selected
runtime dimension N, then evaluates the supplied closure body. Supported
runtime dimensions run from 0 through MAX_STACK_MATRIX_DISPATCH_DIM.
Unsupported dimensions return
Err(LaError::UnsupportedDimension { requested, max }) converted with
From<LaError>, so downstream crates can use their own public error type.
§Errors
Returns LaError::UnsupportedDimension (converted through From<LaError>)
when the requested runtime dimension is greater than
MAX_STACK_MATRIX_DISPATCH_DIM. The closure body may return any other
error representable by its declared Result type.
§Examples
use la_stack::prelude::*;
let requested = 2usize;
let det = try_with_stack_matrix!(requested, |mut m| -> Result<f64, LaError> {
m.set_checked(0, 0, 1.0)?;
m.set_checked(1, 1, 1.0)?;
m.det()
})?;
assert_eq!(det, 1.0);