Skip to main content

DataProvider

Trait DataProvider 

Source
pub trait DataProvider: Send {
    // Required methods
    fn num_samples(&self) -> usize;
    fn num_features(&self) -> usize;
    fn get_batch(&self, indices: &[usize]) -> (Array2<f32>, Array1<f32>);

    // Provided method
    fn shuffle_indices(&self, rng_seed: u64) -> Vec<usize> { ... }
}
Expand description

Trait for data sources that provide batched (features, targets) pairs.

Implementors are responsible for indexing into their underlying storage and producing contiguous sub-arrays. The trait is Send so data providers can be shared across threads.

Required Methods§

Source

fn num_samples(&self) -> usize

Total number of samples in the dataset.

Source

fn num_features(&self) -> usize

Number of features per sample.

Source

fn get_batch(&self, indices: &[usize]) -> (Array2<f32>, Array1<f32>)

Return a mini-batch identified by the given sample indices.

Returns (features, targets) where features has shape [indices.len(), num_features()] and targets has length indices.len().

Provided Methods§

Source

fn shuffle_indices(&self, rng_seed: u64) -> Vec<usize>

Produce a permuted index vector using a simple LCG seeded by rng_seed.

This avoids pulling in rand while still providing reproducible shuffles.

Implementors§