Skip to main content

is_injective_layout

Function is_injective_layout 

Source
pub fn is_injective_layout(dims: &[usize], strides: &[isize]) -> bool
Expand description

Decide whether distinct logical positions map to distinct offsets.

Runs the allocation-free proof first (separated axes, the two-axis gcd argument, then the pairwise budget) and falls back to the exact enumeration only when the interleaved block exceeds the pairwise budget. This accepts every injective layout the exact check can settle, including the interleaved [3, 1500] / [2000, 3] case, without allocating for the common separated, small-block, or two-axis layouts.

ยง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]));