pub struct SparseVec {
pub indices: Vec<usize>,
pub values: Vec<f64>,
pub len: usize,
}Expand description
疎ベクトル(インデックス・値のペアリスト、インデックスで昇順ソート済み)
ゼロでない要素のみをインデックスと値のペアで保持する。
indices は常に昇順にソートされており、二分探索による O(log n) アクセスが可能。
ゼロ近傍の値(絶対値が ZERO_TOL 以下)は自動的に除去される。
Fields§
§indices: Vec<usize>§values: Vec<f64>§len: usizeImplementations§
Source§impl SparseVec
impl SparseVec
Sourcepub fn from_dense(dense: &[f64]) -> Self
pub fn from_dense(dense: &[f64]) -> Self
Creates a SparseVec from a dense slice, dropping entries with |v| ≤ ZERO_TOL.
pub fn to_dense(&self) -> Vec<f64>
Sourcepub fn to_dense_into(&self, buf: &mut [f64])
pub fn to_dense_into(&self, buf: &mut [f64])
Writes to a pre-allocated buffer (zero-fills first). Avoids heap allocation in hot loops.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for SparseVec
impl RefUnwindSafe for SparseVec
impl Send for SparseVec
impl Sync for SparseVec
impl Unpin for SparseVec
impl UnsafeUnpin for SparseVec
impl UnwindSafe for SparseVec
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T, U> Imply<T> for U
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>
Converts
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>
Converts
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