MemoryMappedChunkIter

Trait MemoryMappedChunkIter 

Source
pub trait MemoryMappedChunkIter<A: Clone + Copy + 'static + Send + Sync> {
    // Required method
    fn chunks(&self, strategy: ChunkingStrategy) -> ChunkIter<'_, A> ;
}
Expand description

Extension trait for MemoryMappedArray to enable chunked iteration.

This trait extends MemoryMappedArray with the ability to iterate over chunks of the array, which provides a convenient way to process large arrays sequentially in smaller, manageable pieces.

Required Methods§

Source

fn chunks(&self, strategy: ChunkingStrategy) -> ChunkIter<'_, A>

Create an iterator over chunks of the array (for 1D arrays only).

This method returns an iterator that yields chunks of the array as Array1<A> values, making it easy to process the array in smaller pieces.

§Arguments
  • strategy - The chunking strategy to determine chunk sizes
§Returns

An iterator that yields Array1<A> chunks of the memory-mapped array

§Examples
use scirs2_core::memory_efficient::{create_mmap, AccessMode, ChunkingStrategy, MemoryMappedChunkIter};
use scirs2_core::ndarray::Array1;

// Create a memory-mapped array
let data = Array1::<f64>::linspace(0., 99., 100);
let file_path = "example.bin";  // In practice, use a proper temporary path
let mmap = create_mmap(&data, file_path.as_ref(), AccessMode::Write, 0).expect("Operation failed");

// Create a chunk iterator with chunks of size 25
let mut iter = mmap.chunks(ChunkingStrategy::Fixed(25));

// Get the first chunk (elements 0-24)
let chunk1 = iter.next().expect("Operation failed");
assert_eq!(chunk1.len(), 25);
assert_eq!(chunk1[0], 0.0);
assert_eq!(chunk1[24], 24.0);

Implementors§