Linear algebra types and operations for dew expressions.
This crate provides vector and matrix types (Vec2, Vec3, Mat2, Mat3, etc.)
that work with dew-core's AST. Types propagate during evaluation/emission.
Quick Start
use wick_core::Expr;
use wick_linalg::{Value, eval, linalg_registry};
use std::collections::HashMap;
let expr = Expr::parse("dot(a, b)").unwrap();
let vars: HashMap<String, Value<f32>> = [
("a".into(), Value::Vec2([1.0, 0.0])),
("b".into(), Value::Vec2([0.0, 1.0])),
].into();
let result = eval(expr.ast(), &vars, &linalg_registry()).unwrap();
assert_eq!(result, Value::Scalar(0.0));
Features
| Feature |
Description |
3d |
Vec3, Mat3 (default) |
4d |
Vec4, Mat4 (implies 3d) |
wgsl |
WGSL shader code generation |
lua |
Lua code generation |
cranelift |
Cranelift JIT compilation |
Types
| Type |
Description |
Scalar |
Single f32/f64 value |
Vec2 |
2D vector [x, y] |
Vec3 |
3D vector [x, y, z] (3d) |
Vec4 |
4D vector [x, y, z, w] (4d) |
Mat2 |
2x2 matrix, column-major |
Mat3 |
3x3 matrix, column-major (3d) |
Mat4 |
4x4 matrix, column-major (4d) |
Functions
| Function |
Description |
dot(a, b) |
Dot product → scalar |
cross(a, b) |
Cross product → vec3 (3d only) |
length(v) |
Vector magnitude → scalar |
normalize(v) |
Unit vector → same type |
distance(a, b) |
Distance between points → scalar |
reflect(v, n) |
Reflect v around normal n → same type |
hadamard(a, b) |
Element-wise multiply → same type |
lerp(a, b, t) |
Linear interpolation |
mix(a, b, t) |
Alias for lerp |
Operators
| Operation |
Types |
vec + vec |
Component-wise addition |
vec - vec |
Component-wise subtraction |
vec * scalar |
Scalar multiplication |
scalar * vec |
Scalar multiplication |
mat * vec |
Matrix-vector multiplication |
mat * mat |
Matrix multiplication |
-vec |
Negation |
Composability
For composing multiple domain crates (e.g., linalg + rotors), the [LinalgValue]
trait allows defining a combined value type that works with both crates.