nemos.batching.ArrayDataLoader#

class nemos.batching.ArrayDataLoader(*arrays, batch_size, shuffle='full', seed=None)[source]#

Bases: _BaseArrayDataLoader

DataLoader 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

batch_size

Number of samples in each batch.

n_samples

Total number of samples in the dataset.

Parameters:
  • arrays (ArrayLike)

  • batch_size (int)

  • shuffle (str)

  • seed (int | None)

__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.

sample_batch()

Return the first batch containing at least one valid sample.

__iter__()#

Return a fresh iterator over batches, dispatching on the shuffle strategy.

Return type:

Iterator[tuple[Array, ...]]

property batch_size: int#

Number of samples in each batch.

property n_samples: int#

Total number of samples in the dataset.

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_multitree notion as validate_inputs and _preprocess_inputs, so an accepted batch is exactly one that passes validation and stays non-empty after NaN-dropping.

Return type:

tuple[Array, ...]

Returns:

The first batch with a valid sample. If no batch has one (the whole dataset is invalid), the first batch is returned so that downstream validation raises the canonical “all samples invalid” error.