nemos.batching.ArrayDataLoader#
- class nemos.batching.ArrayDataLoader(*arrays, batch_size, shuffle='full', seed=None)[source]#
Bases:
_BaseArrayDataLoaderDataLoader for in-memory arrays.
Arrays are eagerly converted to JAX arrays at construction. This loader is re-iterable: each call to
__iter__()returns a fresh iterator.Examples
>>> import jax.numpy as jnp >>> from nemos.batching import ArrayDataLoader >>> X = jnp.ones((100, 5)) >>> y = jnp.ones((100,)) >>> loader = ArrayDataLoader(X, y, batch_size=32, shuffle="full") >>> for X_batch, y_batch in loader: ... pass # Train on batch
Attributes
Number of samples in each batch.
Total number of samples in the dataset.
- __init__(*arrays, batch_size, shuffle='full', seed=None)[source]#
Initialize an in-memory array data loader.
- Parameters:
*arrays (
ArrayLike) – Input and output arrays (any number), each an array of shape (n_samples, n_features) or (n_samples, ).batch_size (
int) – Number of samples per batch.shuffle (
str) – Shuffle strategy: one of"none","chunk_order","chunk_and_samples", or"full". Default is"full".seed (
int|None) – Random seed for shuffling. Default is None.
Methods
__init__(*arrays, batch_size[, shuffle, seed])Initialize an in-memory array data loader.
Return the first batch containing at least one valid sample.
- __iter__()#
Return a fresh iterator over batches, dispatching on the shuffle strategy.
- sample_batch()#
Return the first batch containing at least one valid sample.
Scans contiguous batches in sequential order (ignoring shuffle) and returns the first one with a sample that is finite (no NaN/Inf) across every array. This skips leading all-invalid regions, such as the NaN warmup of convolutional-basis features, while loading only as much data as needed.
Validity uses the same
get_valid_multitreenotion asvalidate_inputsand_preprocess_inputs, so an accepted batch is exactly one that passes validation and stays non-empty after NaN-dropping.