wls_alloc/types.rs
1//! Core types and constants shared across the crate.
2
3use nalgebra::{Const, OMatrix, OVector};
4
5/// Constraint feasibility tolerance for f32 (matches C `AS_CONSTR_TOL` with `AS_SINGLE_FLOAT`).
6pub const CONSTR_TOL: f32 = 1e-4;
7
8/// Minimum diagonal value used when normalising actuator weights.
9pub(crate) const MIN_DIAG_CLAMP: f32 = 1e-6;
10
11/// Solver exit status.
12#[derive(Debug, Clone, Copy, PartialEq, Eq)]
13#[repr(u8)]
14pub enum ExitCode {
15 /// Optimal feasible solution found.
16 Success = 0,
17 /// Maximum iteration count reached without convergence.
18 IterLimit = 1,
19 // CostBelowTol (2) and CostPlateau (3) are not implemented — they only
20 // applied to the Cholesky solver's optional cost-truncation mode, which
21 // this crate does not port.
22 /// NaN detected in QR solve (indicates singular or near-singular subproblem).
23 NanFoundQ = 4,
24 /// NaN detected in solution update.
25 NanFoundUs = 5,
26}
27
28/// Statistics returned by the solver alongside the solution.
29#[derive(Debug, Clone, Copy)]
30pub struct SolverStats {
31 /// How the solver terminated.
32 pub exit_code: ExitCode,
33 /// Number of active-set iterations performed.
34 pub iterations: usize,
35 /// Number of free (unconstrained) actuators at the solution.
36 pub n_free: usize,
37}
38
39/// Convenience alias for an `NC × NU` matrix (column-major, f32).
40pub type MatA<const NC: usize, const NU: usize> = OMatrix<f32, Const<NC>, Const<NU>>;
41
42/// Convenience alias for an `N`-element column vector (f32).
43pub type VecN<const N: usize> = OVector<f32, Const<N>>;