pub struct StridedTensor<T: Clone + Default + Copy + 'static> {
pub underlying_data: Array2<T>,
pub inner_dim: usize,
pub element_lengths: Array1<i64>,
pub max_element_len: usize,
pub precomputed_strides: Vec<usize>,
pub cumulative_lengths: Array1<i64>,
}Expand description
A data structure for efficient batch lookups on tensors of varying lengths.
StridedTensor stores a collection of variable-length sequences as a single,
contiguous array with padding. It precomputes several views with different
strides to optimize retrieval of sequences with common lengths.
Fields§
§underlying_data: Array2<T>The flattened, contiguous data containing all sequences with padding
inner_dim: usizeThe shape of each individual element within the data (e.g., embedding dim)
element_lengths: Array1<i64>Length of each element sequence
max_element_len: usizeMaximum length found among all sequences
precomputed_strides: Vec<usize>Sorted vector of strides for precomputed views
cumulative_lengths: Array1<i64>Cumulative sum of element_lengths for offset calculation
Implementations§
Source§impl<T: Clone + Default + Copy + 'static> StridedTensor<T>
impl<T: Clone + Default + Copy + 'static> StridedTensor<T>
Source§impl StridedTensor<i64>
impl StridedTensor<i64>
Source§impl StridedTensor<u8>
impl StridedTensor<u8>
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for StridedTensor<T>
impl<T> RefUnwindSafe for StridedTensor<T>where
T: RefUnwindSafe,
impl<T> Send for StridedTensor<T>where
T: Send,
impl<T> Sync for StridedTensor<T>where
T: Sync,
impl<T> Unpin for StridedTensor<T>
impl<T> UnwindSafe for StridedTensor<T>where
T: RefUnwindSafe,
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> 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