pub struct HVec10240 {
pub data: [u128; 80],
}Expand description
10240-bit hypervector (80 x 128-bit words)
Fields§
§data: [u128; 80]Implementations§
Source§impl HVec10240
impl HVec10240
pub const DIMENSION: usize = 10240
pub const WORDS: usize = 80
Sourcepub fn random() -> Self
pub fn random() -> Self
Create a random hypervector (each bit has 50% probability)
Performance Optimization: Uses rng.fill() for bulk data generation, reducing
per-word overhead and allowing the RNG to use vectorized memory-filling paths.
Expected speedup: ~15% for random generation.
Sourcepub fn new_seeded(seed: u64) -> Self
pub fn new_seeded(seed: u64) -> Self
Create a deterministic random hypervector from a seed.
Uses rand::rngs::StdRng for reproducibility across runs.
Sourcepub fn bundle(vectors: &[Self]) -> Result<Self>
pub fn bundle(vectors: &[Self]) -> Result<Self>
Bundle (sum) multiple hypervectors using bit-sliced addition.
This implementation is optimized for performance and memory efficiency:
- It uses word-parallel bit-sliced addition to count set bits across vectors.
- It eliminates the large heap-allocated counter array and bit-by-bit loops.
- It parallelizes over hypervector words rather than over vectors to minimize memory traffic and synchronization overhead.
Sourcepub fn cosine_similarity(&self, other: &Self) -> f32
pub fn cosine_similarity(&self, other: &Self) -> f32
Cosine similarity between two hypervectors.
Calculated as 1.0 - (HammingDistance / 5120.0) for 10240-bit vectors.
Sourcepub fn hamming_distance(&self, other: &Self) -> u32
pub fn hamming_distance(&self, other: &Self) -> u32
Hamming distance
Dispatches to optimized SIMD paths based on platform:
- x86_64: AVX2 (runtime detection) or unrolled scalar GPR popcount fallback
- aarch64: NEON
- Other: unrolled scalar GPR popcount
Sourcepub fn permute(&self, shift: usize) -> Self
pub fn permute(&self, shift: usize) -> Self
Permute the hypervector (cyclic rotation)
Optimized implementation that eliminates modulo operations and branches from the hot loop by splitting the rotation into two contiguous segments.
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self>
pub fn from_bytes(bytes: &[u8]) -> Result<Self>
Deserialize from bytes