SciRS2 - Python Bindings
SciRS2: High-performance scientific computing in Rust with Python bindings. A comprehensive, type-safe alternative to SciPy with exceptional performance for statistical analysis, linear algebra, FFT, signal processing, clustering, and more.
Overview
scirs2-python provides Python bindings for the entire SciRS2 scientific computing ecosystem using PyO3 and Maturin. It leverages scirs2-numpy — a SciRS2-maintained fork of rust-numpy with native ndarray 0.17 support — for zero-copy NumPy array interoperability.
Key Characteristics
- Exceptional Statistics Performance: Up to 410x faster than SciPy for higher-order moments (skewness, kurtosis) on small/medium datasets
- Pure Rust Stack: OxiBLAS for linear algebra, OxiFFT for transforms — no system OpenBLAS or FFTW required
- Zero-Copy NumPy Interop: Direct memory sharing between Rust and NumPy arrays via
scirs2-numpy - SciPy-Compatible API: Familiar naming conventions for Python scientists migrating from SciPy
- Maturin Build System: Single
pip install scirs2— no C/Fortran compiler needed - Type Stubs:
.pyifiles for full IDE autocompletion and type checking - Feature-Gated Modules: Enable only the SciRS2 crates you need
Architecture
scirs2-python/
├── src/
│ ├── lib.rs - PyO3 module registration
│ ├── linalg.rs - Linear algebra (OxiBLAS-powered)
│ ├── stats.rs - Statistics and distributions
│ ├── fft.rs - FFT (OxiFFT-powered)
│ ├── cluster.rs - Clustering algorithms
│ ├── series.rs - Time series analysis
│ ├── signal.rs - Signal processing
│ ├── optimize.rs - Optimization algorithms
│ ├── spatial.rs - Spatial algorithms
│ ├── sparse.rs - Sparse matrix operations
│ ├── ndimage.rs - N-dimensional image processing
│ ├── graph.rs - Graph algorithms
│ ├── metrics.rs - ML evaluation metrics
│ ├── io.rs - File I/O (CSV, HDF5, Parquet, etc.)
│ ├── datasets.rs - Dataset loading and generation
│ ├── transform.rs - Dimensionality reduction
│ ├── text.rs - NLP and text processing
│ ├── vision.rs - Computer vision
│ ├── linalg_ext.rs - Extended linear algebra (v0.3.4+)
│ ├── signal_ext.rs - Extended signal processing (v0.3.4+)
│ ├── optimize_ext.rs - Extended optimization (v0.3.4+)
│ └── stats/
│ └── mcmc_gp.rs - MCMC and Gaussian process bindings (v0.3.4+)
├── tests/
│ └── test_module_structure.py
├── scirs2.pyi - Type stubs
└── pyproject.toml
Installation
For development (builds Rust from source):
No system BLAS, OpenBLAS, or FFTW installation required — SciRS2 uses pure Rust OxiBLAS and OxiFFT.
Quick Start
Statistics (Fastest Module)
SciRS2 delivers exceptional speed for statistical analysis:
=
# Basic statistics (5-25x faster than NumPy on small-medium data)
= # 8x faster
= # 14x faster
=
=
=
# Higher-order moments (50-410x faster than SciPy!)
= # 52x faster
= # 52x faster
# Correlation (17-127x faster)
=
=
=
=
# Full descriptive summary
=
# Returns: {'mean', 'std', 'min', 'max', 'skewness', 'kurtosis', ...}
Linear Algebra
=
=
# Basic operations
=
=
=
# Decompositions
= # {'L', 'U', 'P'}
= # {'Q', 'R'}
= # {'U', 'S', 'Vt'}
=
# Eigenvalues/vectors
= # {'eigenvalues_real', 'eigenvalues_imag', 'eigenvectors'}
= # For symmetric matrices
# Solvers
=
=
# Norms and properties
=
=
=
=
FFT (OxiFFT Backend)
=
# FFT (2-5x faster than NumPy on small data < 2K samples)
= # {'real', 'imag'}
, = ,
=
=
=
# DCT
= # Type-II DCT
=
# Helpers
=
=
=
=
Clustering
=
# K-Means
=
=
=
# Cluster quality metrics
=
=
=
# Preprocessing
=
=
Time Series
=
=
# Transformations
=
=
# ARIMA modelling
=
=
# Box-Cox transform
= # auto lambda
=
=
=
# Stationarity test
=
# STL decomposition
=
=
=
=
MCMC and Gaussian Processes (v0.3.4+)
# Gaussian Process regression
=
= + 0.1 *
=
=
, =
# MCMC sampling
=
=
Extended Optimization (v0.3.4+)
# Gradient-free optimization
=
# Constrained optimization
=
Performance Guide
Where SciRS2 Excels
| Operation | Data Size | Speedup vs SciPy | Notes |
|---|---|---|---|
| Skewness | 100 | 410x | Higher-order moments |
| Kurtosis | 100 | 408x | Higher-order moments |
| Pearson correlation | 100 | 127x | Small dataset |
| IQR | 100 | 95x | Quartile calculations |
| Percentile | 100 | 49x | Distribution analysis |
| Skewness | 1,000 | 52x | Medium dataset |
| Std | 100 | 25x | Small data variability |
| Mean | 100 | 11x | Small data average |
| FFT (rfft) | 128 | 5.2x | Small signal |
| Linear solve | 10x10 | 9.4x | Small systems |
Where NumPy/SciPy May Win
| Operation | Size | Notes |
|---|---|---|
| Linear algebra (SVD, QR) | 200x200+ | SciPy LAPACK highly optimized |
| FFT | 32K+ samples | NumPy FFT optimized for large N |
| Basic stats | 100K+ elements | NumPy C SIMD optimizations |
Recommended Hybrid Approach
=
# Use scirs2 for statistics on small-medium data
= # 52x faster than SciPy
= # 52x faster than SciPy
= # 8x faster
= # 14x faster
# Use scirs2 for FFT on small signals
=
= # 3x faster than NumPy
# Fall back to NumPy/SciPy for large transforms
=
= # NumPy wins here
Feature Flags
Enable specific SciRS2 crates in pyproject.toml:
[]
= ["linalg", "stats", "fft", "cluster", "series"]
= ["scirs2-linalg"]
= ["scirs2-stats"]
= ["scirs2-fft"]
= ["scirs2-cluster"]
= ["scirs2-series"]
= ["scirs2-signal"]
= ["scirs2-optimize"]
= ["scirs2-spatial"]
= ["scirs2-sparse"]
= ["scirs2-ndimage"]
= ["scirs2-graph"]
= ["scirs2-metrics"]
= ["scirs2-io"]
= ["scirs2-datasets"]
= ["scirs2-transform"]
= ["scirs2-text"]
= ["scirs2-vision"]
Type Hints
# IDE provides full autocompletion from .pyi stubs
: =
: =
: =
: =
Building from Source
# 1. Install Rust
|
# 2. Install maturin
# 3. Build and install in development mode
# 4. Run tests
Dependencies
- PyO3 - Rust/Python FFI
- scirs2-numpy - SciRS2 fork of rust-numpy with ndarray 0.17 support
- Maturin - Build system for Python/Rust extensions
- OxiBLAS - Pure Rust BLAS/LAPACK (no system dependencies)
- OxiFFT - Pure Rust FFT
Related Projects
- SciRS2 Core - Rust scientific computing library
- scirs2-numpy - NumPy/ndarray 0.17 bridge
- NumPy - Array operations
- SciPy - Python scientific computing (API inspiration)
License
Licensed under the Apache License 2.0. See LICENSE for details.
Authors
COOLJAPAN OU (Team KitaSan)