From 8867b365e3a824981363a00ec62fc37237c7a21a Mon Sep 17 00:00:00 2001 From: Andreas Longva Date: Mon, 14 Nov 2022 14:40:53 +0100 Subject: [PATCH] Rename slice -> view in parameter names, comments etc. --- src/base/construction_view.rs | 6 +-- src/base/conversion.rs | 96 +++++++++++++++++------------------ src/base/matrix_view.rs | 4 +- src/base/storage.rs | 4 +- 4 files changed, 55 insertions(+), 55 deletions(-) diff --git a/src/base/construction_view.rs b/src/base/construction_view.rs index fbb038cb..910b2873 100644 --- a/src/base/construction_view.rs +++ b/src/base/construction_view.rs @@ -48,7 +48,7 @@ impl<'a, T: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim> assert!( data.len() + cstride.value() + rstride.value() >= ncols.value() * cstride.value() + nrows.value() * rstride.value() + 1, - "Matrix slice: input data buffer to small." + "Matrix view: input data buffer too small." ); unsafe { @@ -186,7 +186,7 @@ impl<'a, T: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim> assert!( data.len() + cstride.value() + rstride.value() >= ncols.value() * cstride.value() + nrows.value() * rstride.value() + 1, - "Matrix slice: input data buffer to small." + "Matrix view: input data buffer too small." ); assert!( @@ -208,7 +208,7 @@ impl<'a, T: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim> } } }, - "Matrix slice: dimensions and strides result in aliased indices." + "Matrix view: dimensions and strides result in aliased indices." ); unsafe { diff --git a/src/base/conversion.rs b/src/base/conversion.rs index 4c83796e..79a61461 100644 --- a/src/base/conversion.rs +++ b/src/base/conversion.rs @@ -296,8 +296,8 @@ where RStride: Dim, CStride: Dim, { - fn from(matrix_slice: MatrixView<'a, T, Const, Const, RStride, CStride>) -> Self { - matrix_slice.into_owned() + fn from(matrix_view: MatrixView<'a, T, Const, Const, RStride, CStride>) -> Self { + matrix_view.into_owned() } } @@ -310,8 +310,8 @@ where RStride: Dim, CStride: Dim, { - fn from(matrix_slice: MatrixView<'a, T, Dynamic, C, RStride, CStride>) -> Self { - matrix_slice.into_owned() + fn from(matrix_view: MatrixView<'a, T, Dynamic, C, RStride, CStride>) -> Self { + matrix_view.into_owned() } } @@ -324,8 +324,8 @@ where RStride: Dim, CStride: Dim, { - fn from(matrix_slice: MatrixView<'a, T, R, Dynamic, RStride, CStride>) -> Self { - matrix_slice.into_owned() + fn from(matrix_view: MatrixView<'a, T, R, Dynamic, RStride, CStride>) -> Self { + matrix_view.into_owned() } } @@ -337,8 +337,8 @@ where RStride: Dim, CStride: Dim, { - fn from(matrix_slice: MatrixViewMut<'a, T, Const, Const, RStride, CStride>) -> Self { - matrix_slice.into_owned() + fn from(matrix_view: MatrixViewMut<'a, T, Const, Const, RStride, CStride>) -> Self { + matrix_view.into_owned() } } @@ -351,8 +351,8 @@ where RStride: Dim, CStride: Dim, { - fn from(matrix_slice: MatrixViewMut<'a, T, Dynamic, C, RStride, CStride>) -> Self { - matrix_slice.into_owned() + fn from(matrix_view: MatrixViewMut<'a, T, Dynamic, C, RStride, CStride>) -> Self { + matrix_view.into_owned() } } @@ -365,116 +365,116 @@ where RStride: Dim, CStride: Dim, { - fn from(matrix_slice: MatrixViewMut<'a, T, R, Dynamic, RStride, CStride>) -> Self { - matrix_slice.into_owned() + fn from(matrix_view: MatrixViewMut<'a, T, R, Dynamic, RStride, CStride>) -> Self { + matrix_view.into_owned() } } -impl<'a, T, R, C, RSlice, CSlice, RStride, CStride, S> From<&'a Matrix> - for MatrixView<'a, T, RSlice, CSlice, RStride, CStride> +impl<'a, T, R, C, RView, CView, RStride, CStride, S> From<&'a Matrix> + for MatrixView<'a, T, RView, CView, RStride, CStride> where T: Scalar, R: Dim, C: Dim, - RSlice: Dim, - CSlice: Dim, + RView: Dim, + CView: Dim, RStride: Dim, CStride: Dim, S: RawStorage, - ShapeConstraint: DimEq - + DimEq + ShapeConstraint: DimEq + + DimEq + DimEq + DimEq, { fn from(m: &'a Matrix) -> Self { let (row, col) = m.shape_generic(); - let row_slice = RSlice::from_usize(row.value()); - let col_slice = CSlice::from_usize(col.value()); + let rows_result = RView::from_usize(row.value()); + let cols_result = CView::from_usize(col.value()); let (rstride, cstride) = m.strides(); - let rstride_slice = RStride::from_usize(rstride); - let cstride_slice = CStride::from_usize(cstride); + let rstride_result = RStride::from_usize(rstride); + let cstride_result = CStride::from_usize(cstride); unsafe { let data = ViewStorage::from_raw_parts( m.data.ptr(), - (row_slice, col_slice), - (rstride_slice, cstride_slice), + (rows_result, cols_result), + (rstride_result, cstride_result), ); Matrix::from_data_statically_unchecked(data) } } } -impl<'a, T, R, C, RSlice, CSlice, RStride, CStride, S> From<&'a mut Matrix> - for MatrixView<'a, T, RSlice, CSlice, RStride, CStride> +impl<'a, T, R, C, RView, CView, RStride, CStride, S> From<&'a mut Matrix> + for MatrixView<'a, T, RView, CView, RStride, CStride> where T: Scalar, R: Dim, C: Dim, - RSlice: Dim, - CSlice: Dim, + RView: Dim, + CView: Dim, RStride: Dim, CStride: Dim, S: RawStorage, - ShapeConstraint: DimEq - + DimEq + ShapeConstraint: DimEq + + DimEq + DimEq + DimEq, { fn from(m: &'a mut Matrix) -> Self { let (row, col) = m.shape_generic(); - let row_slice = RSlice::from_usize(row.value()); - let col_slice = CSlice::from_usize(col.value()); + let rows_result = RView::from_usize(row.value()); + let cols_result = CView::from_usize(col.value()); let (rstride, cstride) = m.strides(); - let rstride_slice = RStride::from_usize(rstride); - let cstride_slice = CStride::from_usize(cstride); + let rstride_result = RStride::from_usize(rstride); + let cstride_result = CStride::from_usize(cstride); unsafe { let data = ViewStorage::from_raw_parts( m.data.ptr(), - (row_slice, col_slice), - (rstride_slice, cstride_slice), + (rows_result, cols_result), + (rstride_result, cstride_result), ); Matrix::from_data_statically_unchecked(data) } } } -impl<'a, T, R, C, RSlice, CSlice, RStride, CStride, S> From<&'a mut Matrix> - for MatrixViewMut<'a, T, RSlice, CSlice, RStride, CStride> +impl<'a, T, R, C, RView, CView, RStride, CStride, S> From<&'a mut Matrix> + for MatrixViewMut<'a, T, RView, CView, RStride, CStride> where T: Scalar, R: Dim, C: Dim, - RSlice: Dim, - CSlice: Dim, + RView: Dim, + CView: Dim, RStride: Dim, CStride: Dim, S: RawStorageMut, - ShapeConstraint: DimEq - + DimEq + ShapeConstraint: DimEq + + DimEq + DimEq + DimEq, { fn from(m: &'a mut Matrix) -> Self { let (row, col) = m.shape_generic(); - let row_slice = RSlice::from_usize(row.value()); - let col_slice = CSlice::from_usize(col.value()); + let rows_result = RView::from_usize(row.value()); + let cols_result = CView::from_usize(col.value()); let (rstride, cstride) = m.strides(); - let rstride_slice = RStride::from_usize(rstride); - let cstride_slice = CStride::from_usize(cstride); + let rstride_result = RStride::from_usize(rstride); + let cstride_result = CStride::from_usize(cstride); unsafe { let data = ViewStorageMut::from_raw_parts( m.data.ptr_mut(), - (row_slice, col_slice), - (rstride_slice, cstride_slice), + (rows_result, cols_result), + (rstride_result, cstride_result), ); Matrix::from_data_statically_unchecked(data) } diff --git a/src/base/matrix_view.rs b/src/base/matrix_view.rs index 0580546e..4af0a7e9 100644 --- a/src/base/matrix_view.rs +++ b/src/base/matrix_view.rs @@ -667,7 +667,7 @@ macro_rules! matrix_view_impl ( let nrows1 = r1.size(nrows); let nrows2 = r2.size(nrows); - assert!(start2 >= end1 || start1 >= end2, "Rows range pair: the slice ranges must not overlap."); + assert!(start2 >= end1 || start1 >= end2, "Rows range pair: the ranges must not overlap."); assert!(end2 <= nrows.value(), "Rows range pair: index out of range."); unsafe { @@ -703,7 +703,7 @@ macro_rules! matrix_view_impl ( let ncols1 = r1.size(ncols); let ncols2 = r2.size(ncols); - assert!(start2 >= end1 || start1 >= end2, "Columns range pair: the slice ranges must not overlap."); + assert!(start2 >= end1 || start1 >= end2, "Columns range pair: the ranges must not overlap."); assert!(end2 <= ncols.value(), "Columns range pair: index out of range."); unsafe { diff --git a/src/base/storage.rs b/src/base/storage.rs index 76a60ce3..dd335014 100644 --- a/src/base/storage.rs +++ b/src/base/storage.rs @@ -122,7 +122,7 @@ pub unsafe trait RawStorage: Sized { /// # Safety /// The matrix components may not be stored in a contiguous way, depending on the strides. /// This method is unsafe because this can yield to invalid aliasing when called on some pairs - /// of matrix slices originating from the same matrix with strides. + /// of matrix views originating from the same matrix with strides. /// /// Call the safe alternative `matrix.as_slice()` instead. unsafe fn as_slice_unchecked(&self) -> &[T]; @@ -148,7 +148,7 @@ pub unsafe trait Storage: RawStorage { /// contains `MaybeUninit` elements. /// /// Note that a mutable access does not mean that the matrix owns its data. For example, a mutable -/// matrix slice can provide mutable access to its elements even if it does not own its data (it +/// matrix view can provide mutable access to its elements even if it does not own its data (it /// contains only an internal reference to them). pub unsafe trait RawStorageMut: RawStorage { /// The matrix mutable data pointer.