processChunked<R> method
Processes the array in chunks along an axis.
This method divides the array along the specified axis into chunks, processes each chunk with the processor function, and combines results with the combiner function.
Example:
var arr = NDArray([
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
]);
// Sum each row chunk
var result = await arr.processChunked<num>(
axis: 0,
chunkSize: 2,
processor: (chunk) => chunk.sum(),
combiner: (results) => results.reduce((a, b) => a + b),
);
print(result); // 45
Implementation
Future<R> processChunked<R>({
required int axis,
required int chunkSize,
required dynamic Function(NDArray chunk) processor,
required R Function(List<dynamic> results) combiner,
}) async {
final results = <dynamic>[];
await for (var chunk in streamAlongAxis(axis, chunkSize: chunkSize)) {
results.add(processor(chunk));
}
return combiner(results);
}