Skip to content

Repository files navigation

Github CI Crates.io docs.rs

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:

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.

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:

cargo run --example regression_workflow

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.

About

Scientific computing for Rhai.

Topics

Resources

Stars

20 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages