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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
//! # 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. Fixed-size routines are no-alloc;
//! dynamic-dimension counterparts ([`optim::minimize_bfgs_dyn`],
//! [`optim::least_squares_gn_dyn`], [`optim::least_squares_lm_dyn`],
//! [`optim::finite_difference_gradient_dyn`],
//! [`optim::finite_difference_jacobian_dyn`]) operate on
//! [`DynVector`] / [`DynMatrix`] and require the `alloc` feature.
//! 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.
//!
//! - [`imageproc`] — 2D image processing on `DynMatrix` buffers. Full
//! toolkit: convolution ([`imageproc::convolve2d`],
//! [`imageproc::convolve2d_separable`]), blurs / sharpening / gradients /
//! Laplacian / LoG, order-statistic filters (quickselect and
//! Huang sliding-histogram for u16), morphology (Van Herk max/min plus
//! opening / closing / top-hat / black-hat / morphology gradient),
//! integral image and local mean / variance / stddev, thresholding
//! (binary / Otsu / adaptive), Canny edge detection, Harris and
//! Shi-Tomasi corners, difference of Gaussians and Gaussian pyramid,
//! connected-components labeling (SAUF union-find, 4- or 8-connectivity,
//! with per-component area / bbox / centroid / second moments, and
//! optional `DynMatrix<u32>` or row-major `Vec<u32>` labels image),
//! geometric utilities (flip, rotate 90°/180°/270°, pad, crop,
//! resize bilinear and nearest). See [`imageproc`] module for details.
//! Requires `imageproc` feature (implies `alloc`).
//!
//! - [`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) |
//! | `imageproc` | no | 2D image processing: filters, morphology, integral image, thresholding, Canny, corners, DoG, pyramid, geometric. Implies `alloc` |
//! | `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 |
//! | `rayon` | no | Multi-threaded parallelism on runtime-sized paths (e.g. dynamic finite-difference Jacobians, most `imageproc` filters). Implies `std` |
//! | `all` | no | All features |
//!
//! ## Parallelism
//!
//! SIMD is always-on and parallelizes *within* a core; the optional `rayon`
//! feature parallelizes *across* cores, and the two compose. It is opt-in
//! (rayon needs `std`, so it is never part of the no-std baseline) and purely
//! additive — builds without it are unchanged. Only heap-backed, runtime-sized
//! paths with independent, disjoint output columns are parallelized: dynamic
//! finite-difference Jacobians (the separate `_par` routines
//! [`optim::finite_difference_jacobian_dyn_par`],
//! [`optim::finite_difference_gradient_dyn_par`]) and most `imageproc` filters
//! (convolution/blur, rank & median, morphology, resize, local statistics).
//! Small fixed-size [`Matrix`] operations and order-sensitive reductions are
//! never parallelized. Each routine gates on total work (so small inputs stay
//! sequential) and writes to disjoint slices, so results are identical
//! regardless of thread count. Speedups run ~2.5–4× on large images.
//!
//! The feature is purely additive — it never changes an existing signature
//! (the parallel optim routines are *new* `_par` functions; the sequential ones
//! keep their `FnMut` bound).
// Coefficient tables (quadrature nodes/weights, Runge-Kutta tableaux, Lanczos
// constants, …) are written at full published precision. The extra digits beyond
// f64 are harmless (the compiler rounds to the nearest representable value), so
// allow the lint crate-wide rather than truncating documented source values.
// Numerical code legitimately favors index-based loops: 2D access (`a[i][j]`,
// `A[k][j]`), parallel indexing of several arrays by the same index, and
// `f(i, j)` element constructors are clearer with explicit indices than with
// zipped iterators. `needless_range_loop` is a known false positive here.
// Iterative solvers (BFGS, Gauss-Newton, LM, …) keep evaluation counters
// (`f_evals`, `j_evals`) that are *not* loop counters — they increment
// conditionally / multiple times per iteration (line search, etc.), so they
// cannot be replaced by `enumerate()`.
// Low-level numeric kernels (SIMD matmul with strides, Van Herk passes, ODE
// `integrate` entry points) genuinely need many parameters (dimensions, scratch
// buffers, callbacks); factoring them into structs would only obscure the math.
extern crate alloc;
// The `par` module backs the parallel paths: `imageproc` (always, sequential or
// parallel) and the `optim` `_par` routines (only under `rayon`).
// Marker trait used in public `imageproc` signatures; an implementation detail
// of the `rayon` feature, hidden from the docs.
pub use MaybeSync;
pub use ;
pub use ;
pub use ;
pub use ;
pub use Matrix;
pub use Quaternion;
pub use ;
pub use Complex;