Scientific computing for the Rhai scripting language, inspired by MATLAB, Octave, and R. Includes statistics, linear algebra, interpolation, integration, and regression.
Add the crate to your Cargo.toml:
rhai-sci = "0.4.0"Evaluate a Rhai expression:
use rhai::INT;
use rhai_sci::eval;
let result = eval::<INT>("argmin([43, 42, -500])").unwrap();
assert_eq!(result, 2);For a persistent engine, register SciPackage as shown in the
Rust host example.
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:
cargo run --example regression_workflowMore examples: matrix inversion, projectile motion, and XOR backpropagation.
| 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.
API documentation · Changelog · Development checks
Licensed under MIT or Apache-2.0, at your option.