Do not panic on empty ranges. (#257)

This commit is contained in:
Laurent Mazare
2023-07-27 09:28:47 +01:00
committed by GitHub
parent 209f06d7c3
commit f291065f6c
2 changed files with 14 additions and 1 deletions

View File

@ -42,7 +42,7 @@ impl Tensor {
Bound::Excluded(n) => *n,
Bound::Unbounded => dims[i],
};
let out = x.narrow(current_dim, start, stop - start)?;
let out = x.narrow(current_dim, start, stop.saturating_sub(start))?;
current_dim += 1;
out
}