pub struct TransitionBuffer<B: Backend, SB: SliceAccess<B>, AB: SliceAccess<B>> { /* private fields */ }Expand description
A tensor-backed circular buffer for transitions.
Uses SliceAccess to store state and action batches in contiguous
tensor storage, enabling efficient random sampling via select.
The buffer lazily initializes its storage on the first push call.
Implementations§
Source§impl<B: Backend, SB: SliceAccess<B>, AB: SliceAccess<B>> TransitionBuffer<B, SB, AB>
impl<B: Backend, SB: SliceAccess<B>, AB: SliceAccess<B>> TransitionBuffer<B, SB, AB>
Sourcepub fn new(capacity: usize, device: &B::Device) -> Self
pub fn new(capacity: usize, device: &B::Device) -> Self
Creates a new buffer. Storage is lazily allocated on the first push.
Sourcepub fn push(
&mut self,
state: SB,
next_state: SB,
action: AB,
reward: f32,
done: bool,
)
pub fn push( &mut self, state: SB, next_state: SB, action: AB, reward: f32, done: bool, )
Add a transition, overwriting the oldest if full.
Sourcepub fn sample(&self, batch_size: usize) -> TransitionBatch<B, SB, AB>
pub fn sample(&self, batch_size: usize) -> TransitionBatch<B, SB, AB>
Sample a random batch of transitions.
Auto Trait Implementations§
impl<B, SB, AB> Freeze for TransitionBuffer<B, SB, AB>
impl<B, SB, AB> RefUnwindSafe for TransitionBuffer<B, SB, AB>where
<B as Backend>::Device: RefUnwindSafe,
SB: RefUnwindSafe,
AB: RefUnwindSafe,
<B as Backend>::FloatTensorPrimitive: RefUnwindSafe,
<B as Backend>::QuantizedTensorPrimitive: RefUnwindSafe,
impl<B, SB, AB> Send for TransitionBuffer<B, SB, AB>
impl<B, SB, AB> Sync for TransitionBuffer<B, SB, AB>
impl<B, SB, AB> Unpin for TransitionBuffer<B, SB, AB>
impl<B, SB, AB> UnsafeUnpin for TransitionBuffer<B, SB, AB>where
<B as Backend>::Device: UnsafeUnpin,
SB: UnsafeUnpin,
AB: UnsafeUnpin,
<B as Backend>::FloatTensorPrimitive: UnsafeUnpin,
<B as Backend>::QuantizedTensorPrimitive: UnsafeUnpin,
impl<B, SB, AB> UnwindSafe for TransitionBuffer<B, SB, AB>where
<B as Backend>::Device: UnwindSafe,
SB: UnwindSafe,
AB: UnwindSafe,
<B as Backend>::FloatTensorPrimitive: UnwindSafe,
<B as Backend>::QuantizedTensorPrimitive: UnwindSafe,
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