Rename slice -> view in parameter names, comments etc.
This commit is contained in:
parent
34f4537376
commit
8867b365e3
@ -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 {
|
||||
|
@ -296,8 +296,8 @@ where
|
||||
RStride: Dim,
|
||||
CStride: Dim,
|
||||
{
|
||||
fn from(matrix_slice: MatrixView<'a, T, Const<R>, Const<C>, RStride, CStride>) -> Self {
|
||||
matrix_slice.into_owned()
|
||||
fn from(matrix_view: MatrixView<'a, T, Const<R>, Const<C>, 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<R>, Const<C>, RStride, CStride>) -> Self {
|
||||
matrix_slice.into_owned()
|
||||
fn from(matrix_view: MatrixViewMut<'a, T, Const<R>, Const<C>, 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<T, R, C, S>>
|
||||
for MatrixView<'a, T, RSlice, CSlice, RStride, CStride>
|
||||
impl<'a, T, R, C, RView, CView, RStride, CStride, S> From<&'a Matrix<T, R, C, S>>
|
||||
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<T, R, C>,
|
||||
ShapeConstraint: DimEq<R, RSlice>
|
||||
+ DimEq<C, CSlice>
|
||||
ShapeConstraint: DimEq<R, RView>
|
||||
+ DimEq<C, CView>
|
||||
+ DimEq<RStride, S::RStride>
|
||||
+ DimEq<CStride, S::CStride>,
|
||||
{
|
||||
fn from(m: &'a Matrix<T, R, C, S>) -> 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<T, R, C, S>>
|
||||
for MatrixView<'a, T, RSlice, CSlice, RStride, CStride>
|
||||
impl<'a, T, R, C, RView, CView, RStride, CStride, S> From<&'a mut Matrix<T, R, C, S>>
|
||||
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<T, R, C>,
|
||||
ShapeConstraint: DimEq<R, RSlice>
|
||||
+ DimEq<C, CSlice>
|
||||
ShapeConstraint: DimEq<R, RView>
|
||||
+ DimEq<C, CView>
|
||||
+ DimEq<RStride, S::RStride>
|
||||
+ DimEq<CStride, S::CStride>,
|
||||
{
|
||||
fn from(m: &'a mut Matrix<T, R, C, S>) -> 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<T, R, C, S>>
|
||||
for MatrixViewMut<'a, T, RSlice, CSlice, RStride, CStride>
|
||||
impl<'a, T, R, C, RView, CView, RStride, CStride, S> From<&'a mut Matrix<T, R, C, S>>
|
||||
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<T, R, C>,
|
||||
ShapeConstraint: DimEq<R, RSlice>
|
||||
+ DimEq<C, CSlice>
|
||||
ShapeConstraint: DimEq<R, RView>
|
||||
+ DimEq<C, CView>
|
||||
+ DimEq<RStride, S::RStride>
|
||||
+ DimEq<CStride, S::CStride>,
|
||||
{
|
||||
fn from(m: &'a mut Matrix<T, R, C, S>) -> 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)
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -122,7 +122,7 @@ pub unsafe trait RawStorage<T, R: Dim, C: Dim = U1>: 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<T, R: Dim, C: Dim = U1>: RawStorage<T, R, C> {
|
||||
/// contains `MaybeUninit<T>` 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<T, R: Dim, C: Dim = U1>: RawStorage<T, R, C> {
|
||||
/// The matrix mutable data pointer.
|
||||
|
Loading…
Reference in New Issue
Block a user