Skip to content

Commit

Permalink
Merge pull request #975 from xd009642/feature/track-callers
Browse files Browse the repository at this point in the history
Track-caller panics
  • Loading branch information
bluss authored Mar 10, 2024
2 parents c4db8e7 + 2cb374a commit 5465bc4
Show file tree
Hide file tree
Showing 12 changed files with 93 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/dimension/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,11 +310,13 @@ pub trait DimensionExt {
/// Get the dimension at `axis`.
///
/// *Panics* if `axis` is out of bounds.
#[track_caller]
fn axis(&self, axis: Axis) -> Ix;

/// Set the dimension at `axis`.
///
/// *Panics* if `axis` is out of bounds.
#[track_caller]
fn set_axis(&mut self, axis: Axis, value: Ix);
}

Expand Down Expand Up @@ -349,6 +351,7 @@ impl DimensionExt for [Ix] {
/// available.
///
/// **Panics** if `index` is larger than the size of the axis
#[track_caller]
// FIXME: Move to Dimension trait
pub fn do_collapse_axis<D: Dimension>(
dims: &mut D,
Expand Down Expand Up @@ -385,6 +388,7 @@ pub fn abs_index(len: Ix, index: Ixs) -> Ix {
/// The return value is (start, end, step).
///
/// **Panics** if stride is 0 or if any index is out of bounds.
#[track_caller]
fn to_abs_slice(axis_len: usize, slice: Slice) -> (usize, usize, isize) {
let Slice { start, end, step } = slice;
let start = abs_index(axis_len, start);
Expand Down Expand Up @@ -426,6 +430,7 @@ pub fn offset_from_low_addr_ptr_to_logical_ptr<D: Dimension>(dim: &D, strides: &
/// Modify dimension, stride and return data pointer offset
///
/// **Panics** if stride is 0 or if any index is out of bounds.
#[track_caller]
pub fn do_slice(dim: &mut usize, stride: &mut usize, slice: Slice) -> isize {
let (start, end, step) = to_abs_slice(*dim, slice);

Expand Down
4 changes: 4 additions & 0 deletions src/impl_2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ where
/// let array = array![[1., 2.], [3., 4.]];
/// assert_eq!(array.row(0), array![1., 2.]);
/// ```
#[track_caller]
pub fn row(&self, index: Ix) -> ArrayView1<'_, A>
where
S: Data,
Expand All @@ -40,6 +41,7 @@ where
/// array.row_mut(0)[1] = 5.;
/// assert_eq!(array, array![[1., 5.], [3., 4.]]);
/// ```
#[track_caller]
pub fn row_mut(&mut self, index: Ix) -> ArrayViewMut1<'_, A>
where
S: DataMut,
Expand Down Expand Up @@ -77,6 +79,7 @@ where
/// let array = array![[1., 2.], [3., 4.]];
/// assert_eq!(array.column(0), array![1., 3.]);
/// ```
#[track_caller]
pub fn column(&self, index: Ix) -> ArrayView1<'_, A>
where
S: Data,
Expand All @@ -94,6 +97,7 @@ where
/// array.column_mut(0)[1] = 5.;
/// assert_eq!(array, array![[1., 2.], [5., 4.]]);
/// ```
#[track_caller]
pub fn column_mut(&mut self, index: Ix) -> ArrayViewMut1<'_, A>
where
S: DataMut,
Expand Down
2 changes: 2 additions & 0 deletions src/impl_dyn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ where
/// assert_eq!(a, arr3(&[[[1, 2, 3]], [[4, 5, 6]]]).into_dyn());
/// assert_eq!(a.shape(), &[2, 1, 3]);
/// ```
#[track_caller]
pub fn insert_axis_inplace(&mut self, axis: Axis) {
assert!(axis.index() <= self.ndim());
self.dim = self.dim.insert_axis(axis);
Expand All @@ -50,6 +51,7 @@ where
/// assert_eq!(a, arr1(&[2, 5]).into_dyn());
/// assert_eq!(a.shape(), &[2]);
/// ```
#[track_caller]
pub fn index_axis_inplace(&mut self, axis: Axis, index: usize) {
self.collapse_axis(axis, index);
self.dim = self.dim.remove_axis(axis);
Expand Down
Loading

0 comments on commit 5465bc4

Please sign in to comment.