ReplayBuffer

Struct ReplayBuffer 

Source
pub struct ReplayBuffer { /* private fields */ }
Expand description

Fixed-capacity ring buffer with uniform random sampling.

Pre-allocates all arrays at construction for zero-allocation push. Oldest transitions are overwritten when capacity is reached.

Supports optional extra f32 columns (e.g. log-probs, value estimates) via ColumnHandle. When no extra columns are registered, there is zero overhead — no allocations and no branches in the hot push/sample path.

Implementations§

Source§

impl ReplayBuffer

Source

pub fn new(capacity: usize, obs_dim: usize, act_dim: usize) -> Self

Create a ring buffer with fixed capacity. All arrays are pre-allocated.

Source

pub fn register_column(&mut self, name: &str, dim: usize) -> ColumnHandle

Register an extra f32 column with the given name and dimensionality.

Returns a ColumnHandle for O(1) push/sample access. Must be called before any push() — the column is pre-allocated to match the buffer’s capacity.

Source

pub fn push_extra( &mut self, handle: ColumnHandle, values: &[f32], ) -> Result<(), RloxError>

Push extra column data for the most recently pushed transition.

Must be called after push() and before the next push(). The values slice length must match the column’s registered dim.

Source

pub fn obs_dim(&self) -> usize

Observation dimensionality.

Source

pub fn act_dim(&self) -> usize

Action dimensionality.

Source

pub fn len(&self) -> usize

Number of valid transitions currently stored.

Source

pub fn is_empty(&self) -> bool

Whether the buffer is empty.

Source

pub fn push_slices( &mut self, obs: &[f32], next_obs: &[f32], action: &[f32], reward: f32, terminated: bool, truncated: bool, ) -> Result<(), RloxError>

Push a transition from borrowed slices, avoiding intermediate allocation.

Source

pub fn push_batch( &mut self, obs_batch: &[f32], next_obs_batch: &[f32], actions_batch: &[f32], rewards: &[f32], terminated: &[bool], truncated: &[bool], ) -> Result<(), RloxError>

Push multiple transitions at once from flat arrays.

obs_batch shape: [n * obs_dim], next_obs_batch: same, actions_batch: [n * act_dim], others: [n].

Source

pub fn push(&mut self, record: ExperienceRecord) -> Result<(), RloxError>

Push a transition, overwriting the oldest if at capacity.

Prefer push_slices to avoid the intermediate Vec<f32> allocations inside ExperienceRecord.

Source

pub fn sample( &self, batch_size: usize, seed: u64, ) -> Result<SampledBatch, RloxError>

Sample a batch of transitions uniformly at random.

Uses ChaCha8Rng seeded with seed for deterministic cross-platform reproducibility. Returns owned SampledBatch.

If extra columns have been registered, their data is included in SampledBatch::extra.

Source

pub fn sample_into( &self, batch: &mut SampledBatch, batch_size: usize, seed: u64, ) -> Result<(), RloxError>

Sample into a pre-allocated batch, reusing its capacity.

Same as sample() but avoids allocation by reusing batch.

Source

pub fn extra_columns(&self) -> &ExtraColumns

Access the extra columns storage (for advanced use / testing).

Trait Implementations§

Source§

impl Debug for ReplayBuffer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V