Class ParallelBatchLoaderExtensions
Provides extension methods for parallel batch loading.
public static class ParallelBatchLoaderExtensions
- Inheritance
-
ParallelBatchLoaderExtensions
- Inherited Members
Methods
WithParallelLoading<TBatch>(IBatchIterable<TBatch>, Func<int[], TBatch>, int, int?, int?)
Wraps a batch iterable with parallel loading support.
public static ParallelBatchLoader<TBatch> WithParallelLoading<TBatch>(this IBatchIterable<TBatch> source, Func<int[], TBatch> batchFactory, int batchSize, int? numWorkers = null, int? prefetchCount = null)
Parameters
sourceIBatchIterable<TBatch>The source batch iterable.
batchFactoryFunc<int[], TBatch>Function to create a batch from an array of sample indices. The factory receives all indices for a single batch and should aggregate them.
batchSizeintThe batch size (number of samples per batch).
numWorkersint?Number of parallel workers. Default is processor count.
prefetchCountint?Number of batches to prefetch. Default is 2 * numWorkers.
Returns
- ParallelBatchLoader<TBatch>
A parallel batch loader configured with the specified parameters.
Type Parameters
TBatchThe batch type.
Examples
var parallelLoader = dataLoader.WithParallelLoading(
batchFactory: indices => {
var xBatch = new Matrix<float>(indices.Length, numFeatures);
var yBatch = new Vector<float>(indices.Length);
for (int i = 0; i < indices.Length; i++) {
int idx = indices[i];
// Copy sample data at idx to position i in batch
for (int j = 0; j < numFeatures; j++)
xBatch[i, j] = fullDataset.X[idx, j];
yBatch[i] = fullDataset.Y[idx];
}
return (xBatch, yBatch);
},
batchSize: 32,
numWorkers: 4
);