Skip to main content

Crate wick_linalg

Crate wick_linalg 

Source
Expand description

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)); // perpendicular vectors

§Features

FeatureDescription
3dVec3, Mat3 (default)
4dVec4, Mat4 (implies 3d)
wgslWGSL shader code generation
luaLua code generation
craneliftCranelift JIT compilation

§Types

TypeDescription
ScalarSingle f32/f64 value
Vec22D vector [x, y]
Vec33D vector [x, y, z] (3d)
Vec44D vector [x, y, z, w] (4d)
Mat22x2 matrix, column-major
Mat33x3 matrix, column-major (3d)
Mat44x4 matrix, column-major (4d)

§Functions

FunctionDescription
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

OperationTypes
vec + vecComponent-wise addition
vec - vecComponent-wise subtraction
vec * scalarScalar multiplication
scalar * vecScalar multiplication
mat * vecMatrix-vector multiplication
mat * matMatrix multiplication
-vecNegation

§Composability

For composing multiple domain crates (e.g., linalg + rotors), the LinalgValue trait allows defining a combined value type that works with both crates.

Modules§

ops
Binary and unary operations with type dispatch.

Structs§

Cross
Cross product: cross(a, b) -> vec3
Distance
Distance between two points: distance(a, b) -> scalar
Dot
Dot product: dot(a, b) -> scalar
FunctionRegistry
Registry of linalg functions.
Hadamard
Element-wise vector multiply: hadamard(a, b) -> vec
Length
Vector length: length(v) -> scalar
Lerp
Linear interpolation: lerp(a, b, t) -> vec Returns a + (b - a) * t
Mix
Linear interpolation (GLSL naming): mix(a, b, t) -> vec
Normalize
Normalize vector: normalize(v) -> vec (same type, unit length)
Reflect
Reflect vector: reflect(incident, normal) -> vec Returns incident - 2 * dot(normal, incident) * normal
Signature
A function signature: argument types and return type.

Enums§

Error
Linalg evaluation error.
Type
Type of a linalg value (shape only, not numeric type).
Value
A linalg value, generic over numeric type.

Traits§

LinalgFn
A function that can be called from linalg expressions.
LinalgValue
Trait for values that support linalg operations.

Functions§

eval
Evaluate an AST with linalg values.
linalg_registry
Create a new registry with all standard linalg functions using the default Value type.
linalg_registry_int
Create a registry with Numeric-compatible functions for integer vectors.
register_linalg
Register all standard linalg functions.
register_linalg_numeric
Register only Numeric-compatible linalg functions (no sqrt, trig, etc.).