cubecl_std/tensor/base.rs
1/// Checks if the tensor associated with the given strides is contiguous.
2pub fn is_contiguous(strides: &[usize]) -> bool {
3 let mut current = 1;
4
5 for stride in strides.iter().rev() {
6 if current > *stride {
7 return false;
8 }
9 current = *stride;
10 }
11
12 true
13}
14
15pub fn compact_strides(shape: &[usize]) -> Vec<usize> {
16 let rank = shape.len();
17 let mut strides = vec![1; rank];
18 for i in (0..rank - 1).rev() {
19 strides[i] = strides[i + 1] * shape[i + 1];
20 }
21 strides
22}