2 unstable releases

0.4.0 Jan 3, 2024
0.2.0 Dec 22, 2023

#1406 in Parser implementations

Download history 687/week @ 2024-03-14 581/week @ 2024-03-21 975/week @ 2024-03-28 381/week @ 2024-04-04 544/week @ 2024-04-11 997/week @ 2024-04-18 67/week @ 2024-04-25 426/week @ 2024-05-02 334/week @ 2024-05-09 567/week @ 2024-05-16 475/week @ 2024-05-23 1284/week @ 2024-05-30 768/week @ 2024-06-06 931/week @ 2024-06-13 208/week @ 2024-06-20 641/week @ 2024-06-27

2,857 downloads per month

MIT/Apache

44KB
1K SLoC

vector-expr

Vectorized math expression parser/evaluator.

Why?

Performance. Evaluation of math expressions involving many variables can incur significant overhead from traversing the expression tree or performing variable lookups. We amortize that cost by performing intermediate operations on vectors of input data at a time (with optional data parallelism via the rayon feature).

Example

use vector_expr::*;

fn binding_map(var_name: &str) -> BindingId {
    match var_name {
        "bar" => 0,
        "baz" => 1,
        "foo" => 2,
        _ => unreachable!(),
    }
}
let parsed = Expression::parse("2 * (foo + bar) * baz", &binding_map).unwrap();
let real = parsed.unwrap_real();

let bar = [1.0, 2.0, 3.0];
let baz = [4.0, 5.0, 6.0];
let foo = [7.0, 8.0, 9.0];
let bindings: &[&[f64]] = &[&bar, &baz, &foo];
let mut registers = Registers::new(3);
let output = real.evaluate(bindings, &mut registers);
assert_eq!(&output, &[64.0, 100.0, 144.0]);

License: MIT OR Apache-2.0

Dependencies

~3–4.5MB
~90K SLoC