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() -> HVec10240
pub fn random() -> HVec10240
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) -> HVec10240
pub fn new_seeded(seed: u64) -> HVec10240
Create a deterministic random hypervector from a seed.
Uses rand::rngs::StdRng for reproducibility across runs.
Sourcepub fn bundle(vectors: &[HVec10240]) -> Result<HVec10240, MemoryError>
pub fn bundle(vectors: &[HVec10240]) -> Result<HVec10240, MemoryError>
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: &HVec10240) -> f32
pub fn cosine_similarity(&self, other: &HVec10240) -> f32
Cosine similarity between two hypervectors.
Calculated as 1.0 - (HammingDistance / 5120.0) for 10240-bit vectors.
Sourcepub fn hamming_distance(&self, other: &HVec10240) -> u32
pub fn hamming_distance(&self, other: &HVec10240) -> 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) -> HVec10240
pub fn permute(&self, shift: usize) -> HVec10240
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<HVec10240, MemoryError>
pub fn from_bytes(bytes: &[u8]) -> Result<HVec10240, MemoryError>
Deserialize from bytes
Trait Implementations§
impl Copy for HVec10240
Source§impl<'de> Deserialize<'de> for HVec10240
impl<'de> Deserialize<'de> for HVec10240
Source§fn deserialize<D>(
deserializer: D,
) -> Result<HVec10240, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<HVec10240, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
impl Eq for HVec10240
Source§impl Hypervector for HVec10240
impl Hypervector for HVec10240
const DIMENSION: usize = 10240
const FORMAT_NAME: &'static str = "f32"
fn zero() -> HVec10240
fn random() -> HVec10240
fn new_seeded(seed: u64) -> HVec10240
fn bundle(vectors: &[&HVec10240]) -> Result<HVec10240, MemoryError>
fn bind(&self, other: &HVec10240) -> HVec10240
fn cosine_similarity(&self, other: &HVec10240) -> f32
fn hamming_distance(&self, other: &HVec10240) -> u32
fn permute(&self, shift: usize) -> HVec10240
fn to_bytes(&self) -> Vec<u8> ⓘ
fn from_bytes(bytes: &[u8]) -> Result<HVec10240, MemoryError>
Source§impl Serialize for HVec10240
impl Serialize for HVec10240
Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
impl StructuralPartialEq for HVec10240
Auto Trait Implementations§
impl Freeze for HVec10240
impl RefUnwindSafe for HVec10240
impl Send for HVec10240
impl Sync for HVec10240
impl Unpin for HVec10240
impl UnsafeUnpin for HVec10240
impl UnwindSafe for HVec10240
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request