nirs4all.utils.memory module
Memory estimation and RSS tracking utilities.
Provides fast, numpy-first memory estimation for datasets and cache entries, plus process RSS tracking via /proc/self/statm (Linux) or psutil (macOS/Windows).
Phase 1.4 – Cache Implementation Backlog
- nirs4all.utils.memory.estimate_cache_entry_bytes(entry: Any) int[source]
Estimate memory size of a cache entry.
Uses numpy nbytes for arrays and SpectroDatasets (O(1)). Falls back to sys.getsizeof for other types.
- Parameters:
entry – The object to measure. Can be a numpy array, a SpectroDataset, a tuple/list of arrays, or any other object.
- Returns:
Estimated byte count.
- nirs4all.utils.memory.estimate_dataset_bytes(dataset: SpectroDataset) int[source]
Estimate total memory footprint of a SpectroDataset.
Sums numpy nbytes across all feature sources and target processings. O(1) per array – reads shape and dtype only, no serialization.
- Parameters:
dataset – The SpectroDataset to measure.
- Returns:
Estimated byte count (features + targets).