rhai-sci
Scientific computing for the Rhai scripting language, inspired by MATLAB, Octave, and R. Includes statistics, linear algebra, interpolation, integration, and regression.
Quickstart
Add the crate to your Cargo.toml:
= "0.4.0"
Evaluate a Rhai expression:
use INT;
use eval;
let result = .unwrap;
assert_eq!;
For a persistent engine, register SciPackage as shown in the
Rust host example.
Numerical workflows
Use row, col, and mat to construct vectors and matrices from ordinary Rhai
arrays. Statistics accept lists, rows, or columns; sequence results are flat lists.
Use mtimes for matrix multiplication and dot for a scalar vector inner product.
regress(X, y) fits an intercept automatically and returns it separately from the
predictor coefficients. See the workflow guide for
shape conventions, predictions, and input validation.
Run the bundled CSV example to fit a model and summarize its residuals:
More examples: matrix inversion, projectile motion, and XOR backpropagation.
Features
| Feature | Default | Enables |
|---|---|---|
io |
On | CSV loading with read_matrix |
nalgebra |
On | Matrix operations and regression |
rand |
On | Random values and matrices |
metadata |
Off | Function metadata and Rhai documentation tests |
Disable default features and select only what you need for smaller builds; CSV support brings in Polars.
Reference
API documentation · Changelog · Development checks
License
Licensed under MIT or Apache-2.0, at your option.