Expand description
Element-wise vector math nodes (type_system_alignment.md §8.2).
These are the first compute-shaped (rather than I/O-shaped)
consumers of the typed-vector family: perturbing query vectors,
computing ground-truth distances in evaluations, normalizing
embeddings. On jit builds the f32 hot loops execute through
the cranelift-SIMD kernels (compile::jit::simd — F32X4
chunked with scalar tails); without jit, or if host ISA
construction fails, the scalar reference loops below run
instead. SIMD accumulation reassociates float addition, so dot
products may differ from the scalar reference in the final
ulps — both orders are equally valid IEEE 754 sums.
Length mismatches panic with both lengths named: silently truncating to the shorter operand would corrupt distance semantics (“never ignore silently”).
Structs§
- HashVec
hash_vec(seed, dim)— deterministic synthetic f32 vector: elementiis the SplitMix64 hash of(seed, i)mapped into[-1, 1). The canonical generator for synthetic embeddings — equal seeds always produce the identical vector, so dataset- free vector workloads stay replayable. Pairs withvec_normfor unit vectors.- LidMle
lid_mle(distances, k)— Levina–Bickel maximum-likelihood estimate of the local intrinsic dimensionality at one query point, from its sorted ground-truth nearest-neighbor distances.- VecAdd
F32 vec_add_f32(a, b)— element-wise sum of two f32 vectors. Panics when the lengths differ.- VecAdd
F64 vec_add_f64(a, b)— element-wise sum of two f64 vectors. Panics when the lengths differ.- VecCosine
F32 vec_cosine_f32(a, b)— cosine similarity of two f32 vectors:dot(a,b) / (|a| * |b|). Returns 0.0 when either vector has zero magnitude (the conventional degenerate-case value: no direction, no similarity). Panics when the lengths differ.- VecCosine
F64 vec_cosine_f64(a, b)— cosine similarity of two f64 vectors:dot(a,b) / (|a| * |b|), and 0.0 when either vector has zero magnitude, asvec_cosine_f32answers. Panics when the lengths differ.- VecDistance
F32 vec_distance_f32(metric, a, b)— the distance between two f32 vectors as a dataset’s ground truth records it, accumulated in f64. Smaller is closer under every metric:- VecDistance
F64 vec_distance_f64(metric, a, b)— the distance between two f64 vectors as a dataset’s ground truth records it, under the metrics and conventions ofvec_distance_f32.- VecDot
F32 vec_dot_f32(a, b)— dot product of two f32 vectors, widened to f64 on the output wire. Panics when the lengths differ.- VecDot
F64 vec_dot_f64(a, b)— dot product of two f64 vectors. Panics when the lengths differ.- VecL2
F32 vec_l2_f32(a, b)— Euclidean (L2) distance between two f32 vectors. Panics when the lengths differ.- VecL2
F64 vec_l2_f64(a, b)— Euclidean (L2) distance between two f64 vectors. Panics when the lengths differ.- VecNorm
F32 vec_norm_f32(a)— scale an f32 vector to unit L2 magnitude. A zero vector passes through unchanged (there is no direction to normalize onto, and emitting NaNs would poison downstream distance math silently).- VecNorm
F64 vec_norm_f64(a)— scale an f64 vector to unit L2 magnitude, a zero vector passing through unchanged asvec_norm_f32passes it.- VecScale
F32 vec_scale_f32(a, k)— multiply every element of an f32 vector by scalark(applied at f32 precision).- VecScale
F64 vec_scale_f64(a, k)— multiply every element of an f64 vector by scalark.- Xxhash3
Vec xxhash3_vec(seed, dim)— deterministic synthetic f32 vector using xxHash3.
Functions§
- add_f32
a + belement-wise, as a new vector.- add_
f32_ into a + belement-wise intoout, which is cleared first.- check_
lens - Panics with both lengths named when two operands differ in length.
- cosine_
f32 - The cosine similarity of
vec_cosine. - dot_f32
- The dot product, through the SIMD kernel where the host has one.
- dot_
scalar - The scalar dot product: the reference the SIMD kernel is checked against.
- hash_
vec_ into - The vector of
hash_vecintoout, which is cleared first. - l2sq_
f32 - The squared L2 distance, through the SIMD kernel where the host has one.
- l2sq_
scalar - The scalar squared L2 distance: the reference the SIMD kernel is checked against.
- lid_
mle_ of - The estimate of
lid_mle. - norm_
f32_ into ascaled to unit L2 magnitude intoout;aitself when its magnitude is zero.- scale_
f32 a * kelement-wise, as a new vector.- scale_
f32_ into a * kelement-wise intoout, which is cleared first.- xxhash3_
vec_ into - The vector of
xxhash3_vecintoout, which is cleared first.