1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
//! # numeris
//!
//! Pure-Rust numerical algorithms library — high performance with SIMD support
//! (NEON, SSE2, AVX, AVX-512) while also supporting no-std for embedded and WASM
//! targets. Similar in scope to SciPy.
//!
//! **Documentation & examples:** <https://numeris-rs.dev/>
//!
//! ## Quick start
//!
//! ```
//! use numeris::{Matrix, Vector};
//!
//! // Solve a linear system Ax = b
//! let a = Matrix::new([
//! [2.0_f64, 1.0, -1.0],
//! [-3.0, -1.0, 2.0],
//! [-2.0, 1.0, 2.0],
//! ]);
//! let b = Vector::from_array([8.0, -11.0, -3.0]);
//! let x = a.solve(&b).unwrap(); // x = [2, 3, -1]
//! ```
//!
//! ## Modules
//!
//! - [`matrix`] — Fixed-size `Matrix<T, M, N>` with const-generic dimensions.
//! Stack-allocated `[[T; M]; N]` column-major storage (matches LAPACK conventions).
//! `Matrix::new()` accepts row-major input and transposes internally.
//! Includes arithmetic, indexing, norms, block operations, and iteration.
//! [`Vector<T, N>`] is a type alias for an N×1 column matrix (matching
//! nalgebra convention).
//!
//! - [`dynmatrix`] — Heap-allocated `DynMatrix<T>` with runtime dimensions
//! (requires `alloc` feature, included with `std`). `Vec<T>` column-major storage
//! (`col * nrows + row`). `from_rows()` accepts row-major data (transposes
//! internally); `from_slice()` accepts column-major data directly.
//! Implements [`MatrixRef`] / [`MatrixMut`], so all linalg free functions work
//! automatically. [`DynVector<T>`] newtype for single-index vector access.
//! Includes `DynLu`, `DynCholesky`, `DynQr`, `DynSvd`, `DynSymmetricEigen`,
//! `DynSchur` wrapper structs.
//!
//! - [`linalg`] — LU (partial pivoting), Cholesky (A = LL^H), QR (Householder),
//! SVD (Householder bidiagonalization + Golub-Kahan implicit-shift QR),
//! symmetric/Hermitian eigendecomposition (Householder tridiagonalization +
//! implicit QR with Wilkinson shift), and real Schur decomposition (Hessenberg
//! reduction + Francis double-shift QR). Each provides `solve()`, `inverse()`,
//! `det()`, `eigenvalues()`, etc. Free functions operate on
//! `&mut impl MatrixMut<T>` for in-place use; wrapper structs offer a
//! higher-level API. Convenience methods on both `Matrix` and `DynMatrix`.
//!
//! - [`ode`] — Fixed-step RK4 and 7 adaptive Runge-Kutta solvers (RKF45,
//! RKTS54, RKV65, RKV87, RKV98, RKV98NoInterp, RKV98Efficient). PI step-size
//! controller with dense output / interpolation. Supports both vector and
//! matrix state (e.g., state transition matrix propagation). RODAS4 L-stable
//! Rosenbrock method for stiff systems (vector state, user-supplied or
//! finite-difference Jacobians). Requires `ode` feature.
//!
//! - [`optim`] — Optimization: scalar root finding ([`optim::brent`],
//! [`optim::newton_1d`]), BFGS quasi-Newton minimization ([`optim::minimize_bfgs`]),
//! Gauss-Newton ([`optim::least_squares_gn`]) and Levenberg-Marquardt
//! ([`optim::least_squares_lm`]) nonlinear least squares. Finite-difference
//! Jacobian and gradient utilities. Requires `optim` feature.
//!
//! - [`control`] — Digital IIR filters: [`control::Biquad`] second-order section and
//! [`control::BiquadCascade`] for cascaded filters. Design functions for Butterworth
//! and Chebyshev Type I lowpass/highpass. [`control::Pid`] discrete-time PID controller
//! with anti-windup. [`control::lead_compensator`] and [`control::lag_compensator`] for
//! compensator design via bilinear transform. PID tuning via [`control::FopdtModel`]
//! (Ziegler-Nichols, Cohen-Coon, SIMC) and [`control::ziegler_nichols_ultimate`].
//! No `complex` feature dependency. Requires `control` feature.
//!
//! - [`estimate`] — State estimation: [`estimate::Ekf`] (Extended Kalman Filter),
//! [`estimate::Ukf`] (Unscented Kalman Filter), [`estimate::SrUkf`] (Square-Root UKF),
//! [`estimate::Ckf`] (Cubature Kalman Filter), [`estimate::rts_smooth`] (RTS smoother),
//! and [`estimate::BatchLsq`] (batch least-squares). Closure-based dynamics and
//! measurement models, Joseph-form covariance update, Merwe-scaled sigma points.
//! EKF and BatchLsq are fully no-std; sigma-point filters and RTS require `alloc`.
//! Requires `estimate` feature.
//!
//! - [`interp`] — Interpolation: [`interp::LinearInterp`], [`interp::HermiteInterp`],
//! [`interp::LagrangeInterp`] (barycentric), [`interp::CubicSpline`] (natural BCs),
//! and [`interp::BilinearInterp`] (2D rectangular grid).
//! Fixed-size (const N, stack-allocated, no-std) and dynamic variants (`Dyn*`, requires
//! `alloc`). Out-of-bounds evaluations extrapolate. Requires `interp` feature.
//!
//! - [`special`] — Special functions: [`special::gamma`], [`special::lgamma`],
//! [`special::digamma`], [`special::beta`] / [`special::lbeta`],
//! regularized incomplete gamma ([`special::gamma_inc`] / [`special::gamma_inc_upper`]),
//! regularized incomplete beta ([`special::betainc`]),
//! and error functions ([`special::erf`] / [`special::erfc`]).
//! Generic over `FloatScalar` (f32/f64), fully no-std. Requires `special` feature.
//!
//! - [`quad`] — Numerical quadrature (integration): [`quad::gauss_legendre`] (N-point
//! Gauss-Legendre, N=1..10,15,20), [`quad::adaptive_simpson`] (automatic subdivision),
//! [`quad::trapezoid`] and [`quad::simpson`] (composite rules). All no-alloc.
//! Requires `quad` feature.
//!
//! - [`stats`] — Statistical distributions with [`stats::ContinuousDistribution`] and
//! [`stats::DiscreteDistribution`] traits. Continuous: [`stats::Normal`],
//! [`stats::Uniform`], [`stats::Exponential`], [`stats::Gamma`], [`stats::Beta`],
//! [`stats::ChiSquared`], [`stats::StudentT`]. Discrete: [`stats::Bernoulli`],
//! [`stats::Binomial`], [`stats::Poisson`]. Built-in [`stats::Rng`] (xoshiro256++)
//! with `sample()` / `sample_array()` on every distribution.
//! Requires `stats` feature (implies `special`).
//!
//! - [`quaternion`] — Unit quaternion for 3D rotations. Scalar-first `[w, x, y, z]`.
//! Construct from axis-angle, Euler angles, or rotation matrices. Supports
//! Hamilton product, vector rotation, SLERP, and conversion back to matrices.
//!
//! - [`traits`] — Element trait hierarchy:
//! - [`Scalar`] — all matrix elements (`Copy + PartialEq + Debug + Zero + One + Num`)
//! - [`FloatScalar`] — real floats (`Scalar + Float`), used by quaternions
//! - [`LinalgScalar`] — real floats and complex numbers, used by decompositions and norms
//! - [`MatrixRef`] / [`MatrixMut`] — generic read/write access for algorithms
//!
//! ## Complex matrices
//!
//! Enable the `complex` feature to use decompositions with `Complex<f32>` /
//! `Complex<f64>`. Cholesky generalizes to Hermitian (A = LL^H), QR uses
//! complex Householder reflections, and norms return real values. Zero overhead
//! for real-only code paths.
//!
//! ## Cargo features
//!
//! | Feature | Default | Description |
//! |-----------|----------|-------------|
//! | `std` | yes | Implies `alloc`. Hardware FPU via system libm |
//! | `alloc` | via std | `DynMatrix` / `DynVector` (heap-allocated, runtime-sized) |
//! | `ode` | yes | ODE integration (RK4, adaptive solvers) |
//! | `optim` | no | Optimization (root finding, BFGS, Gauss-Newton, LM) |
//! | `control` | no | Digital IIR filters, PID, lead/lag compensators, PID tuning |
//! | `estimate`| no | State estimation (EKF, UKF). Implies `alloc` |
//! | `interp` | no | Interpolation (linear, Hermite, Lagrange, cubic spline, bilinear 2D) |
//! | `quad` | no | Numerical quadrature (Gauss-Legendre, adaptive Simpson, composite rules) |
//! | `special` | no | Special functions (gamma, beta, erf, incomplete gamma/beta) |
//! | `stats` | no | Statistical distributions (Normal, Gamma, etc.) with sampling. Implies `special` |
//! | `libm` | baseline | Pure-Rust software float fallback |
//! | `complex` | no | `Complex<f32>` / `Complex<f64>` support via `num-complex` |
//! | `nalgebra`| no | Conversions between numeris and nalgebra types |
//! | `serde` | no | Serialize/deserialize all types via serde |
//! | `all` | no | All features |
extern crate alloc;
pub use ;
pub use Matrix;
pub use ;
pub use ;
pub use ;
pub use Quaternion;
pub use ;
pub use Complex;