SliceIndexMapper
General-purpose IndexMapper implementation for arbitrary slice patterns.
SliceIndexMapper handles coordinate transformation for any combination of slice types, providing a flexible foundation for tensor slicing operations. It implements the IndexMapper interface with support for NCHW memory layout and row-major storage.
Algorithm Overview
The mapper works by:
Dimension Mapping: Maps each view dimension to parent dimension(s)
Offset Calculation: Computes base offsets from slice start positions
Stride Application: Applies step sizes and memory layout strides
Bounds Validation: Ensures all coordinates remain within valid ranges
Memory Layout Support
The implementation assumes row-major memory layout with rightmost dimension having stride 1. For NCHW tensors with shape N, C, H, W, the natural strides are C×H×W, H×W, W, 1.
Performance Optimizations
Stride Pre-calculation: Computes and caches stride patterns on construction
Contiguity Detection: Identifies patterns that enable bulk operations
Bounds Checking: Validates slice compatibility during construction
Efficient Indexing: Minimizes array allocations in hot paths
Parameters
the data type constraint extending DType
the actual value type
the shape of the parent tensor
the list of slice operations, one per parent dimension
the computed shape of the resulting view
Constructors
Functions
Returns whether this slice pattern can benefit from vectorized access.
Pre-calculates memory access patterns for common slice types. This enables branch prediction optimization and faster hot path execution.
Returns whether this mapper represents contiguous memory access.
Maps view coordinates to parent tensor coordinates.