SciPy, rebuilt in Rust19 cratesv0.5.2 on crates.io
SciPy’s math, without the Python.
FrankenSciPy is SciPy rebuilt from scratch in safe Rust, from linear algebra to statistics: 1,532 of the 1,538 functions and classes SciPy exports, 916 of them checked against a live SciPy in the test suite. Every dense solve returns a certificate saying which algorithm ran and why. The curves here are computed by those crates, running in your browser.
cargo add fsci-linalg fsci-stats
Pick a function
Orders v = 0 to 19, x from 0 to 40: 20 ridges of 300 points.
The same call, twice
SciPyscipy.special.jv(v, x)
Rustfsci_special::jv(&v, &x, mode)
– largest difference from SciPy 1.17.1 over 6,000 values
– same bits– ≤ 4 ulp– ≤ 256 ulp– more
Drawn from SciPy’s recorded values. Starting fsci-special…
The Bessel ridges drift through fractional orders, each frame computed by fsci-special. Point at them and they settle on whole orders, where you can read any value beside SciPy’s for the same input. SciPy’s answers were recorded with SciPy 1.17.1 and NumPy 2.4.3 when this page was built. An ulp is one step between neighbouring doubles.
- 1,532of 1,538 SciPy namesHave a real Rust implementation, across 33 SciPy modules.
- 783differential test filesEach starts a live SciPy, sends it the same inputs and compares.
- 1,167tolerance contractsNamed in the tests. CI fails if any one is loosened.
- 12,304#[test] functionsInline and integration tests across all 19 crates.
- 0lines of unsafe
forbid(unsafe_code)in every crate. No FFI to BLAS or LAPACK.
What’s inside
SciPy’s toolbox, crate by crate.
1,532 of SciPy’s 1,538 public functions and classes, in 19 crates you add one at a time. The counts on each card are from the census: implemented, and compared against a live SciPy.
Solve
Linear algebra
LU, QR, Cholesky, SVD, eig, Schur, expm and Riccati, real and complex, with a certificate on every dense solve.
103 names79 compared live
Factor
Sparse matrices and graphs
Seven formats, sparse LU, Krylov solvers from CG to LSMR, eigsh and eigs, and graph algorithms from Dijkstra to PageRank.
112 names78 compared live
Minimize
Optimization
Fourteen minimize methods, root finders, least squares and curve_fit, global search, and LP and MILP.
77 names34 compared live
Integrate
ODEs and quadrature
solve_ivp's six methods including LSODA, solve_bvp, QUADPACK, cubature and quasi-Monte Carlo.
32 names15 compared live
Evaluate
Special functions
Gamma, Bessel, Airy, hypergeometric, elliptic and orthogonal polynomials, with SciPy's edge cases.
358 names211 compared live
Test
Statistics
Over a hundred distributions with fitting and moments, hypothesis tests, KDE and QMC samplers.
358 names262 compared live
Filter
Signal processing and FFT
Filter design and filtfilt, Welch and STFT, wavelets, and a mixed-radix FFT with DCT and DST.
229 names122 compared live
Fit
Interpolation
Cubic, Akima and PCHIP splines, B-splines, RBF, griddata and regular-grid interpolation.
56 names15 compared live
Search
Spatial, clusters and images
KDTree, distances, Delaunay and Voronoi; k-means and hierarchical clustering; ndimage filters and morphology.
159 names81 compared live
Also in the workspace: scipy.constants, scipy.datasets, scipy.io, scipy.odr, another 48 names. See every name on the map.
What changes for you
Eight jobs it’s built for.
Everyday problems with SciPy’s math outside a Python notebook, how they go today, and how they go with FrankenSciPy.
01The surface
Thirty-three SciPy modules, one Cargo workspace.
FrankenSciPy keeps SciPy’s names, defaults and edge cases, so code ports one call at a time. The symbol census, regenerated against SciPy 1.17.1, counts what is implemented, what is compared live and what is still missing.
The module map
Every public name in SciPy, one square each.
One square per public name in SciPy 1.17.1, grouped by the crate that implements it and coloured by what the census finds: compared live, implemented, missing or not applicable.
Point at a module or a square; select a square to look it up
1,555 public names · 33 modules · 16 crates
- 916compared live against SciPy
- 616implemented, not compared yet
- 6missing
- 17not applicable to Rust
fsci-stats360
stats241/303
stats.contingency2/6
stats.mstats11/31
stats.qmc4/11
stats.sampling4/9
fsci-special358
special211/358
fsci-signal182
signal83/157
signal.windows9/25
fsci-sparse117
sparse25/53
sparse.csgraph24/26
sparse.linalg29/38
fsci-linalg106
linalg72/98
linalg.interpolative7/8
fsci-opt78
differentiate0/3
optimize30/71
optimize.elementwise4/4
fsci-ndimage75
ndimage39/75
fsci-interpolate56
interpolate15/56
fsci-fft51
fft20/41
fftpack10/10
fsci-spatial49
spatial8/18
spatial.distance22/27
spatial.transform0/4
fsci-cluster36
cluster.hierarchy10/32
cluster.vq2/4
fsci-integrate33
integrate15/33
fsci-io31
io3/14
io.arff3/4
io.matlab4/10
io.wavfile2/3
fsci-odr10
odr2/10
fsci-constants8
constants5/8
fsci-datasets5
datasets0/5
Point at a module
One square per name, grouped by crate. Select a square to look it up below.
How the census counts
Names come from each module’s __all__, counted once in the module that owns them, exactly as scripts/symbol_census.py counts them. A name is compared when a diff test’s inline SciPy script calls it and the same file calls the matching Rust item; a test that reaches SciPy through getattr is not seen, so the compared count is a lower bound.
The committed census file, docs/planning/symbol_census.json, counts 909 compared. Tests that landed after it was last regenerated bring the count on this tree to 916, the number this page uses throughout.
__all__, counted once in the module that owns it, at commit d2b206d3d. A module’s count is its compared names over all its names.Look up a function
Does it have the one you use?
Search any SciPy name for its Rust counterpart and the test files that compare it. Missing and not-applicable names carry the census’s reason.
Type a SciPy name to see its Rust counterpart and the tests that compare it
The six SciPy names with no Rust implementation yet:
scipy.io.matlab.MatReadErrorMissingMATLAB read failures are IoError variants, not a distinct error class (frankenscipy-1ksfv.12)
scipy.io.matlab.MatReadWarningMissingno warning channel for recoverable MATLAB read issues (frankenscipy-1ksfv.12)
scipy.io.matlab.MatWriteErrorMissingMATLAB write failures are IoError variants, not a distinct error class (frankenscipy-1ksfv.12)
scipy.io.matlab.MatWriteWarningMissingno warning channel for recoverable MATLAB write issues (frankenscipy-1ksfv.12)
scipy.sparse.linalg.ArpackErrorMissingSparseError has no eigensolver error class (frankenscipy-6j5tz)
scipy.sparse.linalg.MatrixRankWarningMissingspsolve on a singular matrix returns SingularMatrix instead of warning (frankenscipy-6j5tz)
Same call, same answer
Port one call, check one answer.
Eight everyday calls, SciPy beside the Rust that replaces it. The Rust runs in this tab on SciPy’s recorded inputs, and every output is compared bit for bit.
Pick a call: the Rust runs here, and every output is checked against SciPy’s
SciPy
from scipy import linalg x = linalg.solve(a, b)
Rust · fsci-linalg
use fsci_linalg::{solve, SolveOptions}; let x = solve(&a, &b, SolveOptions::default())?.x;
The result also carries a CASP certificate; chapter 03 opens it.
The inputs both sides used
a = [[4, -2, 1, 3], [3, 6, -4, 2], [2, 1, 8, -5], [1, -3, 2, 7]]
b = [1, -2, 3, 4]
SciPy
from scipy import stats r = stats.ttest_ind(a, b, equal_var=False) r.statistic, r.pvalue, r.df
Rust · fsci-stats
use fsci_stats::ttest_ind_welch; let r = ttest_ind_welch(&a, &b); (r.statistic, r.pvalue, r.df)
SciPy’s equal_var=False becomes its own function, ttest_ind_welch.
The inputs both sides used
a = [5.1, 4.9, 6.2, 5.8, 6, 5.5, 5.3, 6.1]
b = [4.1, 4.5, 3.9, 4.8, 4.4, 5, 4.2]
SciPy
from scipy import optimize r = optimize.minimize(optimize.rosen, [-1.2, 1.0], method="BFGS") r.x, r.fun, r.nit, r.nfev
Rust · fsci-opt
use fsci_opt::{minimize, rosen, MinimizeOptions, OptimizeMethod}; let r = minimize(rosen, &[-1.2, 1.0], MinimizeOptions { method: Some(OptimizeMethod::Bfgs), ..Default::default() })?; (r.x, r.fun, r.nit, r.nfev)
BFGS stops once the gradient norm falls below 1e-5, so two correct runs can stop a step apart. The two rosen helpers also round differently in the last bit.
The inputs both sides used
x0 = [-1.2, 1]
SciPy
import math from scipy import integrate value, abserr, info = integrate.quad( lambda t: 1 / math.sqrt(t), 0, 1, full_output=1) info["neval"]
Rust · fsci-integrate
use fsci_integrate::{quad, QuadOptions}; let r = quad(|t: f64| 1.0 / t.sqrt(), 0.0, 1.0, QuadOptions::default())?; (r.integral, r.error, r.neval)
The integrand is infinite at 0; neval counts the evaluations each side made.
The inputs both sides used
a = 0
b = 1
SciPy
from scipy import fft spectrum = fft.rfft(x) spectrum.real, spectrum.imag
Rust · fsci-fft
use fsci_fft::{rfft, FftOptions}; // Vec<(re, im)> let spectrum = rfft(&x, &FftOptions::default())?;
Where one side has an exact zero and the other a residue near 10⁻¹⁶, the difference is shown as |Δ|: ulps away from zero mean nothing.
The inputs both sides used
x = [-3, -1.875, 1.25, -0.625, -0.5, 1.625, -1.25, -2.125, -1, 2.125, 0.25, 0.375, 2.5, -0.375, -1.25, -0.125]
SciPy
from scipy import signal b, a = signal.butter(4, 0.2) y = signal.filtfilt(b, a, x)
Rust · fsci-signal
use fsci_signal::{butter, filtfilt, FilterType}; let ba = butter(4, &[0.2], FilterType::Lowpass)?; let y = filtfilt(&ba.b, &ba.a, &x)?;
The inputs both sides used
x = [-0.5, -0.32352941176470584, -0.14705882352941174, 0.02941176470588236, 0.20588235294117652, 0.38235294117647056, -0.4411764705882353, -0.2647058823529412, -0.08823529411764708, 0.08823529411764708, 0.2647058823529411, 0.4411764705882353, -0.38235294117647056, -0.20588235294117646, -0.02941176470588236, 0.1470588235294118, 0.32352941176470584, -0.5, -0.32352941176470584, -0.14705882352941174, 0.02941176470588236, 0.20588235294117652, 0.38235294117647056, -0.4411764705882353, -0.2647058823529412, -0.08823529411764708, 0.08823529411764708, 0.2647058823529411, 0.4411764705882353, -0.38235294117647056, -0.20588235294117646, -0.02941176470588236, 0.1470588235294118, 0.32352941176470584, -0.5, -0.32352941176470584, -0.14705882352941174, 0.02941176470588236, 0.20588235294117652, 0.38235294117647056, -0.4411764705882353, -0.2647058823529412, -0.08823529411764708, 0.08823529411764708, 0.2647058823529411, 0.4411764705882353, -0.38235294117647056, -0.20588235294117646, -0.02941176470588236, 0.1470588235294118, 0.32352941176470584, -0.5, -0.32352941176470584, -0.14705882352941174, 0.02941176470588236, 0.20588235294117652, 0.38235294117647056, -0.4411764705882353, -0.2647058823529412, -0.08823529411764708, 0.08823529411764708, 0.2647058823529411, 0.4411764705882353, -0.38235294117647056]
SciPy
from scipy import interpolate s = interpolate.CubicSpline(x, y) s(xq)
Rust · fsci-interpolate
use fsci_interpolate::{CubicSpline, SplineBc}; let s = CubicSpline::new(&x, &y, SplineBc::NotAKnot)?; let v: Vec<f64> = xq.iter().map(|&t| s.eval(t)).collect();
SciPy defaults to not-a-knot ends and fsci to natural ones, so a port names the condition.
The inputs both sides used
x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
y = [-1, 1.5, 0.5, -0.5, 2, 1, 0, -1, 1.5, 0.5]
xq = [0, 0.25, 0.5, 0.75, 1, 1.25, 1.5, 1.75, 2, 2.25, 2.5, 2.75, 3, 3.25, 3.5, 3.75, 4, 4.25, 4.5, 4.75, 5, 5.25, 5.5, 5.75, 6, 6.25, 6.5, 6.75, 7, 7.25, 7.5, 7.75, 8, 8.25, 8.5, 8.75, 9]
SciPy
from scipy import special special.ellipk(m)
Rust · fsci-special
use fsci_runtime::RuntimeMode; use fsci_special::{ellipk, SpecialTensor}; ellipk(&SpecialTensor::RealVec(m), RuntimeMode::Strict)?
The inputs both sides used
m = [-1, 0, 0.1, 0.5, 0.9, 0.99, 0.999999]
SciPy’s recorded answer is below. Starting fsci-linalg…
| Output | SciPy 1.17.1 | FrankenSciPy, live | Difference |
|---|
02Checked against SciPy
Tested against SciPy, case by case.
A differential test hands its cases to a real SciPy 1.17.1 and holds FrankenSciPy’s answers to a tolerance named in the file. In CI a test that cannot reach SciPy fails, and so does any change that loosens a tolerance.
One test, start to finish
How a differential test works.
One Rust file per test: cases out to SciPy, the same cases through FrankenSciPy, each pair held to a named tolerance. This one checks the scaled Bessel and Hankel functions.
Step through one real test, then run its eight cases in this tab
let cases: &[(&str, &str, f64, f64, f64)] = &[
("jve_real", "jve", 0.5, 1.25, 0.0),
("yve_real", "yve", 0.5, 1.25, 0.0),
("hankel1e_real", "hankel1e", 1.0, 1.25, 0.0),
("hankel2e_real", "hankel2e", 1.0, 1.25, 0.0),
("jve_complex", "jve", 0.5, 1.25, 0.5),
("yve_complex", "yve", 0.5, 1.25, 0.5),
("hankel1e_complex", "hankel1e", 0.5, 1.25, 0.5),
("hankel2e_complex", "hankel2e", 0.5, 1.25, 0.5),
];diff_special_scaled_bessel.rs:55let mut child = match fsci_conformance::scipy_oracle_command()
…
if std::env::var(REQUIRE_SCIPY_ENV).is_ok() {
return Err(test_error(format!("failed to spawn scipy oracle: {e}")));
…
import json
import sys
from scipy import special
q = json.loads(sys.argv[1])
points = []
for case in q["points"]:
z = complex(case["z_re"], case["z_im"])
if case["z_im"] == 0.0:
z = case["z_re"]
value = complex(getattr(special, case["function"])(case["order"], z))
points.append({"case_id": case["case_id"], "re": value.real, "im": value.imag})
print(json.dumps({"points": points}))diff_special_scaled_bessel.rs:97let output = match case.function.as_str() {
"jve" => jve(&order, &z, RuntimeMode::Strict),
"yve" => yve(&order, &z, RuntimeMode::Strict),
"hankel1e" => hankel1e(&order, &z, RuntimeMode::Strict),
"hankel2e" => hankel2e(&order, &z, RuntimeMode::Strict),
other => return Err(test_error(format!("unknown function {other}"))),
}
.map_err(|err| test_error(err.to_string()))?;diff_special_scaled_bessel.rs:152const SCALED_BESSEL_TOL: f64 = 5.0e-8;
…
let scale = expected.abs().max(1.0);
let diff = (actual - expected).abs();
// Written as `<=` so a NaN component (NaN diff) is a failure, not a silent pass.
let pass = diff <= SCALED_BESSEL_TOL * scale;
ledger.compared(arm, &case.case_id, pass);diff_special_scaled_bessel.rs:20let mut ledger = CompareLedger::new("diff_special_scaled_bessel", &ARMS);
…
ledger.finish(min_per_arm);diff_special_scaled_bessel.rs:182SciPy’s answers are recorded; FrankenSciPy’s are computed when you press Run.
Live, in this tab
Sixteen functions, 4,800 values.
Fourteen special functions and two distributions on 300 inputs each, recorded from SciPy 1.17.1. FrankenSciPy evaluates them here and every pair is compared bit for bit; the numbers are this run’s.
Run the battery: each strip holds all 300 values of one function, coloured by distance from SciPy
- Within 4 ulp
- –
- Worst relative difference
- –
- One pass of all sixteen
- –
- Same bits
- 1 to 4 ulp
- 5 to 256 ulp
- More
Bit for bit
Where the match is exact.
Some ports reproduce SciPy to the last bit or the last evaluation. Each card says whether a test asserts it on every run or it was measured and logged.
Filter the claims by how each one is backed
111 / 111MAT files
loadmat reads SciPy’s MAT test corpus as SciPy does
Asserted by the test
What the test checks
Every file in the corpus, under seven loadmat option sets. Floats are compared as hex bit patterns, and a built-in control shows that a one-bit change, a signed zero, a dtype change or a renamed variable would be caught. The 8 files SciPy rejects are rejected with the same error class.
- Asserted
- every value equal to the bit
408 / 408layouts
dendrogram lays out every tree as SciPy does
Asserted by the test
What the test checks
Four linkage methods, six sizes from 2 to 60 points and seventeen option sets. Coordinates, leaf order, labels and colours must all be equal.
- Asserted
- every field exactly equal
400 / 400matrices
matrix_balance finds LAPACK’s permutation
Asserted by the test
What the test checks
Sparse matrices where dgebal isolates eigenvalues by permutation. Permutations and power-of-two scalings are exact, so the balanced matrix, scaling and permutation are compared for equality.
- Asserted
- exact equality
0 ulpat every step
LSODA takes SciPy’s steps and switches
Asserted by the testMeasured, logged
What the test checks
fsci ports the C translation of ODEPACK that SciPy runs. On Robertson, van der Pol, HIRES, Arenstorf, the Oregonator and more, the test requires SciPy’s step and evaluation counts and its switches between Adams and BDF. On the pinned host every step row and every odeint row also came out bit-identical.
- Asserted
- step counts, evaluations, LU count and switch history equal
- Measured
- values bit-identical, logged
30 / 30cases
Trust-region methods match SciPy’s counts
Measured, logged
What the test checks
trust-ncg, trust-krylov, dogleg and trust-exact took SciPy’s exact iteration, function, gradient and Hessian counts on all 30 cases. The test itself asserts the answers and an iteration count within 30%.
- Measured
- exact counts, logged
24 / 25cases
COBYLA reproduces SciPy’s iterates
Measured, logged
What the test checks
A transcription of PRIMA, which SciPy runs, that evaluates NumPy’s linear algebra in OpenBLAS’s order. 24 of 25 cases end with the same bits for x and f and the same number of evaluations. On hosts whose OpenBLAS uses older kernels, a borderline case can end differently (issue #17).
- Measured
- bit-identical cases, logged
9 / 9problems
solve_bvp arrives at SciPy’s mesh
Asserted by the testMeasured, logged
What the test checks
SciPy’s collocation method, transcribed: on nine boundary-value problems it took SciPy’s iteration count and node count and produced the same mesh. One problem’s exact path, 7 iterations and 233 nodes, is asserted in the crate’s own tests.
- Asserted
- one exact path
- Measured
- same mesh on all nine
6.8 × 10⁻¹⁵worst, 198 cases
Complex linear algebra follows LAPACK
Measured, logged
What the test checks
Complex solve, LU, QR, Hessenberg, Schur, eig and SVD follow the LAPACK routines SciPy calls, so eigenvalues come back in SciPy’s order. The test holds factors to 10⁻¹² and spectra to 10⁻¹⁰; the worst error measured was 6.8 × 10⁻¹⁵.
- Measured
- worst relative error
7.8 × 10⁻¹⁶worst, 300 cases
fftpack’s pseudo-differential operators
Measured, logged
What the test checks
diff, tilbert, hilbert, cs_diff, shift and the rest of scipy.fftpack’s pseudo-differential operators. The test holds them to 10⁻¹³ relative to the signal; the worst error measured was 7.8 × 10⁻¹⁶.
- Measured
- worst relative error
The tolerance ratchet
Tolerances can only tighten.
1,167 tolerances in 782 diff files are pinned in a baseline. CI gate G9 fails the build if one loosens, and the lint refuses to write a looser baseline.
Move the scaled-Bessel test’s tolerance and see what tolerance_lint says
1,167 contracts in 782 files
diff_special_scaled_bessel.rs
const SCALED_BESSEL_TOL: f64 = 5.0e-8;
What the baseline holds
The few contracts at 0.1 and above are ratios, iteration slack or statistical bounds, such as NIT_REL_TOL = 0.3. A tolerance passed to a comparison helper as a literal is not a contract the lint can see.
At this commit the baseline does not yet list one diff file, diff_signal_stft_istft.rs, which the lint reports as unanchored until the baseline is refreshed.
One oracle test, run twice: with SciPy, and in a CI job built to fail without it
Its G3 shardSciPy 1.17.1 installed, oracle required
- run
diff_sparse_basic_queries - SciPy answers every case
- test passes
The control jobno SciPy on the interpreter, oracle still required
- run
diff_sparse_basic_queries - the oracle cannot start
- test fails
- job passes
Gate defectIf that test ever passed without SciPy, the job would fail, because a missing oracle would be skipping instead of failing.
The job’s script, from ci.yml
if python -c "import scipy" 2>/dev/null; then
echo "control interpreter unexpectedly imports scipy" >&2
exit 1
fi
export SCIPY_PYTHON="$(which python)"
export FSCI_REQUIRE_SCIPY_ORACLE=1
if cargo test -p fsci-conformance --test diff_sparse_basic_queries -- --nocapture; then
echo "GATE DEFECT: the oracle-required lane PASSED with no SciPy present" >&2
exit 1
fi
echo "control ok: the lane failed closed without SciPy"03Condition-aware solving
Every solve shows its work.
Every dense solve returns a certificate with its answer: the conditioning it measured, the algorithm it chose and why, the accuracy it reached, and a digest that replays the decision bit for bit. CASP, the Condition-Aware Solver Portfolio, makes and records that choice.
Anatomy of a certificate
Seven fields carry the whole decision.
A real SolveCertificate, returned by a solve that runs in this tab. Point at a numbered field to see what it records; pick another matrix and every value changes.
Point at a numbered field, or pick another matrix
SolveCertificateas JSON
Starting fsci-linalg…- 1
What answered
The action that produced x, the one tried first, and whether it fell back.
– - 2
rcond estimate
How close to singular. Rounding error can grow by up to 1/rcond.
– - 3
Structure
Found exactly, in SciPy’s order. It decides which fast path is a candidate.
– - 4
Posterior
Belief over the 4 condition states, from rcond and any outcomes recorded.
– - 5
Expected loss
Each candidate’s cost plus its expected recovery cost, in units of one LU.
– - 6
Accuracy
Backward error, checked against 10⁻⁸, and a bound on the forward error.
– - 7
state_digest
BLAKE3 of the portfolio state that decided. A replay must start from it.
–
One solve, start to finish
Conditioning decides which algorithm is safe.
Pick a matrix. CASP measures rcond and structure, prices each algorithm, runs one and falls back if its backward error misses 10⁻⁸. Strict mode runs SciPy’s own route first.
Pick a matrix and watch the portfolio choose, attempt and certify
- Probe–
- Posterior–
- Loss–
- Choose–
- Attempt–
- Certify–
Matrix
Mode
Try
Starting fsci-linalg…
The decision surface
Losses measured on 324 matrices.
Expected loss is an action’s cost plus the expected cost of recovering when it fails. On a fresh portfolio, LU wins for every general matrix, as SciPy’s gesv does.
Pick a structure, then move along rcond to read each action’s expected loss
Cost per solve, in LU solves
- LU1
- QR2
- SVD31.5
- Diagonal0
- Triangular0
- Symmetric0.5
SolverPortfolio for its choice at 321 values of rcond. Only the actions a structure admits are candidates: LU, QR and the SVD, plus at most one fast path.How the loss table was measured
casp_calibrate ran every action on 324 seeded matrices at n = 8, 32, 128, in 12 families from Higham’s randsvd to Hilbert, Kahan and Wilkinson’s pivot-growth matrix. An action fails a matrix where the portfolio would fall back: an error, a non-finite answer, or a backward error above 10⁻⁸. Each failure is priced at the cheapest action that recovered that matrix.
The SVD costs 31.5 times LU’s flops and refuses a square system whose numerical rank is short, so it comes last. The generated constants live in calibrated_losses.rs, and a test holds them to the report.
Feedback
It learns from its own failures.
Each attempt is tallied by decade of rcond, and what it shows replaces that action’s calibrated failure rate. Record LU misses and passes at rcond 10⁻³ and watch the choice move.
Record LU’s outcomes one at a time and watch the choice move
SolverPortfolio::record_outcome, with a Beta prior worth four trials. In Strict mode solve still tries SciPy’s LU first on a general matrix; the ranking orders the fallbacks.Reproducibility
Replay any decision, bit for bit.
The certificate carries a BLAKE3 digest of the state that decided. replay_decision refuses any other state, then demands the same choice, posterior and losses, bit for bit.
Pick a matrix; its certificate is replayed against four portfolios
| Replayed against | State digest | Result | Why |
|---|
solve_with_casp, keeping a copy of the portfolio from just before, and replays four times. The conformance test does the same for 1,000 solves through one portfolio that keeps learning.04The algorithms
SciPy’s own algorithms, ported routine by routine.
Where SciPy runs a classic code, FrankenSciPy ports that code instead of writing its own: LSODA, QUADPACK, COBYLA, SLSQP, complex LAPACK and more. The tests then compare step counts, evaluation counts and iterates with SciPy’s, not only the final answers.
ODEPACK’s LSODA
One solver that notices the stiffness.
Robertson’s kinetics is the standard stiff test. LSODA starts with Adams steps of 10⁻⁵ s, detects stiffness at 0.0055 s, switches to BDF and stretches its steps to 10¹¹ s.
Move along the run to read LSODA’s state at each of its 200 output times
- t
- –
- Method
- –
- Step size
- –
- Steps
- –
- RHS evaluations
- –
- Jacobians
- –
- Running fsci-integrate…
odeint(robertson, [1, 0, 0], t, full_output=True) at odeint’s defaults, with 200 times spaced evenly in log t. SciPy’s side was recorded with SciPy 1.17.1’s arm64 macOS wheel.What the test asserts, and why the counts part on this machine
The repository’s test, diff_integrate_lsoda.rs, fails unless step counts, evaluation counts and switch history equal SciPy’s, and on its pinned x86-64 Linux host every row was also measured bit-identical (89d2b1600).
Against the arm64 macOS wheel recorded here, the method history agrees at all 200 outputs and the step counts agree for the first 83 outputs, then part: 793 steps here against SciPy’s 811. The figure reports each difference it finds.
Minimizers
Follow a minimizer iterate by iterate.
Rosenbrock’s curved valley is the standard minimizer test. Pick a method: FrankenSciPy runs it here, iterate by iterate, over SciPy’s recorded path. Click the map to start somewhere else.
Pick a method, then click the map to start from another point
Method
- Start
- (−1.2, 1)
- Iterations
- –
- Evaluations
- –
- Ends at
- –
- f there
- –
- Running fsci-opt…
100·(t·t) + u·u, with t = y − x² and u = 1 − x, using finite-difference gradients at SciPy’s default steps. SciPy’s paths come from minimize(..., callback=...), recorded from (−1.2, 1) with SciPy 1.17.1.Why neither library’s rosen is used
SciPy’s rosen computes 100*(t**2) and fsci’s computes (100*t)*t. The two round differently in the last bit, which is enough to send a minimizer down a different path, so both sides evaluate the same written-out expression. The map’s contours are drawn by this page.
QUADPACK
Split the panel with the largest error.
QAGS integrates each panel with a 21-point Gauss–Kronrod rule, bisects the panel with the largest error estimate, and extrapolates the sums. Pick an integrand and compare its panels with SciPy’s.
Pick an integrand, then point at a panel to read its share of the integral and its error
- Integral
- –
- Exact
- –
- Error estimate
- –
- Evaluations
- –
- Panels
- –
- Running fsci-integrate…
| Rank | Panel | Integral over it | Error estimate | vs SciPy |
|---|
quad(f, 0, 1, full_output=1) at its defaults, recorded with SciPy 1.17.1.Why the panel errors don’t add up to the reported error
QAGS extrapolates the sequence of panel sums with Wynn’s epsilon algorithm, and the extrapolated value is more accurate than any of its panels. That is why 1/√x, infinite at 0, converges after six panels, and why the reported error can be far smaller than the panels’ sum.
Provenance
Where each port comes from.
SciPy’s numerical core is old, tuned code whose edge cases users rely on. FrankenSciPy ports it where it can, and says where it uses its own algorithm for the same contract.
Open a row for what SciPy runs, the Rust that replaces it and what its test checks
01 LSODAAdams and BDF in one ODE solver, switching when the problem turns stiff C
fsci-integrate/lsoda.rsAssertedMeasured- SciPy runs
- SciPy’s
lsoda.c, a C translation of ODEPACK’s DLSODA (Hindmarsh, with Petzold’s method switching). - FrankenSciPy
crates/fsci-integrate/src/lsoda.rs· Ported routine by routine- Compared in
diff_integrate_lsoda.rs- Asserted
- Step counts, evaluation counts and switch history equal to SciPy’s.
- Measured
- Every row bit-identical on the pinned x86-64 host (89d2b1600).
02 QUADPACKAdaptive quadrature: QAGS, QAGI, QAGP and the weighted QAW routines C
fsci-integrate/quadpack.rsAssertedMeasured- SciPy runs
- QUADPACK (Piessens, de Doncker-Kapenga, Überhuber and Kahaner, 1983), as
scipy.integrate.quadbuilds it. - FrankenSciPy
crates/fsci-integrate/src/quadpack.rs· Ported routine by routine- Compared in
diff_integrate_quad_quadpack.rs- Asserted
- SciPy’s
ier, and the value to QUADPACK’s own accuracy request. - Measured
- 53 cases matched value, error, evaluation count and panel count exactly when the port landed (46c6065df).
03 COBYLADerivative-free minimization with constraints, by linear approximation Python
fsci-opt/cobyla.rsAssertedMeasured- SciPy runs
- Powell’s COBYLA as SciPy runs it:
scipy._lib.pyprima, the Python translation of Zaikun Zhang’s PRIMA. - FrankenSciPy
crates/fsci-opt/src/cobyla.rs· Ported routine by routine- Compared in
diff_opt_cobyla_minimize.rs- Asserted
- SciPy’s status, success flag and message.
- Measured
- 24 of 25 cases bit-identical in x and f, in OpenBLAS’s SkylakeX evaluation order (9ec3a5475).
04 SLSQPSequential least squares with equality and inequality constraints C
fsci-opt/slsqp.rsAssertedMeasured- SciPy runs
- Kraft’s SLSQP (1988), from SciPy’s C translation in
__slsqp.cand__nnls.c. - FrankenSciPy
crates/fsci-opt/src/slsqp.rs· Ported routine by routine- Compared in
diff_opt_slsqp_constrained.rs- Asserted
- SciPy’s exit message; x within 10⁻⁶ on Hock–Schittkowski problems 6, 7, 21, 35, 71 and 76.
- Measured
- The same final iteration count as SciPy on 15 of 16 cases (569367b2c).
05 trust-constrByrd–Omojokun SQP for equalities, a trust-region interior point for the rest Python
fsci-opt/trust_constr.rsAsserted- SciPy runs
- SciPy’s
_trustregion_constrpackage, with its projections and memoized function wrappers. - FrankenSciPy
crates/fsci-opt/src/trust_constr.rs· Ported routine by routine- Compared in
diff_opt_trust_constr_constrained.rs- Asserted
- Status and message; x to 10⁻⁵, f to 10⁻⁷, Lagrange multipliers to 10⁻⁴.
06 Trust-region Newtontrust-ncg, dogleg, trust-exact and trust-krylov: four subproblem solvers, one driver Python
fsci-opt/trust_region.rsAssertedMeasured- SciPy runs
- SciPy’s
_minimize_trust_regionwith CG–Steihaug, dogleg, Moré–Sorensen and GLTR subproblems. - FrankenSciPy
crates/fsci-opt/src/trust_region.rs· Ported routine by routine- Compared in
diff_opt_trust_region_family.rs- Asserted
- SciPy’s status; x and f to tolerance; iteration count within 30%.
- Measured
- All 30 cases matched SciPy’s exact iteration, function, gradient and Hessian counts.
07 Radau IIA and BDFThe implicit
solve_ivpmethods for stiff problems Pythonfsci-integrate/radau.rsAssertedMeasured- SciPy runs
- SciPy’s
_ivp/radau.pyand_ivp/bdf.py, step for step. - FrankenSciPy
crates/fsci-integrate/src/radau.rs· Ported routine by routine- Compared in
diff_integrate_solve_ivp_stiff.rs- Asserted
- y within one unit of SciPy’s error scale; evaluation and step counts within 1%.
- Measured
- 15 of 16 finite-difference rows reproduce SciPy’s counts exactly.
08 DOP853The explicit eighth-order Runge–Kutta method, with dense output Python
fsci-integrate/rk.rsAsserted- SciPy runs
- SciPy’s
_ivp/rk.py, with Hairer’s coefficients and its blended E5/E3 error norm. - FrankenSciPy
crates/fsci-integrate/src/rk.rs· Ported routine by routine- Compared in
diff_integrate_dop853.rs- Asserted
- y within one unit of SciPy’s error scale wherever SciPy’s own answer is reproducible at that scale.
09 solve_bvpBoundary-value problems by collocation with mesh refinement Python
fsci-integrate/collocation.rsAssertedMeasured- SciPy runs
- Kierzenka and Shampine’s algorithm, transcribed from SciPy’s
_bvp.py. - FrankenSciPy
crates/fsci-integrate/src/collocation.rs· Ported routine by routine- Compared in
diff_integrate_solve_bvp_collocation.rs- Asserted
- SciPy’s status; one boundary-layer problem pinned at SciPy’s 7 iterations and 233 nodes.
- Measured
- The same iterations, node count and mesh on 9 problems (46c6065df).
10 Complex LAPACKLU, QR, Hessenberg, Schur and eigenvectors of complex matrices LAPACK
fsci-linalg/complex.rsAssertedMeasured- SciPy runs
- The LAPACK routines SciPy calls: zgetf2, zgeqr2 and zung2r, zgebal, zgehd2 and zunghr, zlahqr, ztrevc3.
- FrankenSciPy
crates/fsci-linalg/src/complex.rs· Ported routine by routine- Compared in
diff_linalg_complex_core.rs- Asserted
- Factors entry by entry to 10⁻¹², with SciPy’s pivots, signs and eigenvalue order.
- Measured
- 198 cases within 6.8 × 10⁻¹⁵ (7ec9bee19).
11 Jonker–Volgenant
linear_sum_assignment: the cheapest one-to-one assignment C++Same algorithmfsci-opt/lib.rsAsserted- SciPy runs
- The shortest augmenting path method SciPy uses, including rectangular cost matrices.
- FrankenSciPy
crates/fsci-opt/src/lib.rs· Same algorithm- Compared in
diff_opt_linear_sum_assignment.rs- Asserted
- The total cost to 10⁻¹²; ties between optimal assignments may pick different pairs.
12 eigsh and eigsA few eigenvalues of a large sparse matrix COwn algorithm
fsci-sparse/linalg.rsAsserted- SciPy runs
- SciPy calls ARPACK’s implicitly restarted Lanczos and Arnoldi; FrankenSciPy restarts with thick-restart Lanczos and Krylov–Schur.
- FrankenSciPy
crates/fsci-sparse/src/linalg.rs· Own algorithm, same contract- Compared in
diff_sparse_eigs_eigsh_arpack_parity.rs- Asserted
- Eigenvalues, residuals and convergence status against ARPACK’s, for every
which, shift-invert and a mass matrix.
13 linprogLinear programs with HiGHS’s result shape: slacks, residuals and marginals C++Own algorithm
fsci-opt/linprog.rsAssertedMeasured- SciPy runs
- SciPy calls HiGHS; FrankenSciPy has its own bounded revised simplex and a Mehrotra interior point with crossover.
- FrankenSciPy
crates/fsci-opt/src/linprog.rs· Own algorithm, same contract- Compared in
diff_opt_linprog_highs.rs- Asserted
- Status and message for each of SciPy’s three HiGHS methods.
- Measured
- 102 outcomes compared with none failing when it landed.
05Safe to embed
Safe Rust from the API down to the kernels.
All 19 crates forbid unsafe code, nothing links BLAS or LAPACK, and cargo build is the whole build, so the same crates run in a server, a CLI or this tab. Bad input comes back as a typed error, and the audited entry points record why.
Two modes, one API
Strict for parity, hardened for services.
Every mode-aware routine takes a RuntimeMode. Strict behaves as SciPy does, quirks included; Hardened keeps the signatures and refuses more. Neither repairs input: the caller gets a typed error, the ledger a reason.
Each input goes through solve_with_audit in both modes; switch off check_finite to see where they part
- Hardened adds
- NaN and ∞ even with
check_finiteoff - rcond < 10⁻¹⁴ refused, not solved
- > 10,000 rows or columns refused
…
…
…
…
…
…
…
…
…
…
No capresource budgets are the caller’s
RefusedResourceExhausted
resource_exhausted
check_finite is SciPy’s switch for skipping the scan for NaN and infinity. audit_failclosed_property.rs drives all 49 audited APIs with bad input in every mode they have and asserts that each error is recorded as exactly one fail-closed event, the call’s last.The audit ledger
An audit trail per call.
The _with_audit entry points write every decision and refusal to a ledger the caller owns. Each event carries a BLAKE3 fingerprint of the routine and every input, hashed bit for bit, so 0.0 and −0.0 differ.
Change one entry of the matrix by a single bit and watch the solve’s fingerprint
The system A·x = b
The highlighted entry, A[0][2]
x
…
Fingerprint of the solve
with 0.0…
now…
The ledger, one JSON line per event
Across platforms
The same decisions on every platform.
A last-bit difference matters where it tips a decision: one platform solves and another refuses. So the solver’s decision path computes exp and log10 with its own ports, built from +, −, × and ÷.
Compare each result from this tab with the build machine’s, value by value
Running the battery…
- same bits
- different bits
The portfolio’s state digest after the 6×6 solve
this tab…
build machine…
powf and the FFT’s sin and cos.How the decision path stays the same everywhere
exp and log10 come from the runtime’s own FDLIBM and musl ports, so they return the same bits on every platform. For matrices up to 4×4, rcond is computed with one-sided Jacobi rather than an SVD that calls the platform’s math library.
Where the platform library is still used, the differences stay far below the tolerances: LSODA takes the same 236 steps and 453 evaluations in both builds, and its final state differs by at most 1.6 × 10⁻¹³, against its default rtol of 10⁻³ and atol of 10⁻⁶.
What runs this page
The engine in this tab.
Every live figure calls fsci-web: ten FrankenSciPy crates compiled for wasm32-wasip1 and run through a small WASI shim. It reads one JSON request, writes one reply, and never reaches the network.
These numbers come from your browser, and the call count rises as you use the page
- 19/19crates forbid unsafe code at the crate root, and so does this engine.
- 0BLAS or LAPACK packages in
Cargo.lock. A test fails if one appears. - 0async runtimes:
cargo tree -i tokiois empty on Linux, macOS and wasm32. - 1build tool,
cargo build. This page’s engine is the same crates built for wasm32.
Live, from this browser
06Performance
Faster in places, slower in others, all measured.
Every timing here comes from one run on one machine, FrankenSciPy and SciPy 1.17.1 side by side. Batched calls and structured stiff solves win by large factors; dense eigensolves, sparse LU and sparse addition still lose to the LAPACK, SuperLU and C++ code SciPy calls.
Same-run ratios
Wins and losses, on one scale.
Batched calls SciPy can only loop, and solvers that use structure SciPy ignores, win by one to two orders of magnitude. Plain dense and sparse linear algebra still loses. Open any row for its setup and source.
Filter the rows, then open one to see what was timed and where it is recorded
-
curve_fit_manyBatched API2,000 exponential-decay fits145×faster, FrankenSciPy faster. Open for the setup.
One call fits all 2,000 traces. SciPy ran five public routes to the same answers and the fastest, a joint sparse least-squares solve over the whole study, is the one compared: 633.3 ms against 4.38 ms. 32 pinned cores.
A batched API SciPy does not have. Each row of the batch is bit-identical to a single
curve_fitcall. -
minimize_manyBatched APIBFGS from 128 starts102×faster, FrankenSciPy faster. Open for the setup.
Against SciPy's BFGS with the exact analytic gradient, the fastest of four public routes: 748.8 ms against 7.35 ms. 32 pinned cores.
Multistart is common in global optimization; SciPy runs the starts one at a time.
-
spsolveSparse directperiodic 9×11×13 grid, 32 solves84×faster, FrankenSciPy faster. Open for the setup.
Against
scipy.sparse.linalg.spsolve, one thread each: 6.08 ms against 510.1 ms.The same public call was 124.7× slower before its periodic structure was recognized.
-
solve_ivp, BDFStructuren = 512, diagonal Jacobian39×faster, FrankenSciPy faster. Open for the setup.
Against
solve_ivp(method='BDF')at the same tolerances: 13.6 ms against 522.2 ms.The win comes from noticing the Jacobian is diagonal. SciPy runs a dense LU on every refresh.
-
solve_ivp, BDFStructuren = 512, tridiagonal Jacobian12×faster, FrankenSciPy faster. Open for the setup.
Same harness and size, a tridiagonal Jacobian solved through the banded path: 43.1 ms against 514.9 ms.
Less structure, smaller win. The dense row further down is the same experiment with none.
-
tplquad_manyBatched API100 triple integrals7.1×faster, FrankenSciPy faster. Open for the setup.
Against vectorized
cubatureon a persistent 32-worker process pool, SciPy's fastest public route: 14.24 ms against 2.03 ms.Batched quadrature over a parameter sweep.
-
quad_manyBatched API2,048 integrals5.8×faster, FrankenSciPy faster. Open for the setup.
Against
quadon a persistent 32-worker process pool: 7.64 ms against 1.32 ms.A damped frequency-response study, one integral per parameter set.
-
normaltest, jarque_bera, shapiroBatched API2,048 channels × 4,096 samples4.9×faster, FrankenSciPy faster. Open for the setup.
Batched normality screening against a persistent 32-worker process pool: 83.8 ms against 17.0 ms.
Re-measured in September after the ledger retired the earlier 74–2,267× claims.
-
gmresIterativen = 1,0244.9×faster, FrankenSciPy faster. Open for the setup.
Nonsymmetric convection-diffusion,
rtol = 1e-5. Both sides did the same 127 inner iterations: 2.36 ms against 11.55 ms.Same algorithm, same iteration count; the difference is per-iteration cost.
-
dblquad_manyBatched API128 double integrals3.5×faster, FrankenSciPy faster. Open for the setup.
Against vectorized
cubatureon a 32-worker process pool: 4.19 ms against 1.20 ms.Just above the project's 3× bar for calling a win durable.
-
newton_manyBatched API65,536 implied volatilities1.99×faster, FrankenSciPy faster. Open for the setup.
Against array
newtonon a 32-worker process pool: 13.07 ms against 6.56 ms.Faster, but under the 3× bar, so the ledger does not call it a durable win.
-
gmresIterativen = 4,0961.57×faster, FrankenSciPy faster. Open for the setup.
The same problem on a larger grid, 163 inner iterations each: 13.90 ms against 20.79 ms.
The lead shrinks as the problem grows.
-
gmresIterativen = 9,2161.06×slower, SciPy faster. Open for the setup.
Larger still, 227 inner iterations each: 38.33 ms against 36.06 ms.
Here SciPy is ahead, by 6%.
-
choleskyDensen = 8321.61×slower, SciPy faster. Open for the setup.
A = MMᵀ + nI, FrankenSciPy on all 64 threads against SciPy's threaded LAPACK.
One cell of a measured loss band from n ≈ 576 to 1,280. FrankenSciPy wins again at n = 2,048.
-
solve_ivp, BDFDensen = 512, dense Jacobian2.1×slower, SciPy faster. Open for the setup.
The BDF experiment above with no exploitable structure: 1,086.7 ms against 513.5 ms. 129 LU factorizations against LAPACK's
dgetrf, and 1.9× as many right-hand-side evaluations.On a dense stiff problem FrankenSciPy is 2.1× slower. Its BDF wins only where structure lets it.
-
splu, solve stageSparse directn = 16,384, 16 right-hand sides2.3×slower, SciPy faster. Open for the setup.
Convection-diffusion against SuperLU, one thread each, default settings: 52.0 ms for the 16 solves.
Declaring the 16 solves up front makes the solve stage 1.61× faster than SuperLU, at a cost of 1.29× on the factorization.
-
eighDensen = 7683.6×slower, SciPy faster. Open for the setup.
Dense symmetric eigendecomposition against SciPy with one BLAS thread: 3.63× slower.
The worst dense cell. 61.5% of the time is the eigenvector back-transform; a blocked rewrite of it was measured slower and rejected.
-
COO additionSparse direct28,672², two 1-million-entry operands16×slower, SciPy faster. Open for the setup.
192.5 ms against SciPy's 12.0 ms.
The shipped path is still the slow one: a faster merge reached only 0.49× of SciPy and was reverted (see below).
Which rows are here, and which are not
A row qualifies only if FrankenSciPy and SciPy 1.17.1 were timed in the same invocation on the same machine; beating FrankenSciPy’s own older code does not count. The ledger marks some older fsci-stats, signal, cluster, interpolate, io and fft rows as unverified at the current commit, and they are left out, as is root_many, whose SciPy timing failed its own noise check.
Because the rows were measured on different days, machines and thread counts, the board is a map of where each side is strong, not one benchmark. A single scoreboard re-measured at one commit is in progress, tracked as frankenscipy-sw4p0.2.
The optimization loop
A speedup counts when it beats SciPy.
Every claimed speedup goes through the same five steps, and the ledger keeps failures as carefully as wins. Two real changes: one kept, one reverted after making the code 7.8× faster, because it still lost to SciPy.
Follow two real changes through the same five steps
KeptPeriodic sparse solvethe ledger entry
- 1Baseline124.7×slower than SciPy
- 2ProfileLUon every call; the periodic Fourier path sat unused
- 3One leverFFTreuse the periodic recognizer and Fourier plan
- 4Prove32 / 32calls took the new route; 0 components differ
- 5Re-measure84.2×faster than SciPy: 6.08 ms against 510.1 ms
- ✓DecideKeepthe 67.6× over the old code is logged as maintenance
RevertedSparse additionthe ledger entry
- 1Baseline16×slower than SciPy: 192.5 ms against 12.0 ms
- 2Profiletreeboth operands cloned, merged through an ordered tree
- 3One lever1 passmerge the two sorted operands linearly
- 4Provebit for bitsame matrix as SciPy: pointers, indices, floats
- 5Re-measure2.05×still slower than SciPy, though 7.8× faster than before
- ✓DecideRevertrestored byte for byte; the result stays in the ledger
Every step as the ledger records it
Kept · Periodic sparse solve
- Baseline. Public
spsolveon a shifted periodic cuboid, one factor and solve per right-hand side: 124.7× slower than SciPy. - Profile. The one-shot call took the general sparse factorization every time. The crate already had a recognizer for periodic grids and a Fourier plan; this path never used them.
- One lever. Reuse the periodic recognizer and Fourier plan inside
spsolve, falling back to LU when the true residual is too large. - Prove. The new route fired on 32 of 32 calls. Largest relative residual 2.1 × 10⁻¹², against SciPy’s 1.5 × 10⁻¹²; no component disagreed.
- Re-measure. 6.08 ms against SciPy’s 510.1 ms: 84.2× faster. The 67.6× over the old code is recorded separately, as maintenance.
- Decide. Kept: the route ships, and the row joins the scoreboard above.
Reverted · Sparse addition
- Baseline. Adding two 1-million-entry COO matrices, 28,672 square: 192.5 ms, against SciPy’s 12.0 ms.
- Profile. The public addition cloned both operands and merged their entries through an ordered tree.
- One lever. Merge the two sorted operands in one linear pass instead of through the tree.
- Prove. The candidate, the old path and SciPy produced the same sparse matrix, every pointer, index and float bit for bit.
- Re-measure. 24.6 ms: 7.8× faster than the old code, and still 2.05× slower than SciPy’s 12.0 ms. The gate requires beating SciPy.
- Decide. Reverted: the code is restored byte for byte in a new commit, so the attempt stays in the history and the result stays in the ledger.
The decision is taken on the bootstrap-median interval, which must clear twice the noise of timing each side against itself. The kept change’s parity is in the same entry, and the loss it closed here; the reverted change’s timings are here.
07Get started
Add a crate. Keep your Rust.
Every fsci-* crate is on crates.io at version 0.5.2. Add the ones you need: each brings in only the fsci crates it depends on, and none of them brings in Python, a BLAS or a LAPACK.
Version 0.5.2
Pick the crates, copy one line.
Tick the crates you need and copy one cargo add line, or copy any crate on its own. Eleven of the eighteen need nightly Rust; the repository pins nightly-2026-08-31.
Tick the crates you need, then copy the command or the Cargo.toml lines
Your command
cargo add fsci-linalg fsci-stats
Cargo also builds fsci-fft, fsci-integrate, fsci-opt, fsci-runtime, fsci-sparse, fsci-special, which they depend on.
Or in Cargo.toml
[dependencies] fsci-linalg = "0.5" fsci-stats = "0.5"
Toolchain: rustup toolchain install nightly-2026-08-31, then a rust-toolchain.toml naming it in your project.
-
Linear algebra decompositions, solvers, and eigenvalues.
79 of 103 SciPy names compared live
linalglinalg.interpolative80k lines · 920 tests
-
Probability distributions and statistical tests.
262 of 358 SciPy names compared live
statsstats.contingencystats.mstatsstats.qmcstats.sampling156k lines · 2,654 tests
-
Special mathematical functions.
211 of 358 SciPy names compared live
special85k lines · 1,407 tests
-
Optimization and root-finding solvers.
34 of 77 SciPy names compared live
differentiateoptimizeoptimize.elementwise84k lines · 937 tests
-
Numerical integration and ODE/IVP solvers.
15 of 32 SciPy names compared live
integrate57k lines · 690 tests
-
Sparse matrices and iterative solvers.
78 of 114 SciPy names compared live, 2 missing
sparsesparse.csgraphsparse.linalg98k lines · 1,004 tests
-
Signal processing, filter design, and spectral analysis.
92 of 182 SciPy names compared live
signalsignal.windows46k lines · 831 tests
-
Fast Fourier Transform routines.
30 of 47 SciPy names compared live
fftfftpack14k lines · 266 tests
-
Interpolation and spline routines.
15 of 56 SciPy names compared live
interpolate30k lines · 318 tests
-
Spatial data structures and distance computations.
30 of 49 SciPy names compared live
spatialspatial.distancespatial.transform20k lines · 329 tests
-
Vector quantization and hierarchical clustering.
12 of 35 SciPy names compared live
cluster.hierarchycluster.vq18k lines · 224 tests
-
Multi-dimensional image processing routines.
39 of 75 SciPy names compared live
ndimage33k lines · 373 tests
-
File format I/O (MATLAB, Matrix Market, WAV).
12 of 30 SciPy names compared live, 4 missing
ioio.arffio.matlabio.wavfile14k lines · 162 tests
-
Orthogonal Distance Regression.
2 of 10 SciPy names compared live
odr5.8k lines · 39 tests
-
Physical and mathematical constants.
5 of 7 SciPy names compared live
constants1.7k lines · 25 tests
-
Standard sample fixtures and datasets.
0 of 5 SciPy names compared live
datasets669 lines · 9 tests
-
Condition-Aware Solver Portfolio (CASP) runtime.
CASP, the audit ledger and the Strict and Hardened modes. Add it to pass your own
SolverPortfolioorAuditLedgerto a call.9.5k lines · 414 tests
-
Reference Array API abstraction layer.
The reference Array API backend and broadcasting rules the conformance suite checks against.
5.1k lines · 64 tests
wc -l over each crate’s src/ with inline tests, tests count #[test] functions, and the bar counts the SciPy names the census assigns to each crate. fsci-conformance (36,535 lines, 1,638 tests) is on crates.io too, but it is the test harness that drives a live SciPy; leave it out of your dependencies.Why most crates need nightly Rust
fsci-cluster, fsci-linalg, fsci-ndimage, fsci-spatial, fsci-special, fsci-stats enable the unstable portable_simd feature for their vector kernels, so they and every crate that depends on them build only on a nightly toolchain. A crate is marked nightly when it, or one of the fsci crates it pulls in, enables an unstable feature.
The repository pins nightly-2026-08-31 in its rust-toolchain.toml, and CI checks that the pin and the toolchain it installs agree. Pin the same one in your project to build exactly what the tests ran against.
From Python
The same call, spelled in Rust.
Names and defaults follow SciPy, so most ports are mechanical. Pick an area to see everyday calls beside their Rust, with the use line to start from.
Pick an area of SciPy to see its calls next to their Rust equivalents
Linear algebra
use fsci_linalg::{eigh, expm, lstsq, solve, DecompOptions, LstsqOptions, SolveOptions};x = scipy.linalg.solve(a, b)
let x = solve(&a, &b, SolveOptions::default())?.x;ais aVec<Vec<f64>>, one inner vector per row. The result also carries the CASPcertificateand thebackward_error.x, res, rank, sv = scipy.linalg.lstsq(a, b)
let r = lstsq(&a, &b, LstsqOptions::default())?;One struct instead of a four-tuple:
r.x,r.residuals,r.rank,r.singular_values.w, v = scipy.linalg.eigh(a)
let r = eigh(&a, DecompOptions::default())?;r.eigenvaluesin ascending order andr.eigenvectorsas columns, as SciPy returns them.e = scipy.linalg.expm(a)
let e = expm(&a, DecompOptions::default())?;Padé approximation with scaling and squaring, the algorithm SciPy uses.
Sparse
use fsci_sparse::{cg, spsolve, CsrMatrix, IterativeSolveOptions, Shape2D, SolveOptions};a = csr_matrix((data, indices, indptr), shape=(m, n))
let a = CsrMatrix::from_components(Shape2D::new(m, n), data, indices, indptr, true)?;
The last argument asks for sorted indices with duplicate entries summed.
x = spsolve(a, b)
let x = spsolve(&a, &b, SolveOptions::default())?.solution;The result also names the backend and the fill-reducing ordering that were used.
x, info = cg(a, b)
let r = cg(&a, &b, None, IterativeSolveOptions::default())?;
infobecomesr.converged, withr.iterationsandr.residual_normbeside it. The third argument is the starting guess.
Optimize
use fsci_opt::{bfgs, brentq, lbfgsb, MinimizeOptions, RootOptions};res = minimize(f, x0, method="BFGS")let res = bfgs(&f, &x0, MinimizeOptions::default())?;fis anyFn(&[f64]) -> f64.minimize(f, &x0, options)withmethod: Some(OptimizeMethod::Bfgs)does the same.res = minimize(f, x0, method="L-BFGS-B", bounds=[(0, None)] * n)
let bounds = vec![(Some(0.0), None); n]; let res = lbfgsb(&f, &x0, MinimizeOptions::default(), Some(&bounds))?;
A bound is an
(Option<f64>, Option<f64>)pair, andNoneleaves that side open.root = brentq(f, a, b)
let root = brentq(f, (a, b), RootOptions::default())?.root;The result also reports
converged,iterationsandfunction_calls.
Integrate
use fsci_integrate::{quad, solve_ivp, QuadOptions, SolveIvpOptions, SolverKind};sol = solve_ivp(f, (0, 10), y0, method="LSODA")
let sol = solve_ivp(&mut f, &SolveIvpOptions { t_span: (0.0, 10.0), y0: &y0, method: SolverKind::Lsoda, ..Default::default() })?;
fis anFnMut(f64, &[f64]) -> Vec<f64>. RK23, RK45, DOP853, Radau, BDF and LSODA are all there, with SciPy’s defaults.val, err = quad(f, a, b)
let r = quad(f, a, b, QuadOptions::default())?;r.integralandr.error, from a port of QUADPACK’s qagse, the routine SciPy calls.
Signal and FFT
use fsci_fft::{rfft, FftOptions}; use fsci_signal::{butter, filtfilt, FilterType};
spec = scipy.fft.rfft(x)
let spec = rfft(&x, &FftOptions::default())?;Each bin comes back as an
(re, im)pair. SciPy’s normalization is the default.b, a = butter(4, [lo, hi], btype="bandpass")
let ba = butter(4, &[lo, hi], FilterType::Bandpass)?;
Frequencies are normalized to Nyquist, as in SciPy. The coefficients are
ba.bandba.a.y = filtfilt(b, a, x)
let y = filtfilt(&ba.b, &ba.a, &x)?;Zero-phase filtering, forward then backward, with SciPy’s default padding.
Statistics
use fsci_stats::{ttest_ind_welch, BetaDist, ContinuousDistribution, Normal};p = scipy.stats.norm.pdf(x, loc, scale)
let p = Normal::new(loc, scale).pdf(x);The
ContinuousDistributiontrait has to be in scope forpdf,cdf,ppfand the moments.q = scipy.stats.beta(2, 5).ppf(0.5)
let q = BetaDist::new(2.0, 5.0).ppf(0.5);
Distribution constructors panic on invalid parameters, the one documented exception to typed errors.
t, p = ttest_ind(a, b, equal_var=False)let t = ttest_ind_welch(&a, &b);Welch’s test is its own function;
ttest_indis the pooled-variance test, SciPy’s default.
Special
use fsci_runtime::RuntimeMode; use fsci_special::{elliprf, gamma, SpecialTensor};
g = scipy.special.gamma(x)
let g = gamma(&SpecialTensor::RealScalar(x), RuntimeMode::Strict)?;Tensor functions take a scalar, a vector or complex values, plus a mode.
RealVecevaluates a whole array in one call.rf = scipy.special.elliprf(x, y, z)
let rf = elliprf(x, y, z);The Carlson elliptic integrals are plain
f64functions.
Spatial
use fsci_spatial::KDTree;d, i = KDTree(points).query(q)
let (i, d) = KDTree::new(&points)?.query(&q)?;Index first, then distance: the reverse of SciPy’s tuple.
Result are shown with ?; the error types are LinalgError, SparseError, OptError and so on, one per crate.- 1
Keyword arguments become an options struct
Set the fields you would pass by keyword;
Defaultholds SciPy’s defaults.# SciPy minimize(f, x0, tol=1e-10, options={"maxiter": 500}) // FrankenSciPy MinimizeOptions { tol: Some(1e-10), maxiter: Some(500), ..Default::default() }
- 2
Tuples become named result structs
Read fields by name instead of unpacking a tuple by position.
# SciPy w, v = scipy.linalg.eigh(a) // FrankenSciPy let r = eigh(&a, opts)?; // r.eigenvalues, r.eigenvectors
- 3
Portfolios and ledgers are explicit
Plain
solvekeeps a portfolio per thread; pass your own, or a ledger, when you need one.# SciPy x = scipy.linalg.solve(a, b) // FrankenSciPy solve_with_audit(&a, &b, opts, &mut portfolio, &ledger)?
Honest scope
When it fits, and when it doesn’t.
FrankenSciPy is for Rust programs that need SciPy’s numerics. It does not replace SciPy for interactive work, and it does not try to beat vendor BLAS on large dense matrices.
Reach for it when
A Rust service needs SciPy’s numerics without embedding Python.
An audit or a postmortem must show which algorithm produced a number.
No BLAS, LAPACK or Fortran in the build, and
forbid(unsafe_code)in every fsci crate.SciPy’s names and defaults in a synchronous, deterministic API.
An agent or a pipeline needs a record of every decision and refusal.
Look elsewhere for
Exploring data in a notebook: SciPy, pandas and matplotlib fit better.
Calling it from Python: there is no Python binding today.
The fastest big dense linear algebra: a BLAS-backed stack wins there.
A GPU or a cluster: every routine runs on one machine’s CPU.
One of the six missing names, or a stable API: the crates are pre-1.0.
Check a specific name in the lookup, the losses on the scoreboard, and the open defects in the README’s limitations.
Open source · version 0.5.2
Read the code. Run the tests.
Everything on this page can be checked from a clone: the 783 differential tests, the 1,167 tolerance contracts, the census of SciPy’s public names and the CASP calibration corpus. The README separates what is implemented from what is planned, and lists the places where FrankenSciPy is still slower than SciPy. Bug reports with a failing input are the most useful thing you can send.
git clone https://github.com/Dicklesworthstone/frankenscipy
cd frankenscipy
cargo test -p fsci-conformance # the live-SciPy tests need SciPy 1.17.1 and NumPy 2.4.3