mirror of
https://github.com/huggingface/candle.git
synced 2025-06-18 19:47:12 +00:00
Check that the tensor is contiguous before applying the kernel.
This commit is contained in:
14
src/shape.rs
14
src/shape.rs
@ -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)]
|
||||
|
Reference in New Issue
Block a user