Trait BatchBase

Source
pub trait BatchBase {
    // Required methods
    fn new(capacity: usize) -> Self;
    fn push(&mut self, ix: usize, data: Self);
    fn sample(&self, ixs: &Vec<usize>) -> Self;
}
Expand description

A trait defining basic batch operations.

This trait provides fundamental operations for efficiently managing batches of observations and actions.

§Type Parameters

  • Self - The batch type, representing batches of observations or actions.

§Examples

struct TensorBatch {
    data: Vec<f32>,
    shape: Vec<usize>,
}

impl BatchBase for TensorBatch {
    fn new(capacity: usize) -> Self {
        Self {
            data: Vec::with_capacity(capacity),
            shape: vec![],
        }
    }

    fn push(&mut self, ix: usize, data: Self) {
        // Data addition logic
    }

    fn sample(&self, ixs: &Vec<usize>) -> Self {
        // Sampling logic
    }
}

Required Methods§

Source

fn new(capacity: usize) -> Self

Creates a new batch with the specified capacity.

§Arguments
  • capacity - Initial capacity of the batch
Source

fn push(&mut self, ix: usize, data: Self)

Adds data at the specified index.

§Arguments
  • ix - Index where data should be added
  • data - Data to be added
Source

fn sample(&self, ixs: &Vec<usize>) -> Self

Retrieves samples from the specified indices.

§Arguments
  • ixs - List of indices to sample from
§Returns

A new batch containing the sampled data

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§