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!(
|
assert!(
|
||||||
data.len() + cstride.value() + rstride.value()
|
data.len() + cstride.value() + rstride.value()
|
||||||
>= ncols.value() * cstride.value() + nrows.value() * rstride.value() + 1,
|
>= ncols.value() * cstride.value() + nrows.value() * rstride.value() + 1,
|
||||||
"Matrix slice: input data buffer to small."
|
"Matrix view: input data buffer too small."
|
||||||
);
|
);
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -186,7 +186,7 @@ impl<'a, T: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim>
|
||||||
assert!(
|
assert!(
|
||||||
data.len() + cstride.value() + rstride.value()
|
data.len() + cstride.value() + rstride.value()
|
||||||
>= ncols.value() * cstride.value() + nrows.value() * rstride.value() + 1,
|
>= ncols.value() * cstride.value() + nrows.value() * rstride.value() + 1,
|
||||||
"Matrix slice: input data buffer to small."
|
"Matrix view: input data buffer too small."
|
||||||
);
|
);
|
||||||
|
|
||||||
assert!(
|
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 {
|
unsafe {
|
||||||
|
|
|
@ -296,8 +296,8 @@ where
|
||||||
RStride: Dim,
|
RStride: Dim,
|
||||||
CStride: Dim,
|
CStride: Dim,
|
||||||
{
|
{
|
||||||
fn from(matrix_slice: MatrixView<'a, T, Const<R>, Const<C>, RStride, CStride>) -> Self {
|
fn from(matrix_view: MatrixView<'a, T, Const<R>, Const<C>, RStride, CStride>) -> Self {
|
||||||
matrix_slice.into_owned()
|
matrix_view.into_owned()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -310,8 +310,8 @@ where
|
||||||
RStride: Dim,
|
RStride: Dim,
|
||||||
CStride: Dim,
|
CStride: Dim,
|
||||||
{
|
{
|
||||||
fn from(matrix_slice: MatrixView<'a, T, Dynamic, C, RStride, CStride>) -> Self {
|
fn from(matrix_view: MatrixView<'a, T, Dynamic, C, RStride, CStride>) -> Self {
|
||||||
matrix_slice.into_owned()
|
matrix_view.into_owned()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -324,8 +324,8 @@ where
|
||||||
RStride: Dim,
|
RStride: Dim,
|
||||||
CStride: Dim,
|
CStride: Dim,
|
||||||
{
|
{
|
||||||
fn from(matrix_slice: MatrixView<'a, T, R, Dynamic, RStride, CStride>) -> Self {
|
fn from(matrix_view: MatrixView<'a, T, R, Dynamic, RStride, CStride>) -> Self {
|
||||||
matrix_slice.into_owned()
|
matrix_view.into_owned()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -337,8 +337,8 @@ where
|
||||||
RStride: Dim,
|
RStride: Dim,
|
||||||
CStride: Dim,
|
CStride: Dim,
|
||||||
{
|
{
|
||||||
fn from(matrix_slice: MatrixViewMut<'a, T, Const<R>, Const<C>, RStride, CStride>) -> Self {
|
fn from(matrix_view: MatrixViewMut<'a, T, Const<R>, Const<C>, RStride, CStride>) -> Self {
|
||||||
matrix_slice.into_owned()
|
matrix_view.into_owned()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -351,8 +351,8 @@ where
|
||||||
RStride: Dim,
|
RStride: Dim,
|
||||||
CStride: Dim,
|
CStride: Dim,
|
||||||
{
|
{
|
||||||
fn from(matrix_slice: MatrixViewMut<'a, T, Dynamic, C, RStride, CStride>) -> Self {
|
fn from(matrix_view: MatrixViewMut<'a, T, Dynamic, C, RStride, CStride>) -> Self {
|
||||||
matrix_slice.into_owned()
|
matrix_view.into_owned()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -365,116 +365,116 @@ where
|
||||||
RStride: Dim,
|
RStride: Dim,
|
||||||
CStride: Dim,
|
CStride: Dim,
|
||||||
{
|
{
|
||||||
fn from(matrix_slice: MatrixViewMut<'a, T, R, Dynamic, RStride, CStride>) -> Self {
|
fn from(matrix_view: MatrixViewMut<'a, T, R, Dynamic, RStride, CStride>) -> Self {
|
||||||
matrix_slice.into_owned()
|
matrix_view.into_owned()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, T, R, C, RSlice, CSlice, RStride, CStride, S> From<&'a Matrix<T, R, C, S>>
|
impl<'a, T, R, C, RView, CView, RStride, CStride, S> From<&'a Matrix<T, R, C, S>>
|
||||||
for MatrixView<'a, T, RSlice, CSlice, RStride, CStride>
|
for MatrixView<'a, T, RView, CView, RStride, CStride>
|
||||||
where
|
where
|
||||||
T: Scalar,
|
T: Scalar,
|
||||||
R: Dim,
|
R: Dim,
|
||||||
C: Dim,
|
C: Dim,
|
||||||
RSlice: Dim,
|
RView: Dim,
|
||||||
CSlice: Dim,
|
CView: Dim,
|
||||||
RStride: Dim,
|
RStride: Dim,
|
||||||
CStride: Dim,
|
CStride: Dim,
|
||||||
S: RawStorage<T, R, C>,
|
S: RawStorage<T, R, C>,
|
||||||
ShapeConstraint: DimEq<R, RSlice>
|
ShapeConstraint: DimEq<R, RView>
|
||||||
+ DimEq<C, CSlice>
|
+ DimEq<C, CView>
|
||||||
+ DimEq<RStride, S::RStride>
|
+ DimEq<RStride, S::RStride>
|
||||||
+ DimEq<CStride, S::CStride>,
|
+ DimEq<CStride, S::CStride>,
|
||||||
{
|
{
|
||||||
fn from(m: &'a Matrix<T, R, C, S>) -> Self {
|
fn from(m: &'a Matrix<T, R, C, S>) -> Self {
|
||||||
let (row, col) = m.shape_generic();
|
let (row, col) = m.shape_generic();
|
||||||
let row_slice = RSlice::from_usize(row.value());
|
let rows_result = RView::from_usize(row.value());
|
||||||
let col_slice = CSlice::from_usize(col.value());
|
let cols_result = CView::from_usize(col.value());
|
||||||
|
|
||||||
let (rstride, cstride) = m.strides();
|
let (rstride, cstride) = m.strides();
|
||||||
|
|
||||||
let rstride_slice = RStride::from_usize(rstride);
|
let rstride_result = RStride::from_usize(rstride);
|
||||||
let cstride_slice = CStride::from_usize(cstride);
|
let cstride_result = CStride::from_usize(cstride);
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let data = ViewStorage::from_raw_parts(
|
let data = ViewStorage::from_raw_parts(
|
||||||
m.data.ptr(),
|
m.data.ptr(),
|
||||||
(row_slice, col_slice),
|
(rows_result, cols_result),
|
||||||
(rstride_slice, cstride_slice),
|
(rstride_result, cstride_result),
|
||||||
);
|
);
|
||||||
Matrix::from_data_statically_unchecked(data)
|
Matrix::from_data_statically_unchecked(data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, T, R, C, RSlice, CSlice, RStride, CStride, S> From<&'a mut Matrix<T, R, C, S>>
|
impl<'a, T, R, C, RView, CView, RStride, CStride, S> From<&'a mut Matrix<T, R, C, S>>
|
||||||
for MatrixView<'a, T, RSlice, CSlice, RStride, CStride>
|
for MatrixView<'a, T, RView, CView, RStride, CStride>
|
||||||
where
|
where
|
||||||
T: Scalar,
|
T: Scalar,
|
||||||
R: Dim,
|
R: Dim,
|
||||||
C: Dim,
|
C: Dim,
|
||||||
RSlice: Dim,
|
RView: Dim,
|
||||||
CSlice: Dim,
|
CView: Dim,
|
||||||
RStride: Dim,
|
RStride: Dim,
|
||||||
CStride: Dim,
|
CStride: Dim,
|
||||||
S: RawStorage<T, R, C>,
|
S: RawStorage<T, R, C>,
|
||||||
ShapeConstraint: DimEq<R, RSlice>
|
ShapeConstraint: DimEq<R, RView>
|
||||||
+ DimEq<C, CSlice>
|
+ DimEq<C, CView>
|
||||||
+ DimEq<RStride, S::RStride>
|
+ DimEq<RStride, S::RStride>
|
||||||
+ DimEq<CStride, S::CStride>,
|
+ DimEq<CStride, S::CStride>,
|
||||||
{
|
{
|
||||||
fn from(m: &'a mut Matrix<T, R, C, S>) -> Self {
|
fn from(m: &'a mut Matrix<T, R, C, S>) -> Self {
|
||||||
let (row, col) = m.shape_generic();
|
let (row, col) = m.shape_generic();
|
||||||
let row_slice = RSlice::from_usize(row.value());
|
let rows_result = RView::from_usize(row.value());
|
||||||
let col_slice = CSlice::from_usize(col.value());
|
let cols_result = CView::from_usize(col.value());
|
||||||
|
|
||||||
let (rstride, cstride) = m.strides();
|
let (rstride, cstride) = m.strides();
|
||||||
|
|
||||||
let rstride_slice = RStride::from_usize(rstride);
|
let rstride_result = RStride::from_usize(rstride);
|
||||||
let cstride_slice = CStride::from_usize(cstride);
|
let cstride_result = CStride::from_usize(cstride);
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let data = ViewStorage::from_raw_parts(
|
let data = ViewStorage::from_raw_parts(
|
||||||
m.data.ptr(),
|
m.data.ptr(),
|
||||||
(row_slice, col_slice),
|
(rows_result, cols_result),
|
||||||
(rstride_slice, cstride_slice),
|
(rstride_result, cstride_result),
|
||||||
);
|
);
|
||||||
Matrix::from_data_statically_unchecked(data)
|
Matrix::from_data_statically_unchecked(data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, T, R, C, RSlice, CSlice, RStride, CStride, S> From<&'a mut Matrix<T, R, C, S>>
|
impl<'a, T, R, C, RView, CView, RStride, CStride, S> From<&'a mut Matrix<T, R, C, S>>
|
||||||
for MatrixViewMut<'a, T, RSlice, CSlice, RStride, CStride>
|
for MatrixViewMut<'a, T, RView, CView, RStride, CStride>
|
||||||
where
|
where
|
||||||
T: Scalar,
|
T: Scalar,
|
||||||
R: Dim,
|
R: Dim,
|
||||||
C: Dim,
|
C: Dim,
|
||||||
RSlice: Dim,
|
RView: Dim,
|
||||||
CSlice: Dim,
|
CView: Dim,
|
||||||
RStride: Dim,
|
RStride: Dim,
|
||||||
CStride: Dim,
|
CStride: Dim,
|
||||||
S: RawStorageMut<T, R, C>,
|
S: RawStorageMut<T, R, C>,
|
||||||
ShapeConstraint: DimEq<R, RSlice>
|
ShapeConstraint: DimEq<R, RView>
|
||||||
+ DimEq<C, CSlice>
|
+ DimEq<C, CView>
|
||||||
+ DimEq<RStride, S::RStride>
|
+ DimEq<RStride, S::RStride>
|
||||||
+ DimEq<CStride, S::CStride>,
|
+ DimEq<CStride, S::CStride>,
|
||||||
{
|
{
|
||||||
fn from(m: &'a mut Matrix<T, R, C, S>) -> Self {
|
fn from(m: &'a mut Matrix<T, R, C, S>) -> Self {
|
||||||
let (row, col) = m.shape_generic();
|
let (row, col) = m.shape_generic();
|
||||||
let row_slice = RSlice::from_usize(row.value());
|
let rows_result = RView::from_usize(row.value());
|
||||||
let col_slice = CSlice::from_usize(col.value());
|
let cols_result = CView::from_usize(col.value());
|
||||||
|
|
||||||
let (rstride, cstride) = m.strides();
|
let (rstride, cstride) = m.strides();
|
||||||
|
|
||||||
let rstride_slice = RStride::from_usize(rstride);
|
let rstride_result = RStride::from_usize(rstride);
|
||||||
let cstride_slice = CStride::from_usize(cstride);
|
let cstride_result = CStride::from_usize(cstride);
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let data = ViewStorageMut::from_raw_parts(
|
let data = ViewStorageMut::from_raw_parts(
|
||||||
m.data.ptr_mut(),
|
m.data.ptr_mut(),
|
||||||
(row_slice, col_slice),
|
(rows_result, cols_result),
|
||||||
(rstride_slice, cstride_slice),
|
(rstride_result, cstride_result),
|
||||||
);
|
);
|
||||||
Matrix::from_data_statically_unchecked(data)
|
Matrix::from_data_statically_unchecked(data)
|
||||||
}
|
}
|
||||||
|
|
|
@ -667,7 +667,7 @@ macro_rules! matrix_view_impl (
|
||||||
let nrows1 = r1.size(nrows);
|
let nrows1 = r1.size(nrows);
|
||||||
let nrows2 = r2.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.");
|
assert!(end2 <= nrows.value(), "Rows range pair: index out of range.");
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -703,7 +703,7 @@ macro_rules! matrix_view_impl (
|
||||||
let ncols1 = r1.size(ncols);
|
let ncols1 = r1.size(ncols);
|
||||||
let ncols2 = r2.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.");
|
assert!(end2 <= ncols.value(), "Columns range pair: index out of range.");
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
|
@ -122,7 +122,7 @@ pub unsafe trait RawStorage<T, R: Dim, C: Dim = U1>: Sized {
|
||||||
/// # Safety
|
/// # Safety
|
||||||
/// The matrix components may not be stored in a contiguous way, depending on the strides.
|
/// 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
|
/// 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.
|
/// Call the safe alternative `matrix.as_slice()` instead.
|
||||||
unsafe fn as_slice_unchecked(&self) -> &[T];
|
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.
|
/// contains `MaybeUninit<T>` elements.
|
||||||
///
|
///
|
||||||
/// Note that a mutable access does not mean that the matrix owns its data. For example, a mutable
|
/// 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).
|
/// contains only an internal reference to them).
|
||||||
pub unsafe trait RawStorageMut<T, R: Dim, C: Dim = U1>: RawStorage<T, R, C> {
|
pub unsafe trait RawStorageMut<T, R: Dim, C: Dim = U1>: RawStorage<T, R, C> {
|
||||||
/// The matrix mutable data pointer.
|
/// The matrix mutable data pointer.
|
||||||
|
|
Loading…
Reference in New Issue