tpt-math-numeric
Scalar numeric trait glue for the tpt-math substrate. This crate is a thin
wrapper over num-traits (and,
optionally, libm) that re-exports the numeric
traits the rest of the workspace builds on and adds a single Scalar
supertrait meaning "a floating-point scalar type we can do math on".
Part of tpt-math
tpt-math-numeric is the bottom layer of
tpt-math: every other crate in the
workspace either depends on it directly or is generic over the traits it
re-exports. Its core is the trait vocabulary (Float, Num, NumCast,
FloatConst, Real, the Checked* family, …) so that higher layers agree on
one numeric hierarchy instead of each importing num-traits with its own
feature set. It also carries a set of no_std-friendly numerical routines,
listed under Modules.
Features
std(default) — enablesnum-traits'std-dependent items.alloc— enablesextern crate alloc. The dense-output and event ODE code, and thesensitivitymodule, need it.libm— re-exportslibmso callers can do transcendental math onno_stdtargets.
Modules
report—SolveReport<T>andSolveStatus(Converged,NotConverged,Breakdown), shared by the solver crates.quadrature—simpson,gauss_legendre(fixedN-point rule) andadaptive_gauss_legendre, plusgauss_kronrod_15andadaptive_gauss_kronrod. The adaptive Kronrod rule handles integrable endpoint singularities such as1/√x.roots—bisectandbrentbracketing root finders, returningRootErroron failure.ode—rk4_stepandrk4_integrateon fixed-size state arrays;dopri5_integrate(adaptive Dormand–Prince 5(4), integrating backwards whent1 < t0);dopri5_dense, which returns aDenseSolutionwitheval(t)at any time in the span; anddopri5_events, which locates sign changes of an event function by bisection on the dense output.stiff—rosenbrock2_integrate, the L-stable second-order Rosenbrock method ROS2 with step-doubling error control. It takes the Jacobian.sensitivity(alloc) —forward_sensitivity, which integrates a system and its parameter sensitivities∂y/∂ptogether.
The crate is #![no_std] unconditionally; the std feature only widens what
num-traits itself offers. num-traits is always built with its libm
backend, so float math works without std.
Quick start
[]
= "0.2"
use *;
// Generic over any float: f32, f64, or a downstream scalar newtype.
assert_eq!;
assert!;
Scalar is a blanket supertrait: impl<T: Float + NumCast + FloatConst> Scalar
for T {}, so f32 and f64 satisfy it with no extra work. The prelude
module re-exports Float, FloatConst, Num, NumCast, One, Real,
Scalar, Signed, Unsigned and Zero; the crate root additionally
re-exports the checked-arithmetic traits, Pow, Inv, PrimInt,
FromPrimitive/ToPrimitive, the cast module and num_traits itself.
Notes
- On
no_stdtargets, disable default features and enablelibmif you needlibm's free functions directly:tpt-math-numeric = { version = "0.2", default-features = false, features = ["libm"] }. Scalarintentionally requiresFloat, so integer types do not implement it; use the re-exportedNum/PrimIntbounds for integer-generic code.- Upstream
num-traitsisMIT OR Apache-2.0and the optionallibmis MIT, both compatible with this crate's dual license.
License
Licensed under either of MIT or Apache-2.0 at your option.