Check that the tensor is contiguous before applying the kernel.

This commit is contained in:
laurent
2023-06-21 21:28:59 +01:00
parent 9834151254
commit 7c46de9584
3 changed files with 19 additions and 10 deletions

View File

@ -128,6 +128,20 @@ impl Shape {
stride.reverse();
stride
}
pub fn is_contiguous(&self, stride: &[usize]) -> bool {
if self.0.len() != stride.len() {
return false;
}
let mut acc = 1;
for (&stride, &dim) in stride.iter().zip(self.0.iter()).rev() {
if stride != acc {
return false;
}
acc *= dim;
}
true
}
}
#[cfg(test)]