
SimdVectorOps
- Namespace
- Rowles.LeanLucene.Search.Simd
- Assembly
- Rowles.LeanLucene.dll
SIMD vector primitives used by HNSW graph operations and exact rerank. Built around System.Numerics.Vector`1, which the .NET JIT lowers to AVX2 or AVX-512 instructions automatically on capable hardware.
public static class SimdVectorOps
Remarks
All methods assume the inputs have equal length and treat empty inputs as a similarity of zero.
Methods
CosineSimilarity(ReadOnlySpan<float>, ReadOnlySpan<float>)
Computes cosine similarity between two vectors. Returns zero for empty or length-mismatched inputs; never throws.
DotProduct(ReadOnlySpan<float>, ReadOnlySpan<float>)
Computes the dot product of two equal-length vectors. For pre-normalised vectors this is equivalent to cosine similarity at roughly two thirds of the cost.
Normalise(ReadOnlySpan<float>)
Allocates a normalised copy of the input vector. Throws when the input has zero norm.
NormaliseInPlace(Span<float>)
L2-normalises a vector in place. Returns false when the input has zero norm (cosine is undefined in that case); the buffer is left untouched.
SquaredNorm(ReadOnlySpan<float>)
Computes the squared L2 norm of a vector (sum of squared elements).