Version: v0.2.0
Status: Complete
Header: include/stratax/core/ops/Slice.hpp
Overview
ops/Slice.hpp implements slicing for vector, matrix, and tensor containers using stratax::core::Slice ranges.
All overloads return owning containers that copy selected elements from the source.
Responsibilities
The slice ops module is responsible for:
- Normalizing signed slice ranges against container extents
- Applying strided selection for 1D, 2D, and ND containers
- Building result shapes and copying selected elements
The slice ops module is not responsible for:
- Returning non-owning views
- Defining Slice semantics itself
- Broadcasting or advanced gather indexing
Relationships
slice(...) overloads
├── detail::normalize_slice(...)
├── core::Slice metadata
├── validation::require_rank(...) for tensor rank check
└── validation::checked_* for tensor offset arithmetic
Depends on:
Invariants
The following conditions are always true:
- Output containers are owning copies.
- Slice normalization is half-open and step-aware for both step directions.
- Out-of-range start/stop values are clamped, not rejected.
- Tensor slicing requires slice count equal to tensor rank.
- Empty output shapes return early without element copy loops.
Public Interface
Vector slicing
template<typename T>
Represents a half-open strided range of indices.
stratax::container::Vector< T > slice(const stratax::container::Vector< T > &vec, const stratax::core::Slice &slice)
Copies a half-open range from a vector.
Behavior
- Normalizes and clamps range against vec.size()
- Copies selected elements into a new vector
Throws
Complexity
- O(k), where k is output size
Matrix slicing
Behavior
- Normalizes/clamps row and column slices independently
- Copies rectangular strided region into a new matrix
Throws
Complexity
Tensor slicing
template<typename T, typename... Slices>
Behavior
- Requires all variadic arguments to be stratax::core::Slice
- Requires number of slices to match tensor rank
- Computes output shape from resolved slice sizes
- Copies result in flat order using source/result strides
Throws
Complexity
Complexity Summary
| Operation | Complexity |
| normalize_slice | O(1) |
| Vector slice | O(k) |
| Matrix slice | O(r_out * c_out) |
| Tensor slice | O(n_out * rank) |
Examples
Design Notes
Normalization is permissive by design: start/stop values are clamped to legal bounds, which keeps slicing behavior predictable and pythonic.
Tensor slicing currently copies into new storage rather than producing a view to preserve ownership simplicity.
Future Improvements
- Add non-owning slice/view support
- Add richer slice composition helpers
- Evaluate vectorized copy kernels for dense slices
See Also