Skip to content

tenzr::data::BatchSampler

Groups indices produced by a Sampler into fixed-size batches.

#include <sampler.h>

Public Functions

Name
BatchSampler(std::shared_ptr< Sampler > sampler, size_t batch_size, bool drop_last =false)
std::vector< std::vector< size_t > > Batches() const
size_t NumBatches() const
size_t BatchSize() const
bool DropLast() const

Public Functions Documentation

function BatchSampler

BatchSampler(
    std::shared_ptr< Sampler > sampler,
    size_t batch_size,
    bool drop_last =false
)

Parameters:

  • sampler Underlying index sampler; must not be null.
  • batch_size Batch size, which must be positive.
  • drop_last When true, discard a trailing partial batch.

Group another sampler's indices into fixed-size batches.

function Batches

std::vector< std::vector< size_t > > Batches() const

Return:

  • Batched indices, each inner vector one batch.
  • One index vector per batch.

Materialize the sampler's indices as a list of batches.

function NumBatches

size_t NumBatches() const

Return:

  • Number of batches produced.
  • Batch count, dropping the remainder when drop_last is set.

Number of batches the underlying sampler will produce.

function BatchSize

inline size_t BatchSize() const

Return: Configured batch size.

function DropLast

inline bool DropLast() const

Return: true when the final partial batch is dropped.