statrs
Library Featured
Statistical computing library for Rust
- Downloads
- 4,515,476
- Dependents
- 444
- Stars
- 839
- Forks
- 126
- Contributors
- 65
- Commits
- 1,052
- Latest release
- 0.19.1 ·
About
Statrs provides a host of statistical utilities for Rust scientific computing.
Included are a number of common distributions that can be sampled (i.e. Normal, Exponential, Student's T, Gamma, Uniform, etc.) plus common statistical functions like the gamma function, beta function, and error function.
This library began as port of the statistical capabilities in the C# Math.NET library. All unit tests in the library borrowed from Math.NET when possible and filled-in when not. Planned for future releases are continued implementations of distributions as well as porting over more statistical utilities.
Please check out the documentation here.
Usage
Add the most recent release to your Cargo.toml
[dependencies]
statrs = "*" # replace * by the latest version of the crate.
For examples, view the docs.
no_std
Disable the default features to use statrs without std:
[dependencies]
statrs = { version = "*", default-features = false }
No separate Cargo feature is required for allocation-backed APIs. To enable
matrix-backed distributions without std, enable nalgebra directly:
[dependencies]
statrs = { version = "*", default-features = false, features = ["nalgebra"] }
Read the full README
Heap-backed APIs use Rust's alloc crate. A no_std application that calls
these APIs must provide and initialize a global allocator suitable for its
target:
#[global_allocator]
static ALLOCATOR: PlatformAllocator = PlatformAllocator::new(/* heap memory */);
The allocator type, heap memory, and initialization are platform-specific.
statrs does not provide or select an allocator.
When std is enabled, its global allocator is used and no setup is required.
WebAssembly randomness
On wasm32-unknown-unknown, sampling works with an explicitly seeded random
number generator without a host entropy source. Applications that need
JavaScript entropy, for example for rand::rng(), must select the getrandom
backend themselves:
[dependencies]
statrs = "*"
rand = "0.10"
getrandom = { version = "0.4", features = ["wasm_js"] }
statrs does not select a randomness backend for downstream applications.
Running tests
If you'd like to run all suggested tests, you'll need to download some data from
NIST, we have a script for this and formatting the data in the tests/ folder.
cargo test
./tests/gather_nist_data.sh && cargo test -- --include-ignored nist_
If you'd like to modify where the data is downloaded, you can use the environment variable,
STATRS_NIST_DATA_DIR for running the script and the tests.
Minimum supported Rust version (MSRV)
This crate requires a Rust version of 1.89.0 or higher. Increases in MSRV will be considered a semver non-breaking API change and require a version increase (PATCH until 1.0.0, MINOR after 1.0.0).
Precision
Floating-point numbers cannot always represent decimal values exactly, which can introduce small (and in some cases catastrophically large) errors in computations. In statistical applications, these errors can accumulate, making careful precision control important.
For Users and Evaluators
The statrs crate takes precision seriously:
- We use standardized precision checks throughout the codebase
- Default precision levels are carefully chosen to balance correctness and performance
- Module-specific precision requirements are explicitly documented where they differ from defaults
- Our test suite verifies numerical accuracy against common reference libraries
Key precision constants in the crate are set by pub consts in the prec module:
- Default relative accuracy:
pub const DEFAULT_RELATIVE_ACC - Default epsilon:
pub const DEFAULT_EPS - Default ULPs (Units in Last Place):
pub const DEFAULT_ULPS
Some modules/submodules have default precision that is different from the crate defaults, for searchability the names of such constants are the MODULE_RELATIVE_ACC, MODULE_EPS, and MODULE_ULPS.
[!IMPORTANT] Starting from v0.19.0, the
precmodule is no longer public (pub mod prec→mod prec). This change reflects that precision handling is an internal implementation detail.The precision constants mentioned above remain stable and documented and will be reexported at the crate level, but direct access to the module's utilities is now restricted to maintain better API boundaries.
For Contributors
// express your sentiment about the intended use of prec module in this section. The reason is that this section is for contributors and the users need not know about internal functionality.
To help maintain consistent precision checking, statrs provides:
- A
precmodule that wraps and standardizes common approximation checks from theapproxcrate with crate-specific defaults - Macros for common precision comparison patterns
- Helper functions for convergence testing
When contributing:
- Use the provided precision utilities rather than hard-coding values
- Maintain or improve precision in existing tests when making changes, new modules can start at lesser precision than the crate defaults if need be
- when doing so, one should use the same names as defined in the
precmodule, this helps with searchabiliy.
- when doing so, one should use the same names as defined in the
- Document any module-specific precision requirements
Learning Resources
If you're new to floating-point precision, these resources provide helpful introductions:
- Comparing Floating Point Numbers, 2012 Edition
- The Floating Point Guide - Comparison
- What Every Computer Scientist Should Know About Floating-Point Arithmetic
Contributing
Thanks for your help to improve the project! No contribution is too small and all contributions are valued.
If you're not familiar with precision in floating point operations, please read the section on precision specifically, the For Contributors section.
Suggestions if you don't know where to start,
- if you're an existing user, file an issue or feature request.
- documentation is a great place to start, as you'll be able to identify the value of existing documentation better than its authors.
- tests are valuable in demonstrating correct behavior, you can review test coverage on the CodeCov Report
- check out some of the issues marked help wanted.
- look at features you'd like to see in statrs
- Math.NET
- scipy.stats
- KDE, see (issue #193)[https://github.com/statrs-dev/statrs/issues/193]
How to contribute
Clone the repo:
git clone https://github.com/statrs-dev/statrs
Create a feature branch:
git checkout -b <feature_branch> main
Write your code and docs, then ensure it is formatted:
cargo fmt
Add --check to view the diff without making file changes.
Our CI will check format without making changes.
After commiting your code:
git push -u <your_remote_name> <your_branch> # with `git`
gh pr create --head <your_branch> # with GitHub's cli
Then submit a PR, preferably referencing the relevant issue, if it exists.
Commit messages
Please be explicit and and purposeful with commit messages. Conventional Commits encouraged.
Communication Expectations
Please allow at least one week before pinging issues/pr's.
Compatibility
- Runs on
- GPU support unknown
What shows it
- no dependency or feature matches a backend row
- Native code
- None found
- No native code found
- Python bindings
- No Python binding crate found
- License
- MIT
Compare with similar projects
Order: strongest tier first, then most downloads, then name, with unmeasured values last. A library counts downloads over 30 days. An app counts binary downloads per release. An app with none counts its crate downloads over 30 days. ML Rust runs this catalogue, so its closest project always gets a row.
| Project | Downloads | Dependents | Stars | Latest release | Runs on (GPU) | Native code | License |
|---|---|---|---|---|---|---|---|
|
Statistical computing library for Rust |
4,515,476 downloads over 30 days | 444 | 839 | 0.19.1 | GPU support unknown | No native code found | MIT |
|
rustfft Featured
High-performance FFT library written in pure Rust. |
4,266,035 downloads over 30 days | 571 | 963 | 6.4.1 | GPU support unknown | No native code found | Apache-2.0 OR MIT |
|
Pure-Rust implementation of linear algebra routines for ndarray |
198,623 downloads over 30 days | 20 | 39 | 0.2.1 | GPU support unknown | No native code found | Apache-2.0 OR MIT |
|
differential-equations Listed
A Rust library for solving differential equations. |
4,465 downloads over 30 days | 4 | 83 | 0.7.0 | GPU support unknown | No native code found | Apache-2.0 |
|
numr Listed
The base for numerical code in Rust, in the role NumPy has in Python: n-dimensional tensors, linear algebra, FFT, statistics and autograd on CPU, CUDA and WebGPU. The backends use native kernels, with no cuBLAS, MKL or other vendor math library. |
1,673 downloads over 30 days | 7 | 59 | 0.15.2 | CUDA, WebGPU | Binds native code: ring (feature distributed) | Apache-2.0 |
|
scirs Listed
A Rust port of SciPy with AI/ML extensions - Scientific Computing and AI Library (scirs2) Python bindings |
117 downloads over 30 days | 198 | 306 | 0.6.5 | CUDA, WebGPU, Metal, ROCm, Vulkan | Binds native code: perf-event-open-sys (feature profiling_perf). Build uses a native toolchain: cc (feature c-opt) | Apache-2.0 |
Why FeaturedIt passes every Featured gate.
What it meets
- It has 201 active dependents and 137 new dependents in 365 days. Featured needs 11 active dependents or 9 new dependents in 365 days.
- Active dependents are at 100% of their peak. Featured needs at least 50%.
- Docs are present. The release commit or a manifest ties the crate to the repository.
- No vulnerability advisory stays unpatched past the grace window. At least one version is neither a prerelease nor 0.0.x.
- The last activity is on 23 Sep 2026, 47 days ago. The rules expect an update within 1200 days. Dormancy rule
What else the check found
- The oldest outside issue waits 776 days for a reply, past the limit of 270. No maintainer replied in 365 days. Rot signals rule
Exact rules: Featured library. The check on applied thresholds version 9.
Every rule outcome, as the check records it
expected-interval: version 0.19.1 base 300, doubled for 4515476 downloads per month, doubled for 201.33 active users: E = 1200 daysdormancy: last activity 2026-09-23, 47 days ago, E = 1200: activerot: oldest unanswered issue 776 days (limit 270), no maintainer reply in 365 daysfeatured: featured: active_users 201.33, new_adopters 137, former_glory 1
Measurements and sources
Each signal row shows the raw value, its source and the fetch date. The Sources list gathers every distinct source on this page. Movement needs more history.
Sources6 sources
- Description: the crates.io description
- crates.io database dump, fetched
- RustSec advisory database, fetched
- GitHub repository, fetched
- crates.io package, fetched
- GitHub contributors, fetched
Adoption201 active dependents, 137 new dependents in 365 days1 not measured
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| Active dependents | 201.3333 | crates.io database dump | Yes | |
| New dependents (365 days) | 137 | crates.io database dump | Yes | |
| Peak active dependents | 202.3333 | crates.io database dump | Yes | |
| Active dependents as a share of the peak | 1 | crates.io database dump | Yes | |
| Binary downloads per release | Not measured | Yes |
MaintenanceLatest human commit: 47 days ago3 not measured
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| Latest human commit | 2026-09-23 | GitHub repository | Yes | |
| Latest release | 2026-08-11 | crates.io database dump | Yes | |
| First release | 2016-08-11 | crates.io database dump | Yes | |
| Latest version | 0.19.1 | crates.io database dump | Yes | |
| Days the oldest outside issue waits for a reply | 776 | GitHub repository | Yes | |
| Maintainer replies over 365 days | 0 | GitHub repository | Yes | |
| Repository archived | false | GitHub repository | Yes | |
| Repository gone | false | GitHub repository | Yes | |
| Release commit or manifest in the repo | true | crates.io package | Yes | |
| Published docs | true | crates.io database dump | Yes | |
| Latest release fails cargo check | Not measured | Yes | ||
| Build check date | Not measured | Yes | ||
| Build check toolchain | Not measured | Yes |
SecurityUnpatched vulnerabilities: none
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| Unpatched vulnerabilities past the grace window | none | RustSec advisory database | Yes | |
| RustSec unmaintained advisory | none | RustSec advisory database | Yes | |
| Deprecation notice | none | crates.io database dump | Yes | |
| Deprecated requirement | none | crates.io database dump | Yes |
Distribution25 releases, 4,515,476 downloads over 30 days5 not measured
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| Releases | 25 | crates.io database dump | Yes | |
| Downloads over 30 days | 4515476 | crates.io database dump | Yes | |
| Binary downloads over the last 3 releases | Not measured | Yes | ||
| Homebrew installs on request over 365 days | Not measured | Yes | ||
| Repology repository families | Not measured | Yes | ||
| Docker pull growth over 90 days | Not measured | Yes | ||
| Docker pulls at the growth baseline | Not measured | Yes | ||
| Every version a prerelease | false | crates.io database dump | Yes | |
| Every version 0.0.x | false | crates.io database dump | Yes | |
| Every version yanked | false | crates.io database dump | Yes | |
| Crate deleted from crates.io | false | crates.io database dump | Yes |
Repository839 stars, 126 forks, 65 contributors, 1,052 commits. Stars alone never qualify a project.
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| GitHub stars | 839 | GitHub repository | Yes — one part of the repository route | |
| GitHub forks | 126 | GitHub repository | Yes — one part of the repository route | |
| Contributors with a GitHub account | 65 | GitHub contributors | Yes — one part of the repository route | |
| Commits on the default branch | 1052 | GitHub repository | No | |
| Repository's main crate left out of the entry | none | crates.io database dump | Yes |
Facts that never count
| Signal | Value | Source | Fetched | Counts |
|---|---|---|---|---|
| License | MIT | crates.io database dump | No | |
| Runs on, from listed crates and their direct dependencies | GPU support unknown | crates.io database dump | No | |
| What shows each backend | no dependency or feature matches a backend row | crates.io database dump | No | |
| Native code, from listed crates and their dependencies | No native code found | crates.io database dump | No | |
| Python bindings, from direct dependencies of listed crates | No Python binding crate found | crates.io database dump | No | |
| Crates that depend on a listed crate directly | 444 | crates.io database dump | No |
Corrections and review history
No correction applies to this entry.
Judgments
A judgment enters only through an approved issue and a merged pull request.
No judgment applies to this entry.