Module utils

Module utils 

Source
Expand description

Utility functions for numerical operations

Constants§

EPS
Small epsilon for numerical stability
EPS_F32
Small epsilon for f32
LOG_MAX
Log of maximum positive f64
LOG_MIN
Log of minimum positive f64

Functions§

argsort
Argsort: returns indices that would sort the array
clamp_log
Clamp a log value to prevent overflow/underflow
compute_cdf
Compute cumulative distribution function values
cosine_similarity
Cosine similarity between two vectors
dot
Dot product of two vectors
euclidean_distance
Euclidean distance
jensen_shannon
Jensen-Shannon divergence
kl_divergence
KL divergence: D_KL(P || Q) = sum(P * log(P/Q))
log_softmax
Stable softmax in log domain
log_sum_exp
Stable log-sum-exp: log(sum(exp(x_i)))
norm
Euclidean norm of a vector
normalize
Normalize a vector to unit length
normalize_mut
Normalize vector in place
quantile_sorted
Quantile of sorted data (0.0 to 1.0)
safe_exp
Safe exp that clamps input to prevent overflow
safe_ln
Safe log that returns LOG_MIN for non-positive values
softmax
Standard softmax with numerical stability
sort_with_indices
Sort with indices: returns (sorted_data, original_indices)
squared_euclidean
Squared Euclidean distance
symmetric_kl
Symmetric KL divergence: (D_KL(P||Q) + D_KL(Q||P)) / 2
weighted_quantile
Weighted quantile