pub struct Scratchpad { /* private fields */ }Expand description
A pre-allocated scratch buffer for KV-cache. Allows appending new
key/value vectors without re-allocation, up to a fixed max_seq_len.
Layout: [max_seq_len, dim] with a current_len cursor.
All memory is allocated once at construction; append only copies
new data into existing storage (zero GC pressure per token).
Implementations§
Source§impl Scratchpad
impl Scratchpad
Sourcepub fn new(max_seq_len: usize, dim: usize) -> Self
pub fn new(max_seq_len: usize, dim: usize) -> Self
Create a new scratchpad pre-allocated for max_seq_len tokens of
dimension dim. Zero-fills all storage upfront.
Sourcepub fn append(&mut self, token_vec: &[f64]) -> Result<(), RuntimeError>
pub fn append(&mut self, token_vec: &[f64]) -> Result<(), RuntimeError>
Append a single token vector [dim] to the cache.
Returns an error if the cache is full. Zero allocation.
Sourcepub fn append_tensor(&mut self, t: &Tensor) -> Result<(), RuntimeError>
pub fn append_tensor(&mut self, t: &Tensor) -> Result<(), RuntimeError>
Append a batch of token vectors from a tensor of shape [n, dim].
Zero allocation — writes directly into pre-allocated storage.
Trait Implementations§
Source§impl Clone for Scratchpad
impl Clone for Scratchpad
Source§fn clone(&self) -> Scratchpad
fn clone(&self) -> Scratchpad
Returns a duplicate of the value. Read more
1.0.0 · 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 Scratchpad
impl Debug for Scratchpad
Auto Trait Implementations§
impl Freeze for Scratchpad
impl !RefUnwindSafe for Scratchpad
impl !Send for Scratchpad
impl !Sync for Scratchpad
impl Unpin for Scratchpad
impl UnsafeUnpin for Scratchpad
impl !UnwindSafe for Scratchpad
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