pub fn reshape_with_limit(slice: &Slice, limit: Limit) -> Slice
Expand description
Reshapes a slice by factoring each dimension into smaller extents under the given limit.
This transformation increases dimensionality by breaking large
sizes into products of smaller factors (e.g., [1024]
with limit
32 becomes [32, 32]
). The result is a new Slice
that
preserves memory layout and flat index semantics.
Factoring is greedy, starting from the largest divisors ≤ limit
.
Dimensions that cannot be factored under the limit are left
unchanged.
§Arguments
slice
: the original multidimensional slicelimit
: maximum extent allowed in any factored subdimension
§Returns
A reshaped Slice
with updated sizes and strides.
§Example
use ndslice::Slice;
use ndslice::reshape::Limit;
use ndslice::reshape::reshape_with_limit;
let slice = Slice::new_row_major(vec![1024]);
let reshaped = reshape_with_limit(&slice, Limit::new(32));
assert_eq!(reshaped.sizes(), &[32, 32]);