pub struct SparseVector { /* private fields */ }Expand description
Data type for sparse vector.
Implementations§
Source§impl SparseVector
impl SparseVector
Sourcepub fn new(
dimensions: usize,
indices: Vec<usize>,
values: Vec<f32>,
) -> Result<Self>
pub fn new( dimensions: usize, indices: Vec<usize>, values: Vec<f32>, ) -> Result<Self>
Creates a new value.
Sourcepub fn dimensions(&self) -> usize
pub fn dimensions(&self) -> usize
Returns dimensions.
Sourcepub fn canonicalized(&self) -> Result<Self>
pub fn canonicalized(&self) -> Result<Self>
Returns canonicalized.
Sourcepub fn cosine_similarity(&self, other: &Self) -> Result<f32>
pub fn cosine_similarity(&self, other: &Self) -> Result<f32>
Returns cosine similarity.
Sourcepub fn add(&self, other: &Self) -> Result<Self>
pub fn add(&self, other: &Self) -> Result<Self>
Adds two sparse vectors with matching dimensions.
Sourcepub fn hadamard(&self, other: &Self) -> Result<Self>
pub fn hadamard(&self, other: &Self) -> Result<Self>
Returns the sparse Hadamard product, keeping only overlapping indices.
Sourcepub fn prune_abs_below(&self, threshold: f32) -> Result<Self>
pub fn prune_abs_below(&self, threshold: f32) -> Result<Self>
Removes entries whose absolute value is below a finite non-negative threshold.
Sourcepub fn top_k_by_abs(&self, k: usize) -> Result<Vec<(usize, f32)>>
pub fn top_k_by_abs(&self, k: usize) -> Result<Vec<(usize, f32)>>
Returns the top k entries sorted by descending absolute value, then index.
Sourcepub fn normalize_l2(&self) -> Result<Self>
pub fn normalize_l2(&self) -> Result<Self>
Returns normalize l2.
Sourcepub fn from_dense(values: &[f32]) -> Result<Self>
pub fn from_dense(values: &[f32]) -> Result<Self>
Builds this value from dense.
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 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 ==.impl StructuralPartialEq for SparseVector
Source§impl TryFrom<&DenseVector> for SparseVector
impl TryFrom<&DenseVector> for SparseVector
Source§type Error = DetectError
type Error = DetectError
The type returned in the event of a conversion error.
Source§fn try_from(value: &DenseVector) -> Result<Self>
fn try_from(value: &DenseVector) -> Result<Self>
Performs the conversion.
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