Skip to main content

Crate vecnorm_core

Crate vecnorm_core 

Source
Expand description

Pure-Rust core for vecnorm. Bulk f32 matrix operations:

  • l2_normalize / l2_normalize_copy — row-wise unit-length scaling. Rows whose norm is below EPS are left at zero rather than dividing by zero.
  • cosine_similarity — single pair on 1-D vectors. Returns 0 for any pair where either side has zero norm.
  • top_k_argmax / batch_top_k_argmax — partial-heap top-k that runs in O(n log k). Tied scores are broken by the original index ascending (deterministic).

Enums§

VecNormError
All errors surfaced by vecnorm-core.

Constants§

EPS
Tiny norm below which a row is considered all-zero and left unscaled.

Functions§

argmax
Single argmax: returns (index, score) of the largest element. Ties broken by ascending index. Errors on empty input.
batch_top_k_argmax
Batch top-k argmax over an (n_rows, n_cols) matrix. With parallel = true distributes rows across rayon’s pool.
cosine_distances
Cosine distance matrix between two (n_a, d) and (n_b, d) matrices. Returns an (n_a, n_b) matrix where out[i, j] is the cosine distance 1 - cos(a_i, b_j). Inputs are not modified; this normalizes copies internally so accuracy is preserved on un-normalized inputs.
cosine_similarity
Cosine similarity between two 1-D vectors. Returns 0 if either side is all-zero.
dot_product
Inner product (dot product) of two 1-D vectors. No normalization. Errors on dim mismatch.
l2_normalize
L2-normalize matrix in place, row by row. Rows with norm below EPS are zeroed out (i.e. left unchanged at all-zero) to avoid NaN.
l2_normalize_copy
L2-normalize a copy. Same semantics as l2_normalize.
top_k_argmax
Top-k argmax over a 1-D score vector. Returns (index, score) pairs in descending order. Ties broken by ascending index.

Type Aliases§

Result
Crate-wide result alias.