docs.rs failed to build scirs2-wasm-0.2.0
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build:
scirs2-wasm-0.3.4
SciRS2-WASM: Scientific Computing in WebAssembly
High-performance scientific computing library for JavaScript and TypeScript, powered by Rust and WebAssembly.
Features
- Pure Rust: 100% safe Rust code compiled to WASM
- High Performance: Near-native performance in the browser
- SIMD Support: Optional WASM SIMD acceleration (wasm32-simd128)
- TypeScript Support: Full TypeScript type definitions
- Zero Dependencies: No external JavaScript dependencies
- Memory Efficient: Optimized for browser memory constraints
- Async Operations: Non-blocking computations
Installation
NPM
Yarn
PNPM
Quick Start
Browser (ES Modules)
import init * as scirs2 from 'scirs2-wasm';
;
Node.js
const scirs2 = require;
;
TypeScript
import init, * as scirs2 from 'scirs2-wasm';
async function main(): Promise<void> {
await init();
// Type-safe array operations
const arr: scirs2.WasmArray = scirs2.WasmArray.linspace(0, 10, 100);
const mean: number = scirs2.mean(arr);
const std: number = scirs2.std(arr);
console.log(`Mean: ${mean}, Std: ${std}`);
}
main();
API Reference
Array Creation
// From JavaScript array
const arr = ;
// From typed array
const typed = ;
const arr2 = ;
// With specific shape (2D matrix)
const matrix = scirs2.;
// Special arrays
const zeros = scirs2.;
const ones = scirs2.;
const full = scirs2.;
// Range arrays
const linspace = scirs2.; // [0, 0.02, 0.04, ..., 1]
const arange = scirs2.; // [0, 0.5, 1, ..., 9.5]
Array Operations
const a = ;
const b = ;
// Element-wise operations
const sum = scirs2.; // [5, 7, 9]
const diff = scirs2.; // [-3, -3, -3]
const prod = scirs2.; // [4, 10, 18]
const quot = scirs2.; // [0.25, 0.4, 0.5]
// Dot product and matrix operations
const dot = scirs2.; // 32
const matrix_a = scirs2.;
const matrix_b = scirs2.;
const matmul = scirs2.;
// Reductions
const total = scirs2.; // 6
const average = scirs2.; // 2
const minimum = scirs2.; // 1
const maximum = scirs2.; // 3
Statistical Functions
const data = ;
// Descriptive statistics
const mean = scirs2.; // 3
const std = scirs2.; // ~1.41
const variance = scirs2.; // ~2
const median = scirs2.; // 3
// Percentiles
const p25 = scirs2.; // 2
const p75 = scirs2.; // 4
// Correlation
const x = ;
const y = ;
const corr = scirs2.; // 1.0 (perfect correlation)
// Cumulative operations
const cumsum = scirs2.; // [1, 3, 6, 10, 15]
const cumprod = scirs2.; // [1, 2, 6, 24, 120]
Linear Algebra
const matrix = scirs2.;
// Matrix properties
const det = scirs2.; // Determinant
const trace = scirs2.; // Sum of diagonal
const rank = scirs2.; // Matrix rank
const norm = scirs2.; // Frobenius norm
// Matrix operations
const inv = scirs2.; // Matrix inverse
const transpose = matrix.; // Matrix transpose
// Solve linear system Ax = b
const A = scirs2.;
const b = ;
const x = scirs2.; // Solution: x = [2, 3]
Random Number Generation
// Uniform random [0, 1)
const uniform = scirs2.;
// Normal distribution (mean=0, std=1)
const normal = scirs2.;
// Random integers [0, 10)
const integers = scirs2.;
// Exponential distribution (lambda=1.5)
const exponential = scirs2.;
Performance Monitoring
// Time operations
const timer = ;
const a = scirs2.;
const b = scirs2.;
const result = scirs2.;
timer.; // Logs: "Matrix multiplication: 45.123ms"
// Check capabilities
const caps = scirs2.;
console.log;
console.log;
Building from Source
Prerequisites
- Rust 1.70+ with
wasm32-unknown-unknowntarget - wasm-pack
- Node.js 18+
Build Steps
# Install Rust target
# Install wasm-pack
|
# Build for bundlers (webpack, rollup, etc.)
# Build for web (ES modules)
# Build for Node.js
# Build with SIMD support
# Optimize with wasm-opt
Testing
# Run tests in headless Firefox
# Run tests in headless Chrome
# Run tests in Node.js
Performance
SciRS2-WASM provides near-native performance for scientific computing tasks:
- Array operations: 80-95% of native performance
- Matrix multiplication: Up to 90% with SIMD
- Statistical functions: 85-95% of native
- Random number generation: 70-85% (limited by WASM RNG)
SIMD Acceleration
For maximum performance, build with SIMD support:
Note: SIMD requires browser support for wasm-simd128 feature.
Browser Compatibility
- Chrome 91+ (with SIMD: 91+)
- Firefox 89+ (with SIMD: 89+)
- Safari 16.4+ (with SIMD: limited)
- Edge 91+ (with SIMD: 91+)
- Node.js 18+ (with SIMD: 20+)
Memory Management
WASM has a linear memory model. Best practices:
- Reuse arrays when possible to avoid allocations
- Process in chunks for large datasets
- Monitor memory usage with browser DevTools
- Dispose arrays explicitly if needed (future feature)
Examples
See the examples/ directory for complete examples:
basic-arrays.html- Array creation and manipulationstatistics.html- Statistical analysislinear-algebra.html- Matrix operationsperformance.html- Performance benchmarkingnode-example.js- Node.js usage
Contributing
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
License
Apache-2.0
Authors
COOLJAPAN OU (Team KitaSan)
Acknowledgments
- Built with wasm-bindgen
- Powered by ndarray
- Part of the SciRS2 ecosystem