Feature flags
Cargo features in stochastic-rs — what each one pulls in, how they propagate across the workspace, and which features your crates need.
Feature flags
Cargo features in this workspace are opt-in. The default build links no GPU, no BLAS, no Python, no neural surrogates — just the pure Rust core.
The matrix
| Feature | Owner crate | Pulls in | Use when |
|---|---|---|---|
ai | umbrella | stochastic-rs-ai, candle-core | NN volatility surrogates |
cuda-native | -stochastic | cudarc + cuFFT | NVIDIA GPU FGN / fBM (CudaNative backend) |
gpu / gpu-cuda / gpu-wgpu | -stochastic | cubecl (+ cubecl-cuda / -wgpu) | Portable CUDA / WebGPU kernels (CubeCl backend) |
metal | -stochastic | metal | macOS GPU FGN / fBM (MetalNative backend) |
accelerate | -stochastic | Apple vDSP (system framework) | macOS CPU-FFT FGN / fBM (Accelerate backend) |
openblas | -stats, -quant | ndarray-linalg/openblas | MLE, multivariate copulas, Cholesky-heavy |
viz | umbrella | stochastic-rs-viz, plotly | Quick HTML plots |
python | -py (cdylib) | pyo3, numpy | Building the wheel via maturin |
hotpath | umbrella | tracing-subscriber | Hot-path profiling helpers |
dual-stream-rng | -core, -distributions | none (additive) | ~2–6 % bulk Normal-Ziggurat speedup on Apple Silicon (Exp at parity) — see seeding |
The GPU / accelerator features above select a sampling backend chosen at compile
time with .on::<B>() — see the Backends concept page.
Propagation
A feature on the umbrella stochastic-rs crate maps to a feature on the
relevant sub-crate. Example from the umbrella Cargo.toml:
[features]
default = []
ai = ["stochastic-rs-ai"]
viz = ["stochastic-rs-viz"]
cuda-native = ["dep:cudarc", "stochastic-rs-stochastic/cuda-native"]
metal = ["dep:metal", "stochastic-rs-stochastic/metal"]
openblas = [
"stochastic-rs-stats/openblas",
"stochastic-rs-quant/openblas",
]
dual-stream-rng = [
"stochastic-rs-core/dual-stream-rng",
"stochastic-rs-distributions/dual-stream-rng",
]If you depend on a sub-crate directly (recommended for lean builds), you enable the feature on that sub-crate:
stochastic-rs-stats = { version = "2.2.0", features = ["openblas"] }Common gotchas
openblasis platform-specific. On macOS useRUSTFLAGS=-L/opt/homebrew/opt/openblas/libor thesystemlinkage. On Linuxapt install libopenblas-dev.cuda-native/gpu-cudarequire the CUDA toolkit on the build machine. CI builds do not install it by default.aiis heavy. It pulls incandle-core, which is a substantial ML stack. Only enable when you actually need NN surrogates.
Defining a new feature
When adding a new optional dependency, follow the feature-flag-management SKILL. The short version:
- Add the feature on the owner sub-crate (where the optional dependency lives).
- Re-export the feature on the umbrella via
feature_x = ["stochastic-rs-sub/feature_x"]. - Update the matrix above and the per-feature CI job.
- Add a
cfg-gated module so default builds don't pull in the dep.
Seeding & RNG
The uniform `new(args, &seed)` constructor pattern, the `SeedExt` strategies (`Unseeded` / `Deterministic`), in-place reseeding, and dual-stream RNG.
Sampling backends
Compile-time GPU / accelerator backend selection for the fractional family via `.on::<B>()` — the `Backend` trait, its markers, and zero-cost dispatch.