statrs-dev/statrs
Statistical computation library for Rust
statrs is a Rust library that gives programmers a collection of statistical tools for scientific computing. It was started as a port of the statistical features found in the C# library Math.NET, and it aims to keep growing by adding more distributions and utilities over time.
What’s inside?
- Common probability distributions – e.g., Normal, Exponential, Student’s T, Gamma, Uniform – that you can sample from.
- Frequent statistical functions – like the gamma function, beta function, and error function.
How do I use it?
Add the latest version to your Cargo.toml as a dependency, then check the official documentation (linked in the README) for examples. It’s a typical Rust crate.
Special environments
no_std: If you disable default features, you can use statrs without the standard library. Heap-based APIs rely on Rust’salloccrate, so you’ll need to provide your own global allocator in that case (statrs doesn’t select one for you).- WebAssembly: On
wasm32-unknown-unknown, sampling works with an explicitly seeded random number generator. To use JavaScript entropy (e.g., withrand::rng()), you must choose your owngetrandombackend – statrs leaves that choice to you.
Testing and data
The test suite includes optional tests that download data from NIST (a US standards agency). A script (tests/gather_nist_data.sh) fetches the data; you can run those tests with a special flag. The location of the data can be changed via an environment variable.
Minimum Rust version You need Rust 1.89.0 or higher. Future increases in the minimum version will be treated as a non-breaking change (a version bump, not a breaking API change).
Precision matters Floating-point numbers can’t always represent decimals exactly, which can cause errors to build up. The library takes precision seriously: it uses standardized checks, defines default accuracy constants (like relative accuracy, epsilon, and ULPs), and documents any module‑specific settings. Internal precision utilities are now hidden (since v0.19.0) to keep the public API clean – only the stable constants are re‑exported.
Contributing
The project welcomes all contributions. If you’re new to floating‑point precision, the README points to helpful articles. Suggested starting points include improving documentation, adding tests, or tackling issues marked “help wanted.” The contribution workflow is standard for GitHub: fork, branch, write code, run cargo fmt, and submit a pull request. They recommend using Conventional Commits for commit messages and ask that you allow at least a week before pinging issues or PRs.
Related
- Project
- Project
- Project
- Project