Crate vecstasy

Crate vecstasy 

Source
Expand description

§vecstasy

vecstasy is a minimal, high-performance Rust library for vector arithmetic. It provides a generic VecLike trait for common vector operations and two primary implementations:

  • SIMD-backed linear algebra ([f32] and &[f32]): Fast L2 distance, dot product, and normalization via SIMD. Should natively work on all platforms supported by LLVM, even the ones with no SIMD support (it falls back to sequential evaluation in that case).
  • HashVec wrapper: Stable hashing and equality for &[f32] slices based on IEEE‑754 raw bits, distinguishing +0/−0 and NaNs for deterministic behavior.

§Features

  • VecLike trait: Defines l2_dist_squared, dot, and normalized methods.
  • Optimized implementations: All implementations exploit CPU-based SIMD whenever available
  • Bit-wise hashing: HashVec ensures identical bit-pattern vectors hash and compare consistently.

§Usage

Add to your Cargo.toml:

[dependencies]
vecstasy = "0.1"

Then import and use:

use vecstasy::VecLike;
use vecstasy::HashVec;

let data: &[f32] = &[0.0; 8];  // length should be multiple of the SIMD lane count, which is 8 by default
let hv = HashVec::from(data);
let normed = hv.normalized();

§License

MIT, see license file

Structs§

HashVec
A wrapper type for &[f32] slices that provides stable hashing and equality based on the IEEE‑754 bit patterns.

Constants§

SIMD_LANECOUNT

Traits§

VecLike
A generic vector-like type supporting common vector operations.

Type Aliases§

SimdUnit