rust-num-lib
Scientific computing library written in Rust: linear algebra and statistics
Downloads & Community Adoption
Health & Engineering Analysis (5 Pillars)
1. Governance & Community50 / 200 โพ
2. PEP Metadata & Packaging200 / 200 โพ
3. Security & Supply Chain150 / 200 โพ
4. Documentation, SEO & Ecosystem155 / 200 โพ
5. Engineering, CI & Quality65 / 200 โพ
Official Documentation & Usage Guide โ rust-num-lib
Show full original documentation (English README) โพ
rust_num_lib
A scientific computing library written in Rust, with Python bindings via PyO3.
The goal of this project is to provide fast, low-level implementations of numerical algorithms (linear algebra, statistics) with a convenient Python interface โ combining Rust's performance with Python's ergonomics.
Modules
rust_num_lib.linalgโ linear algebra: matrix multiplication, factorizations (LU, QR, Cholesky), solving linear systems, eigenvalues and eigenvectors.rust_num_lib.statsโ statistics: mean, standard deviation, sampling from distributions, data generation.
Requirements
- Rust (stable toolchain, 2024 edition โ Rust 1.85+)
- Python 3.8+
- maturin โ tool for building Python extensions from Rust
Installation and Setup
The library is not (yet) published on PyPI, so it has to be built locally from source using maturin.
1. Clone the repository
git clone <repository-url>
cd rust_num_lib
2. Create and activate a virtual environment
Using a clean venv is recommended (not conda โ mixing the two causes conflicts during the build):
python3 -m venv .venv
source .venv/bin/activate # Linux / macOS
# .venv\Scripts\activate # Windows
Note: if you have a conda environment active, deactivate it first (
conda deactivate), becausematurinwill refuse to build when bothVIRTUAL_ENVandCONDA_PREFIXare set.
3. Install maturin
pip install maturin
4. Build and install the library
maturin develop --release
The --release flag matters โ without it the code compiles in debug mode (no optimizations), which is many times slower and unsuitable for benchmarking.
This command builds the extension and installs it into the active virtual environment.
5. Verify it works
import rust_num_lib.linalg as linalg
a = linalg.Matrix.identity(3)
print(a)
Tests
Unit tests (pure Rust, without PyO3) are run via Cargo:
cargo test
Project Structure
rust_num_lib/
โโโ src/
โ โโโ lib.rs # entry point, PyO3 module registration
โ โโโ python.rs # Python bindings for Matrix methods
โ โโโ linalg/ # linear algebra module
โ โโโ stats/ # statistics module
โโโ Cargo.toml
โโโ pyproject.toml
โโโ README.md