annbatch.samplers.SequentialSampler#

class annbatch.samplers.SequentialSampler(chunk_size, preload_nchunks, batch_size, *, drop_last=False, mask=None)#

Ordered chunk-based sampler for batched data access.

Chunks are emitted in sequential order and every observation in the range is visited exactly once. This sampler does not support multiple data-loading workers. This sampler is usually used for evaluation or inference.

See RandomSampler for a shuffled alternative.

Parameters:
batch_size int

Number of observations per batch.

chunk_size int

Size of each chunk i.e. the range of each chunk yielded.

mask slice | None (default: None)

A slice defining the observation range to sample from (start:stop).

preload_nchunks int

Number of chunks to load per iteration.

drop_last bool (default: False)

Whether to drop the last incomplete batch.

Attributes table#

batch_size

The batch size for data loading.

mask

The observation range this sampler operates on.

rng

The random number generator used by this sampler.

shuffle

Whether data is shuffled.

Methods table#

n_iters(n_obs)

Return the number of batches.

sample(n_obs)

Sample load requests given the total number of observations.

validate(n_obs)

Validate the sampler configuration against the loader's n_obs.

Attributes#

SequentialSampler.batch_size#
SequentialSampler.mask#

The observation range this sampler operates on.

SequentialSampler.rng#

The random number generator used by this sampler.

SequentialSampler.shuffle#

Methods#

SequentialSampler.n_iters(n_obs)#

Return the number of batches.

Parameters:
n_obs int

The total number of observations available.

Return type:

int

Returns:

int The total number of batches this sampler will produce.

SequentialSampler.sample(n_obs)#

Sample load requests given the total number of observations.

Base implemention simply calls validate() and then yields via _sample().

Parameters:
n_obs int

The total number of observations available.

Yields:

LoadRequest – Load requests for batching data.

Return type:

Iterator[LoadRequest]

SequentialSampler.validate(n_obs)#

Validate the sampler configuration against the loader’s n_obs.

Parameters:
n_obs int

The total number of observations in the loader.

Raises:

ValueError – If the sampler configuration is invalid for the given n_obs.

Return type:

None