pub fn is_injective_layout(dims: &[usize], strides: &[isize]) -> boolExpand description
Decide whether distinct logical positions map to distinct offsets.
Runs the allocation-free proof first (separated axes, the two-axis gcd
argument, the difference search, then the pairwise budget) and falls back
to the exact enumeration only when all of those are out of budget. This
accepts the interleaved [3, 1500] / [2000, 3] and
[2, 2, 5_000_000] / [4, 5, 6] cases without allocating.
true always means injective. false means the layout aliases, except
for one documented residual: an interleaved block of three or more axes
whose difference search (half the product of 2 * extent - 1 over all but
its two longest axes) exceeds 2^22 vectors and whose element count
exceeds 2^24 is not decided and is reported as false. Such a block needs
at least three interleaved axes with long extents.
ยงExamples
use strided_view::is_injective_layout;
assert!(is_injective_layout(&[2, 3], &[1, 2]));
assert!(!is_injective_layout(&[2, 3], &[0, 1]));
// Interleaved but injective: 2000 = 2 (mod 3) keeps the rows apart.
assert!(is_injective_layout(&[3, 1500], &[2000, 3]));