pub struct LRUPolicy { /* private fields */ }Expand description
A least-recently-used EvictionPolicy
Tracks access order in an intrusive doubly linked list and, once the cache is full, evicts the entry that has gone longest without a hit.
§Examples
use candela::skeleton::{DynamicSkeleton, SkeletonSlot};
use candela::{Layout, Tensor};
// LRUPolicy is DynamicSkeleton's default; a size-1 cache drops the older shape.
let sk: DynamicSkeleton<f32> = DynamicSkeleton::new(1, Box::new(|inputs: &[Layout]| {
let a = SkeletonSlot::new(inputs[0].clone());
(&a * 2.0).into_skeleton(&[a]).unwrap()
}));
let a = Tensor::from_scalar(3.0, &[4]);
sk.run(&[&a])?;
sk.run(&[&Tensor::from_scalar(3.0, &[8])])?; // evicts the [4] entry
assert!(!sk.contains_key(&[&a]));Trait Implementations§
Auto Trait Implementations§
impl Freeze for LRUPolicy
impl RefUnwindSafe for LRUPolicy
impl Send for LRUPolicy
impl Sync for LRUPolicy
impl Unpin for LRUPolicy
impl UnsafeUnpin for LRUPolicy
impl UnwindSafe for LRUPolicy
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