Flexible tensor view allocator and cache for deep learning and scientific computing.
Mosaic is a lightweight, extensible Python library for allocating and caching non-overlapping, named regions (views or slices) within large or dynamically constructed tensors.
It is especially useful for deep learning, scientific computing, and any application requiring efficient management and lookup of structured tensor subspaces.
- Reserve and cache named slices: Create stable, named regions within tensors for models, optimizers, or data pipelines.
- Device-aware: Automatically keeps cached indices and slices on the desired device (CPU/GPU).
- Zero-copy views: Retrieve direct views into the underlying tensor without data duplication.
- Compatible with PyTorch and NumPy.
pip install tensor-mosaic
import torch
import tensor_mosaic as mosaic # Alias locally if you like
mosaic = mosaic.Mosaic()
mosaic.INPUTS = 16
mosaic.HIDDEN = 32
mosaic.OUTPUTS = 10
tensor = torch.randn(1, *mosaic.shape) # Reserve total width
inputs_view = mosaic.slice_view(tensor, "inputs")
outputs_view = mosaic["outputs"]
print("Inputs:", inputs_view)
print("Outputs:", outputs_view)