pub struct VsaOps { /* private fields */ }Expand description
VSA operations handler.
Provides ternary VSA operations with automatic CPU/GPU dispatch.
Implementations§
Source§impl VsaOps
impl VsaOps
Sourcepub fn random(&self, dim: usize, seed: u32) -> Result<PackedTritVec, VsaError>
pub fn random(&self, dim: usize, seed: u32) -> Result<PackedTritVec, VsaError>
Generate a random ternary vector.
§Arguments
dim- Vector dimensionseed- Random seed for reproducibility
Sourcepub fn bind(
&self,
a: &PackedTritVec,
b: &PackedTritVec,
) -> Result<PackedTritVec, VsaError>
pub fn bind( &self, a: &PackedTritVec, b: &PackedTritVec, ) -> Result<PackedTritVec, VsaError>
Bind two ternary vectors (association).
Bind is the composition operation, creating associations between vectors. It is commutative and associative.
Sourcepub fn unbind(
&self,
bound: &PackedTritVec,
key: &PackedTritVec,
) -> Result<PackedTritVec, VsaError>
pub fn unbind( &self, bound: &PackedTritVec, key: &PackedTritVec, ) -> Result<PackedTritVec, VsaError>
Unbind two ternary vectors (inverse association).
If bound = bind(a, b), then unbind(bound, b) recovers a.
Sourcepub fn bundle(
&self,
vectors: &[PackedTritVec],
) -> Result<PackedTritVec, VsaError>
pub fn bundle( &self, vectors: &[PackedTritVec], ) -> Result<PackedTritVec, VsaError>
Bundle multiple vectors (superposition).
Combines vectors via majority voting at each dimension. The result is similar to all input vectors.
Sourcepub fn cosine_similarity(
&self,
a: &PackedTritVec,
b: &PackedTritVec,
) -> Result<f32, VsaError>
pub fn cosine_similarity( &self, a: &PackedTritVec, b: &PackedTritVec, ) -> Result<f32, VsaError>
Compute cosine similarity between two vectors.
Returns a value in [-1, 1].
Sourcepub fn dot(&self, a: &PackedTritVec, b: &PackedTritVec) -> Result<i32, VsaError>
pub fn dot(&self, a: &PackedTritVec, b: &PackedTritVec) -> Result<i32, VsaError>
Compute dot product between two vectors.
Sourcepub fn hamming_distance(
&self,
a: &PackedTritVec,
b: &PackedTritVec,
) -> Result<usize, VsaError>
pub fn hamming_distance( &self, a: &PackedTritVec, b: &PackedTritVec, ) -> Result<usize, VsaError>
Compute Hamming distance between two vectors.
Returns the number of positions where the vectors differ.
Sourcepub fn from_i8(&self, values: &[i8]) -> Result<PackedTritVec, VsaError>
pub fn from_i8(&self, values: &[i8]) -> Result<PackedTritVec, VsaError>
Convert i8 slice to PackedTritVec.
Sourcepub fn to_i8(&self, packed: &PackedTritVec) -> Vec<i8>
pub fn to_i8(&self, packed: &PackedTritVec) -> Vec<i8>
Convert PackedTritVec to i8 Vec.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for VsaOps
impl RefUnwindSafe for VsaOps
impl Send for VsaOps
impl Sync for VsaOps
impl Unpin for VsaOps
impl UnwindSafe for VsaOps
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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 more