Skip to content

Commit

Permalink
Merge pull request rust-ndarray#389 from jturner314/fix-step-by
Browse files Browse the repository at this point in the history
Change SliceOrIndex::step_by step to be multiplicative and add debug assertion for step != 0
  • Loading branch information
bluss authored Nov 29, 2017
2 parents 0ece678 + f2dff3e commit 0bdce23
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,24 @@ impl SliceOrIndex {
}
}

/// Returns a new `SliceOrIndex` with the given step size.
/// Returns a new `SliceOrIndex` with the given step size (multiplied with
/// the previous step size).
///
/// `step` must be nonzero.
/// (This method checks with a debug assertion that `step` is not zero.)
#[inline]
pub fn step_by(self, step: isize) -> Self {
debug_assert_ne!(step, 0, "SliceOrIndex::step_by: step must be nonzero");
match self {
SliceOrIndex::Slice { start, end, .. } => SliceOrIndex::Slice { start, end, step },
SliceOrIndex::Slice {
start,
end,
step: orig_step,
} => SliceOrIndex::Slice {
start,
end,
step: orig_step * step,
},
SliceOrIndex::Index(s) => SliceOrIndex::Index(s),
}
}
Expand Down

0 comments on commit 0bdce23

Please sign in to comment.