High-performance scientific mathematical functions for WebAssembly
npm install @velo-sci/sci-math-wasm
High-performance scientific mathematical functions for the web, powered by Rust and WebAssembly.
sci-math-wasm provides a robust, typed, and highly optimized set of mathematical tools designed specifically for scientific applications, data analysis, and signal processing in browser environments.
- ๐ Performance: Hand-optimized Rust algorithms compiled to WASM.
- ๐ Analysis: Regression, Calculus, and Signal Processing (FFT).
- ๐ Statistics: Mean, median, variance, standard deviation.
- ๐ข Linear Algebra: Vector and Matrix operations.
- ๐ File I/O: Scientific data parsing (CSV, Excel, DAT, MPT) with auto-detection.
- ๐ Math Tools: Complex numbers, Polynomials, and Trigonometry.
- ๐ Documentation: Full VitePress site with LaTeX support.
Full documentation is available at https://velosci.github.io/sci-math-wasm/ (locally in /docs).
Interactive benchmarks comparing WASM vs JavaScript performance for both mathematical computations and file processing are available at the /bench route.
``bash`
npm install sci-math-wasmor
pnpm add sci-math-wasm
`typescript
import init, { mean, fft, magnitude, TextStreamer, sniffFormat } from 'sci-math-wasm';
async function run() {
await init();
// === Mathematical Operations ===
const data = new Float64Array([1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0]);
// Statistics
const avg = mean(data);
console.log(Mean: ${avg});
// Signal Processing
const spectrum = fft(data);
const mags = magnitude(spectrum);
console.log('Frequencies:', mags);
// === File Processing ===
// Auto-detect file format
const fileHeader = new Uint8Array(await file.slice(0, 2048).arrayBuffer());
const hint = sniffFormat(fileHeader);
if (!hint.isBinary) {
// Process text-based scientific files
const streamer = new TextStreamer()
.setDelimiter(hint.delimiter)
.setSkipLines(hint.skipLines)
.setCommentChar(hint.commentChar);
// Stream processing for large files
const reader = file.stream().getReader();
while (true) {
const { done, value } = await reader.read();
if (done) break;
const rows = streamer.processChunk(value);
// Process rows incrementally
}
}
}
run();
`
- basic: Fundamental arithmetic and utilities.stats
- : Statistical analysis tools.linalg
- : Linear algebra (Vectors & Matrices).signal
- : Advanced signal processing (FFT).io
- : Scientific file parsing (CSV, Excel, DAT, MPT) with auto-detection.
and wasm-pack.`bash
wasm-pack build --target web
`$3
`bash
cargo doc --open
``MIT ยฉ VeloSci