statrs

Library Featured

Statistical computing library for Rust

Checked · Sources

Downloads
4,515,476
Dependents
444
Stars
839
Forks
126
Contributors
65
Commits
1,052
Latest release
0.19.1 ·

About

From the project README ·

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 prec module 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:

  1. A prec module that wraps and standardizes common approximation checks from the approx crate with crate-specific defaults
  2. Macros for common precision comparison patterns
  3. 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 prec module, this helps with searchabiliy.
  • Document any module-specific precision requirements
Learning Resources

If you're new to floating-point precision, these resources provide helpful introductions:

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
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.

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.

statrs beside the projects that share a topic with it
ProjectDownloadsDependentsStarsLatest releaseRuns on (GPU)Native codeLicense
statrs This page Featured

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
linfa-linalg Listed Dormant

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

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 days
  • dormancy: last activity 2026-09-23, 47 days ago, E = 1200: active
  • rot: oldest unanswered issue 776 days (limit 270), no maintainer reply in 365 days
  • featured: 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
Adoption201 active dependents, 137 new dependents in 365 days1 not measured
Adoption measurements
SignalValueSourceFetchedCounts
Active dependents201.3333crates.io database dumpYes
New dependents (365 days)137crates.io database dumpYes
Peak active dependents202.3333crates.io database dumpYes
Active dependents as a share of the peak1crates.io database dumpYes
Binary downloads per releaseNot measuredYes
MaintenanceLatest human commit: 47 days ago3 not measured
Maintenance measurements
SignalValueSourceFetchedCounts
Latest human commit2026-09-23GitHub repositoryYes
Latest release2026-08-11crates.io database dumpYes
First release2016-08-11crates.io database dumpYes
Latest version0.19.1crates.io database dumpYes
Days the oldest outside issue waits for a reply776GitHub repositoryYes
Maintainer replies over 365 days0GitHub repositoryYes
Repository archivedfalseGitHub repositoryYes
Repository gonefalseGitHub repositoryYes
Release commit or manifest in the repotruecrates.io packageYes
Published docstruecrates.io database dumpYes
Latest release fails cargo checkNot measuredYes
Build check dateNot measuredYes
Build check toolchainNot measuredYes
SecurityUnpatched vulnerabilities: none
Security measurements
SignalValueSourceFetchedCounts
Unpatched vulnerabilities past the grace windownoneRustSec advisory databaseYes
RustSec unmaintained advisorynoneRustSec advisory databaseYes
Deprecation noticenonecrates.io database dumpYes
Deprecated requirementnonecrates.io database dumpYes
Distribution25 releases, 4,515,476 downloads over 30 days5 not measured
Distribution measurements
SignalValueSourceFetchedCounts
Releases25crates.io database dumpYes
Downloads over 30 days4515476crates.io database dumpYes
Binary downloads over the last 3 releasesNot measuredYes
Homebrew installs on request over 365 daysNot measuredYes
Repology repository familiesNot measuredYes
Docker pull growth over 90 daysNot measuredYes
Docker pulls at the growth baselineNot measuredYes
Every version a prereleasefalsecrates.io database dumpYes
Every version 0.0.xfalsecrates.io database dumpYes
Every version yankedfalsecrates.io database dumpYes
Crate deleted from crates.iofalsecrates.io database dumpYes
Repository839 stars, 126 forks, 65 contributors, 1,052 commits. Stars alone never qualify a project.
Repository measurements
SignalValueSourceFetchedCounts
GitHub stars839GitHub repositoryYes — one part of the repository route
GitHub forks126GitHub repositoryYes — one part of the repository route
Contributors with a GitHub account65GitHub contributorsYes — one part of the repository route
Commits on the default branch1052GitHub repositoryNo
Repository's main crate left out of the entrynonecrates.io database dumpYes
Facts that never count
Facts that never count measurements
SignalValueSourceFetchedCounts
LicenseMITcrates.io database dumpNo
Runs on, from listed crates and their direct dependenciesGPU support unknowncrates.io database dumpNo
What shows each backendno dependency or feature matches a backend rowcrates.io database dumpNo
Native code, from listed crates and their dependenciesNo native code foundcrates.io database dumpNo
Python bindings, from direct dependencies of listed cratesNo Python binding crate foundcrates.io database dumpNo
Crates that depend on a listed crate directly444crates.io database dumpNo

Corrections and review history

Report a correction

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.