pub struct SparseVector {
pub indices: Vec<u32>,
pub values: Vec<f32>,
}Expand description
A sparse vector: parallel indices and values. Indices are dimension ids
into a (possibly very large) sparse vocabulary; values are their weights.
Fields§
§indices: Vec<u32>Dimension ids. After SparseVector::normalized they are sorted and unique.
values: Vec<f32>Per-index weights, parallel to indices.
Implementations§
Source§impl SparseVector
impl SparseVector
Sourcepub fn validate(&self) -> Result<(), String>
pub fn validate(&self) -> Result<(), String>
Validate shape: equal-length, and no duplicate index after sorting.
Sourcepub fn normalized(&self) -> SparseVector
pub fn normalized(&self) -> SparseVector
Return a copy with indices sorted ascending (values kept parallel). The
canonical form the inverted index and dot assume.
Sourcepub fn dot(&self, other: &SparseVector) -> f32
pub fn dot(&self, other: &SparseVector) -> f32
Dot product with another sparse vector. Order-independent (builds a small
lookup over self), so callers need not pre-sort.
Trait Implementations§
Source§impl Clone for SparseVector
impl Clone for SparseVector
Source§fn clone(&self) -> SparseVector
fn clone(&self) -> SparseVector
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SparseVector
impl Debug for SparseVector
Source§impl<'de> Deserialize<'de> for SparseVector
impl<'de> Deserialize<'de> for SparseVector
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl PartialEq for SparseVector
impl PartialEq for SparseVector
Source§fn eq(&self, other: &SparseVector) -> bool
fn eq(&self, other: &SparseVector) -> bool
Tests for
self and other values to be equal, and is used by ==.Source§impl Serialize for SparseVector
impl Serialize for SparseVector
impl StructuralPartialEq for SparseVector
Auto Trait Implementations§
impl Freeze for SparseVector
impl RefUnwindSafe for SparseVector
impl Send for SparseVector
impl Sync for SparseVector
impl Unpin for SparseVector
impl UnsafeUnpin for SparseVector
impl UnwindSafe for SparseVector
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
Mutably borrows from an owned value. Read more