Rename MatrixSlice(Mut) to MatrixView(Mut)

Additionally introduce deprecated type aliases with the old names to avoid
a breaking change.
This commit is contained in:
Andreas Longva 2022-11-11 16:10:39 +01:00
parent c8dfb5e348
commit 29bff32d2d
6 changed files with 96 additions and 75 deletions

View File

@ -1,12 +1,12 @@
use crate::base::dimension::{Const, Dim, DimName, Dynamic}; use crate::base::dimension::{Const, Dim, DimName, Dynamic};
use crate::base::matrix_slice::{ViewStorage, ViewStorageMut}; use crate::base::matrix_slice::{ViewStorage, ViewStorageMut};
use crate::base::{MatrixSlice, MatrixSliceMutMN, Scalar}; use crate::base::{MatrixView, MatrixSliceMutMN, Scalar};
use num_rational::Ratio; use num_rational::Ratio;
/// # Creating matrix slices from `&[T]` /// # Creating matrix slices from `&[T]`
impl<'a, T: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim> impl<'a, T: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim>
MatrixSlice<'a, T, R, C, RStride, CStride> MatrixView<'a, T, R, C, RStride, CStride>
{ {
/// Creates, without bound-checking, a matrix slice from an array and with dimensions and strides specified by generic types instances. /// Creates, without bound-checking, a matrix slice from an array and with dimensions and strides specified by generic types instances.
/// ///
@ -57,7 +57,7 @@ impl<'a, T: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim>
} }
} }
impl<'a, T: Scalar, R: Dim, C: Dim> MatrixSlice<'a, T, R, C> { impl<'a, T: Scalar, R: Dim, C: Dim> MatrixView<'a, T, R, C> {
/// Creates, without bound-checking, a matrix slice from an array and with dimensions specified by generic types instances. /// Creates, without bound-checking, a matrix slice from an array and with dimensions specified by generic types instances.
/// ///
/// # Safety /// # Safety
@ -87,7 +87,7 @@ impl<'a, T: Scalar, R: Dim, C: Dim> MatrixSlice<'a, T, R, C> {
macro_rules! impl_constructors( macro_rules! impl_constructors(
($($Dims: ty),*; $(=> $DimIdent: ident: $DimBound: ident),*; $($gargs: expr),*; $($args: ident),*) => { ($($Dims: ty),*; $(=> $DimIdent: ident: $DimBound: ident),*; $($gargs: expr),*; $($args: ident),*) => {
impl<'a, T: Scalar, $($DimIdent: $DimBound),*> MatrixSlice<'a, T, $($Dims),*> { impl<'a, T: Scalar, $($DimIdent: $DimBound),*> MatrixView<'a, T, $($Dims),*> {
/// Creates a new matrix slice from the given data array. /// Creates a new matrix slice from the given data array.
/// ///
/// Panics if `data` does not contain enough elements. /// Panics if `data` does not contain enough elements.
@ -103,7 +103,7 @@ macro_rules! impl_constructors(
} }
} }
impl<'a, T: Scalar, $($DimIdent: $DimBound, )*> MatrixSlice<'a, T, $($Dims,)* Dynamic, Dynamic> { impl<'a, T: Scalar, $($DimIdent: $DimBound, )*> MatrixView<'a, T, $($Dims,)* Dynamic, Dynamic> {
/// Creates a new matrix slice with the specified strides from the given data array. /// Creates a new matrix slice with the specified strides from the given data array.
/// ///
/// Panics if `data` does not contain enough elements. /// Panics if `data` does not contain enough elements.

View File

@ -16,8 +16,8 @@ use crate::base::dimension::{
use crate::base::iter::{MatrixIter, MatrixIterMut}; use crate::base::iter::{MatrixIter, MatrixIterMut};
use crate::base::storage::{IsContiguous, RawStorage, RawStorageMut}; use crate::base::storage::{IsContiguous, RawStorage, RawStorageMut};
use crate::base::{ use crate::base::{
ArrayStorage, DVectorSlice, DVectorSliceMut, DefaultAllocator, Matrix, MatrixSlice, ArrayStorage, DVectorSlice, DVectorSliceMut, DefaultAllocator, Matrix, MatrixView,
MatrixSliceMut, OMatrix, Scalar, MatrixViewMut, OMatrix, Scalar,
}; };
#[cfg(any(feature = "std", feature = "alloc"))] #[cfg(any(feature = "std", feature = "alloc"))]
use crate::base::{DVector, RowDVector, VecStorage}; use crate::base::{DVector, RowDVector, VecStorage};
@ -221,19 +221,19 @@ impl<T: Scalar, const R: usize, const C: usize> From<SMatrix<T, R, C>> for [[T;
} }
impl<'a, T: Scalar, RStride: Dim, CStride: Dim, const R: usize, const C: usize> impl<'a, T: Scalar, RStride: Dim, CStride: Dim, const R: usize, const C: usize>
From<MatrixSlice<'a, T, Const<R>, Const<C>, RStride, CStride>> for [[T; R]; C] From<MatrixView<'a, T, Const<R>, Const<C>, RStride, CStride>> for [[T; R]; C]
{ {
#[inline] #[inline]
fn from(mat: MatrixSlice<'a, T, Const<R>, Const<C>, RStride, CStride>) -> Self { fn from(mat: MatrixView<'a, T, Const<R>, Const<C>, RStride, CStride>) -> Self {
mat.into_owned().into() mat.into_owned().into()
} }
} }
impl<'a, T: Scalar, RStride: Dim, CStride: Dim, const R: usize, const C: usize> impl<'a, T: Scalar, RStride: Dim, CStride: Dim, const R: usize, const C: usize>
From<MatrixSliceMut<'a, T, Const<R>, Const<C>, RStride, CStride>> for [[T; R]; C] From<MatrixViewMut<'a, T, Const<R>, Const<C>, RStride, CStride>> for [[T; R]; C]
{ {
#[inline] #[inline]
fn from(mat: MatrixSliceMut<'a, T, Const<R>, Const<C>, RStride, CStride>) -> Self { fn from(mat: MatrixViewMut<'a, T, Const<R>, Const<C>, RStride, CStride>) -> Self {
mat.into_owned().into() mat.into_owned().into()
} }
} }
@ -289,20 +289,20 @@ impl_from_into_asref_borrow_2D!(
); );
impl<'a, T, RStride, CStride, const R: usize, const C: usize> impl<'a, T, RStride, CStride, const R: usize, const C: usize>
From<MatrixSlice<'a, T, Const<R>, Const<C>, RStride, CStride>> From<MatrixView<'a, T, Const<R>, Const<C>, RStride, CStride>>
for Matrix<T, Const<R>, Const<C>, ArrayStorage<T, R, C>> for Matrix<T, Const<R>, Const<C>, ArrayStorage<T, R, C>>
where where
T: Scalar, T: Scalar,
RStride: Dim, RStride: Dim,
CStride: Dim, CStride: Dim,
{ {
fn from(matrix_slice: MatrixSlice<'a, T, Const<R>, Const<C>, RStride, CStride>) -> Self { fn from(matrix_slice: MatrixView<'a, T, Const<R>, Const<C>, RStride, CStride>) -> Self {
matrix_slice.into_owned() matrix_slice.into_owned()
} }
} }
#[cfg(any(feature = "std", feature = "alloc"))] #[cfg(any(feature = "std", feature = "alloc"))]
impl<'a, T, C, RStride, CStride> From<MatrixSlice<'a, T, Dynamic, C, RStride, CStride>> impl<'a, T, C, RStride, CStride> From<MatrixView<'a, T, Dynamic, C, RStride, CStride>>
for Matrix<T, Dynamic, C, VecStorage<T, Dynamic, C>> for Matrix<T, Dynamic, C, VecStorage<T, Dynamic, C>>
where where
T: Scalar, T: Scalar,
@ -310,13 +310,13 @@ where
RStride: Dim, RStride: Dim,
CStride: Dim, CStride: Dim,
{ {
fn from(matrix_slice: MatrixSlice<'a, T, Dynamic, C, RStride, CStride>) -> Self { fn from(matrix_slice: MatrixView<'a, T, Dynamic, C, RStride, CStride>) -> Self {
matrix_slice.into_owned() matrix_slice.into_owned()
} }
} }
#[cfg(any(feature = "std", feature = "alloc"))] #[cfg(any(feature = "std", feature = "alloc"))]
impl<'a, T, R, RStride, CStride> From<MatrixSlice<'a, T, R, Dynamic, RStride, CStride>> impl<'a, T, R, RStride, CStride> From<MatrixView<'a, T, R, Dynamic, RStride, CStride>>
for Matrix<T, R, Dynamic, VecStorage<T, R, Dynamic>> for Matrix<T, R, Dynamic, VecStorage<T, R, Dynamic>>
where where
T: Scalar, T: Scalar,
@ -324,26 +324,26 @@ where
RStride: Dim, RStride: Dim,
CStride: Dim, CStride: Dim,
{ {
fn from(matrix_slice: MatrixSlice<'a, T, R, Dynamic, RStride, CStride>) -> Self { fn from(matrix_slice: MatrixView<'a, T, R, Dynamic, RStride, CStride>) -> Self {
matrix_slice.into_owned() matrix_slice.into_owned()
} }
} }
impl<'a, T, RStride, CStride, const R: usize, const C: usize> impl<'a, T, RStride, CStride, const R: usize, const C: usize>
From<MatrixSliceMut<'a, T, Const<R>, Const<C>, RStride, CStride>> From<MatrixViewMut<'a, T, Const<R>, Const<C>, RStride, CStride>>
for Matrix<T, Const<R>, Const<C>, ArrayStorage<T, R, C>> for Matrix<T, Const<R>, Const<C>, ArrayStorage<T, R, C>>
where where
T: Scalar, T: Scalar,
RStride: Dim, RStride: Dim,
CStride: Dim, CStride: Dim,
{ {
fn from(matrix_slice: MatrixSliceMut<'a, T, Const<R>, Const<C>, RStride, CStride>) -> Self { fn from(matrix_slice: MatrixViewMut<'a, T, Const<R>, Const<C>, RStride, CStride>) -> Self {
matrix_slice.into_owned() matrix_slice.into_owned()
} }
} }
#[cfg(any(feature = "std", feature = "alloc"))] #[cfg(any(feature = "std", feature = "alloc"))]
impl<'a, T, C, RStride, CStride> From<MatrixSliceMut<'a, T, Dynamic, C, RStride, CStride>> impl<'a, T, C, RStride, CStride> From<MatrixViewMut<'a, T, Dynamic, C, RStride, CStride>>
for Matrix<T, Dynamic, C, VecStorage<T, Dynamic, C>> for Matrix<T, Dynamic, C, VecStorage<T, Dynamic, C>>
where where
T: Scalar, T: Scalar,
@ -351,13 +351,13 @@ where
RStride: Dim, RStride: Dim,
CStride: Dim, CStride: Dim,
{ {
fn from(matrix_slice: MatrixSliceMut<'a, T, Dynamic, C, RStride, CStride>) -> Self { fn from(matrix_slice: MatrixViewMut<'a, T, Dynamic, C, RStride, CStride>) -> Self {
matrix_slice.into_owned() matrix_slice.into_owned()
} }
} }
#[cfg(any(feature = "std", feature = "alloc"))] #[cfg(any(feature = "std", feature = "alloc"))]
impl<'a, T, R, RStride, CStride> From<MatrixSliceMut<'a, T, R, Dynamic, RStride, CStride>> impl<'a, T, R, RStride, CStride> From<MatrixViewMut<'a, T, R, Dynamic, RStride, CStride>>
for Matrix<T, R, Dynamic, VecStorage<T, R, Dynamic>> for Matrix<T, R, Dynamic, VecStorage<T, R, Dynamic>>
where where
T: Scalar, T: Scalar,
@ -365,13 +365,13 @@ where
RStride: Dim, RStride: Dim,
CStride: Dim, CStride: Dim,
{ {
fn from(matrix_slice: MatrixSliceMut<'a, T, R, Dynamic, RStride, CStride>) -> Self { fn from(matrix_slice: MatrixViewMut<'a, T, R, Dynamic, RStride, CStride>) -> Self {
matrix_slice.into_owned() matrix_slice.into_owned()
} }
} }
impl<'a, T, R, C, RSlice, CSlice, RStride, CStride, S> From<&'a Matrix<T, R, C, S>> impl<'a, T, R, C, RSlice, CSlice, RStride, CStride, S> From<&'a Matrix<T, R, C, S>>
for MatrixSlice<'a, T, RSlice, CSlice, RStride, CStride> for MatrixView<'a, T, RSlice, CSlice, RStride, CStride>
where where
T: Scalar, T: Scalar,
R: Dim, R: Dim,
@ -408,7 +408,7 @@ where
} }
impl<'a, T, R, C, RSlice, CSlice, RStride, CStride, S> From<&'a mut Matrix<T, R, C, S>> impl<'a, T, R, C, RSlice, CSlice, RStride, CStride, S> From<&'a mut Matrix<T, R, C, S>>
for MatrixSlice<'a, T, RSlice, CSlice, RStride, CStride> for MatrixView<'a, T, RSlice, CSlice, RStride, CStride>
where where
T: Scalar, T: Scalar,
R: Dim, R: Dim,
@ -445,7 +445,7 @@ where
} }
impl<'a, T, R, C, RSlice, CSlice, RStride, CStride, S> From<&'a mut Matrix<T, R, C, S>> impl<'a, T, R, C, RSlice, CSlice, RStride, CStride, S> From<&'a mut Matrix<T, R, C, S>>
for MatrixSliceMut<'a, T, RSlice, CSlice, RStride, CStride> for MatrixViewMut<'a, T, RSlice, CSlice, RStride, CStride>
where where
T: Scalar, T: Scalar,
R: Dim, R: Dim,

View File

@ -3,7 +3,7 @@
use crate::base::storage::{RawStorage, RawStorageMut}; use crate::base::storage::{RawStorage, RawStorageMut};
use crate::base::{ use crate::base::{
Const, Dim, DimDiff, DimName, DimSub, Dynamic, Matrix, MatrixSlice, MatrixSliceMut, Scalar, U1, Const, Dim, DimDiff, DimName, DimSub, Dynamic, Matrix, MatrixView, MatrixViewMut, Scalar, U1,
}; };
use std::ops; use std::ops;
@ -669,7 +669,7 @@ macro_rules! impl_index_pair {
$( $RConstraintType: $RConstraintBound $(<$( $RConstraintBoundParams $( = $REqBound )*),*>)* ,)* $( $RConstraintType: $RConstraintBound $(<$( $RConstraintBoundParams $( = $REqBound )*),*>)* ,)*
$( $CConstraintType: $CConstraintBound $(<$( $CConstraintBoundParams $( = $CEqBound )*),*>)* ),* $( $CConstraintType: $CConstraintBound $(<$( $CConstraintBoundParams $( = $CEqBound )*),*>)* ),*
{ {
type Output = MatrixSlice<'a, T, $ROut, $COut, S::RStride, S::CStride>; type Output = MatrixView<'a, T, $ROut, $COut, S::RStride, S::CStride>;
#[doc(hidden)] #[doc(hidden)]
#[inline(always)] #[inline(always)]
@ -705,7 +705,7 @@ macro_rules! impl_index_pair {
$( $RConstraintType: $RConstraintBound $(<$( $RConstraintBoundParams $( = $REqBound )*),*>)* ,)* $( $RConstraintType: $RConstraintBound $(<$( $RConstraintBoundParams $( = $REqBound )*),*>)* ,)*
$( $CConstraintType: $CConstraintBound $(<$( $CConstraintBoundParams $( = $CEqBound )*),*>)* ),* $( $CConstraintType: $CConstraintBound $(<$( $CConstraintBoundParams $( = $CEqBound )*),*>)* ),*
{ {
type OutputMut = MatrixSliceMut<'a, T, $ROut, $COut, S::RStride, S::CStride>; type OutputMut = MatrixViewMut<'a, T, $ROut, $COut, S::RStride, S::CStride>;
#[doc(hidden)] #[doc(hidden)]
#[inline(always)] #[inline(always)]

View File

@ -6,7 +6,7 @@ use std::mem;
use crate::base::dimension::{Dim, U1}; use crate::base::dimension::{Dim, U1};
use crate::base::storage::{RawStorage, RawStorageMut}; use crate::base::storage::{RawStorage, RawStorageMut};
use crate::base::{Matrix, MatrixSlice, MatrixSliceMut, Scalar}; use crate::base::{Matrix, MatrixView, MatrixViewMut, Scalar};
macro_rules! iterator { macro_rules! iterator {
(struct $Name:ident for $Storage:ident.$ptr: ident -> $Ptr:ty, $Ref:ty, $SRef: ty) => { (struct $Name:ident for $Storage:ident.$ptr: ident -> $Ptr:ty, $Ref:ty, $SRef: ty) => {
@ -193,7 +193,7 @@ impl<'a, T, R: Dim, C: Dim, S: 'a + RawStorage<T, R, C>> RowIter<'a, T, R, C, S>
} }
impl<'a, T, R: Dim, C: Dim, S: 'a + RawStorage<T, R, C>> Iterator for RowIter<'a, T, R, C, S> { impl<'a, T, R: Dim, C: Dim, S: 'a + RawStorage<T, R, C>> Iterator for RowIter<'a, T, R, C, S> {
type Item = MatrixSlice<'a, T, U1, C, S::RStride, S::CStride>; type Item = MatrixView<'a, T, U1, C, S::RStride, S::CStride>;
#[inline] #[inline]
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
@ -254,7 +254,7 @@ impl<'a, T, R: Dim, C: Dim, S: 'a + RawStorageMut<T, R, C>> RowIterMut<'a, T, R,
impl<'a, T, R: Dim, C: Dim, S: 'a + RawStorageMut<T, R, C>> Iterator impl<'a, T, R: Dim, C: Dim, S: 'a + RawStorageMut<T, R, C>> Iterator
for RowIterMut<'a, T, R, C, S> for RowIterMut<'a, T, R, C, S>
{ {
type Item = MatrixSliceMut<'a, T, U1, C, S::RStride, S::CStride>; type Item = MatrixViewMut<'a, T, U1, C, S::RStride, S::CStride>;
#[inline] #[inline]
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
@ -306,7 +306,7 @@ impl<'a, T, R: Dim, C: Dim, S: 'a + RawStorage<T, R, C>> ColumnIter<'a, T, R, C,
} }
impl<'a, T, R: Dim, C: Dim, S: 'a + RawStorage<T, R, C>> Iterator for ColumnIter<'a, T, R, C, S> { impl<'a, T, R: Dim, C: Dim, S: 'a + RawStorage<T, R, C>> Iterator for ColumnIter<'a, T, R, C, S> {
type Item = MatrixSlice<'a, T, R, U1, S::RStride, S::CStride>; type Item = MatrixView<'a, T, R, U1, S::RStride, S::CStride>;
#[inline] #[inline]
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
@ -367,7 +367,7 @@ impl<'a, T, R: Dim, C: Dim, S: 'a + RawStorageMut<T, R, C>> ColumnIterMut<'a, T,
impl<'a, T, R: Dim, C: Dim, S: 'a + RawStorageMut<T, R, C>> Iterator impl<'a, T, R: Dim, C: Dim, S: 'a + RawStorageMut<T, R, C>> Iterator
for ColumnIterMut<'a, T, R, C, S> for ColumnIterMut<'a, T, R, C, S>
{ {
type Item = MatrixSliceMut<'a, T, R, U1, S::RStride, S::CStride>; type Item = MatrixViewMut<'a, T, R, U1, S::RStride, S::CStride>;
#[inline] #[inline]
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {

View File

@ -285,7 +285,7 @@ impl<T, R: Dim, C: Dim, S: RawStorage<T, R, C>> Matrix<T, R, C, S> {
} }
macro_rules! matrix_slice_impl ( macro_rules! matrix_slice_impl (
($me: ident: $Me: ty, $MatrixSlice: ident, $ViewStorage: ident, $Storage: ident.$get_addr: ident (), $data: expr; ($me: ident: $Me: ty, $MatrixView: ident, $ViewStorage: ident, $Storage: ident.$get_addr: ident (), $data: expr;
$row: ident, $row: ident,
$row_part: ident, $row_part: ident,
$rows: ident, $rows: ident,
@ -317,20 +317,20 @@ macro_rules! matrix_slice_impl (
*/ */
/// Returns a slice containing the i-th row of this matrix. /// Returns a slice containing the i-th row of this matrix.
#[inline] #[inline]
pub fn $row($me: $Me, i: usize) -> $MatrixSlice<'_, T, U1, C, S::RStride, S::CStride> { pub fn $row($me: $Me, i: usize) -> $MatrixView<'_, T, U1, C, S::RStride, S::CStride> {
$me.$fixed_rows::<1>(i) $me.$fixed_rows::<1>(i)
} }
/// Returns a slice containing the `n` first elements of the i-th row of this matrix. /// Returns a slice containing the `n` first elements of the i-th row of this matrix.
#[inline] #[inline]
pub fn $row_part($me: $Me, i: usize, n: usize) -> $MatrixSlice<'_, T, U1, Dynamic, S::RStride, S::CStride> { pub fn $row_part($me: $Me, i: usize, n: usize) -> $MatrixView<'_, T, U1, Dynamic, S::RStride, S::CStride> {
$me.$generic_slice((i, 0), (Const::<1>, Dynamic::new(n))) $me.$generic_slice((i, 0), (Const::<1>, Dynamic::new(n)))
} }
/// Extracts from this matrix a set of consecutive rows. /// Extracts from this matrix a set of consecutive rows.
#[inline] #[inline]
pub fn $rows($me: $Me, first_row: usize, nrows: usize) pub fn $rows($me: $Me, first_row: usize, nrows: usize)
-> $MatrixSlice<'_, T, Dynamic, C, S::RStride, S::CStride> { -> $MatrixView<'_, T, Dynamic, C, S::RStride, S::CStride> {
$me.$rows_generic(first_row, Dynamic::new(nrows)) $me.$rows_generic(first_row, Dynamic::new(nrows))
} }
@ -338,7 +338,7 @@ macro_rules! matrix_slice_impl (
/// Extracts from this matrix a set of consecutive rows regularly skipping `step` rows. /// Extracts from this matrix a set of consecutive rows regularly skipping `step` rows.
#[inline] #[inline]
pub fn $rows_with_step($me: $Me, first_row: usize, nrows: usize, step: usize) pub fn $rows_with_step($me: $Me, first_row: usize, nrows: usize, step: usize)
-> $MatrixSlice<'_, T, Dynamic, C, Dynamic, S::CStride> { -> $MatrixView<'_, T, Dynamic, C, Dynamic, S::CStride> {
$me.$rows_generic_with_step(first_row, Dynamic::new(nrows), step) $me.$rows_generic_with_step(first_row, Dynamic::new(nrows), step)
} }
@ -346,7 +346,7 @@ macro_rules! matrix_slice_impl (
/// Extracts a compile-time number of consecutive rows from this matrix. /// Extracts a compile-time number of consecutive rows from this matrix.
#[inline] #[inline]
pub fn $fixed_rows<const RSLICE: usize>($me: $Me, first_row: usize) pub fn $fixed_rows<const RSLICE: usize>($me: $Me, first_row: usize)
-> $MatrixSlice<'_, T, Const<RSLICE>, C, S::RStride, S::CStride> { -> $MatrixView<'_, T, Const<RSLICE>, C, S::RStride, S::CStride> {
$me.$rows_generic(first_row, Const::<RSLICE>) $me.$rows_generic(first_row, Const::<RSLICE>)
} }
@ -355,7 +355,7 @@ macro_rules! matrix_slice_impl (
/// rows. /// rows.
#[inline] #[inline]
pub fn $fixed_rows_with_step<const RSLICE: usize>($me: $Me, first_row: usize, step: usize) pub fn $fixed_rows_with_step<const RSLICE: usize>($me: $Me, first_row: usize, step: usize)
-> $MatrixSlice<'_, T, Const<RSLICE>, C, Dynamic, S::CStride> { -> $MatrixView<'_, T, Const<RSLICE>, C, Dynamic, S::CStride> {
$me.$rows_generic_with_step(first_row, Const::<RSLICE>, step) $me.$rows_generic_with_step(first_row, Const::<RSLICE>, step)
} }
@ -364,7 +364,7 @@ macro_rules! matrix_slice_impl (
/// argument may or may not be values known at compile-time. /// argument may or may not be values known at compile-time.
#[inline] #[inline]
pub fn $rows_generic<RSlice: Dim>($me: $Me, row_start: usize, nrows: RSlice) pub fn $rows_generic<RSlice: Dim>($me: $Me, row_start: usize, nrows: RSlice)
-> $MatrixSlice<'_, T, RSlice, C, S::RStride, S::CStride> { -> $MatrixView<'_, T, RSlice, C, S::RStride, S::CStride> {
let my_shape = $me.shape_generic(); let my_shape = $me.shape_generic();
$me.assert_slice_index((row_start, 0), (nrows.value(), my_shape.1.value()), (0, 0)); $me.assert_slice_index((row_start, 0), (nrows.value(), my_shape.1.value()), (0, 0));
@ -381,7 +381,7 @@ macro_rules! matrix_slice_impl (
/// argument may or may not be values known at compile-time. /// argument may or may not be values known at compile-time.
#[inline] #[inline]
pub fn $rows_generic_with_step<RSlice>($me: $Me, row_start: usize, nrows: RSlice, step: usize) pub fn $rows_generic_with_step<RSlice>($me: $Me, row_start: usize, nrows: RSlice, step: usize)
-> $MatrixSlice<'_, T, RSlice, C, Dynamic, S::CStride> -> $MatrixView<'_, T, RSlice, C, Dynamic, S::CStride>
where RSlice: Dim { where RSlice: Dim {
let my_shape = $me.shape_generic(); let my_shape = $me.shape_generic();
@ -404,20 +404,20 @@ macro_rules! matrix_slice_impl (
*/ */
/// Returns a slice containing the i-th column of this matrix. /// Returns a slice containing the i-th column of this matrix.
#[inline] #[inline]
pub fn $column($me: $Me, i: usize) -> $MatrixSlice<'_, T, R, U1, S::RStride, S::CStride> { pub fn $column($me: $Me, i: usize) -> $MatrixView<'_, T, R, U1, S::RStride, S::CStride> {
$me.$fixed_columns::<1>(i) $me.$fixed_columns::<1>(i)
} }
/// Returns a slice containing the `n` first elements of the i-th column of this matrix. /// Returns a slice containing the `n` first elements of the i-th column of this matrix.
#[inline] #[inline]
pub fn $column_part($me: $Me, i: usize, n: usize) -> $MatrixSlice<'_, T, Dynamic, U1, S::RStride, S::CStride> { pub fn $column_part($me: $Me, i: usize, n: usize) -> $MatrixView<'_, T, Dynamic, U1, S::RStride, S::CStride> {
$me.$generic_slice((0, i), (Dynamic::new(n), Const::<1>)) $me.$generic_slice((0, i), (Dynamic::new(n), Const::<1>))
} }
/// Extracts from this matrix a set of consecutive columns. /// Extracts from this matrix a set of consecutive columns.
#[inline] #[inline]
pub fn $columns($me: $Me, first_col: usize, ncols: usize) pub fn $columns($me: $Me, first_col: usize, ncols: usize)
-> $MatrixSlice<'_, T, R, Dynamic, S::RStride, S::CStride> { -> $MatrixView<'_, T, R, Dynamic, S::RStride, S::CStride> {
$me.$columns_generic(first_col, Dynamic::new(ncols)) $me.$columns_generic(first_col, Dynamic::new(ncols))
} }
@ -426,7 +426,7 @@ macro_rules! matrix_slice_impl (
/// columns. /// columns.
#[inline] #[inline]
pub fn $columns_with_step($me: $Me, first_col: usize, ncols: usize, step: usize) pub fn $columns_with_step($me: $Me, first_col: usize, ncols: usize, step: usize)
-> $MatrixSlice<'_, T, R, Dynamic, S::RStride, Dynamic> { -> $MatrixView<'_, T, R, Dynamic, S::RStride, Dynamic> {
$me.$columns_generic_with_step(first_col, Dynamic::new(ncols), step) $me.$columns_generic_with_step(first_col, Dynamic::new(ncols), step)
} }
@ -434,7 +434,7 @@ macro_rules! matrix_slice_impl (
/// Extracts a compile-time number of consecutive columns from this matrix. /// Extracts a compile-time number of consecutive columns from this matrix.
#[inline] #[inline]
pub fn $fixed_columns<const CSLICE: usize>($me: $Me, first_col: usize) pub fn $fixed_columns<const CSLICE: usize>($me: $Me, first_col: usize)
-> $MatrixSlice<'_, T, R, Const<CSLICE>, S::RStride, S::CStride> { -> $MatrixView<'_, T, R, Const<CSLICE>, S::RStride, S::CStride> {
$me.$columns_generic(first_col, Const::<CSLICE>) $me.$columns_generic(first_col, Const::<CSLICE>)
} }
@ -443,7 +443,7 @@ macro_rules! matrix_slice_impl (
/// `step` columns. /// `step` columns.
#[inline] #[inline]
pub fn $fixed_columns_with_step<const CSLICE: usize>($me: $Me, first_col: usize, step: usize) pub fn $fixed_columns_with_step<const CSLICE: usize>($me: $Me, first_col: usize, step: usize)
-> $MatrixSlice<'_, T, R, Const<CSLICE>, S::RStride, Dynamic> { -> $MatrixView<'_, T, R, Const<CSLICE>, S::RStride, Dynamic> {
$me.$columns_generic_with_step(first_col, Const::<CSLICE>, step) $me.$columns_generic_with_step(first_col, Const::<CSLICE>, step)
} }
@ -452,7 +452,7 @@ macro_rules! matrix_slice_impl (
/// known at compile-time. /// known at compile-time.
#[inline] #[inline]
pub fn $columns_generic<CSlice: Dim>($me: $Me, first_col: usize, ncols: CSlice) pub fn $columns_generic<CSlice: Dim>($me: $Me, first_col: usize, ncols: CSlice)
-> $MatrixSlice<'_, T, R, CSlice, S::RStride, S::CStride> { -> $MatrixView<'_, T, R, CSlice, S::RStride, S::CStride> {
let my_shape = $me.shape_generic(); let my_shape = $me.shape_generic();
$me.assert_slice_index((0, first_col), (my_shape.0.value(), ncols.value()), (0, 0)); $me.assert_slice_index((0, first_col), (my_shape.0.value(), ncols.value()), (0, 0));
@ -469,7 +469,7 @@ macro_rules! matrix_slice_impl (
/// or may not be values known at compile-time. /// or may not be values known at compile-time.
#[inline] #[inline]
pub fn $columns_generic_with_step<CSlice: Dim>($me: $Me, first_col: usize, ncols: CSlice, step: usize) pub fn $columns_generic_with_step<CSlice: Dim>($me: $Me, first_col: usize, ncols: CSlice, step: usize)
-> $MatrixSlice<'_, T, R, CSlice, S::RStride, Dynamic> { -> $MatrixView<'_, T, R, CSlice, S::RStride, Dynamic> {
let my_shape = $me.shape_generic(); let my_shape = $me.shape_generic();
let my_strides = $me.data.strides(); let my_strides = $me.data.strides();
@ -494,7 +494,7 @@ macro_rules! matrix_slice_impl (
/// consecutive elements. /// consecutive elements.
#[inline] #[inline]
pub fn $slice($me: $Me, start: (usize, usize), shape: (usize, usize)) pub fn $slice($me: $Me, start: (usize, usize), shape: (usize, usize))
-> $MatrixSlice<'_, T, Dynamic, Dynamic, S::RStride, S::CStride> { -> $MatrixView<'_, T, Dynamic, Dynamic, S::RStride, S::CStride> {
$me.assert_slice_index(start, shape, (0, 0)); $me.assert_slice_index(start, shape, (0, 0));
let shape = (Dynamic::new(shape.0), Dynamic::new(shape.1)); let shape = (Dynamic::new(shape.0), Dynamic::new(shape.1));
@ -512,7 +512,7 @@ macro_rules! matrix_slice_impl (
/// original matrix. /// original matrix.
#[inline] #[inline]
pub fn $slice_with_steps($me: $Me, start: (usize, usize), shape: (usize, usize), steps: (usize, usize)) pub fn $slice_with_steps($me: $Me, start: (usize, usize), shape: (usize, usize), steps: (usize, usize))
-> $MatrixSlice<'_, T, Dynamic, Dynamic, Dynamic, Dynamic> { -> $MatrixView<'_, T, Dynamic, Dynamic, Dynamic, Dynamic> {
let shape = (Dynamic::new(shape.0), Dynamic::new(shape.1)); let shape = (Dynamic::new(shape.0), Dynamic::new(shape.1));
$me.$generic_slice_with_steps(start, shape, steps) $me.$generic_slice_with_steps(start, shape, steps)
@ -522,7 +522,7 @@ macro_rules! matrix_slice_impl (
/// CSlice::dim())` consecutive components. /// CSlice::dim())` consecutive components.
#[inline] #[inline]
pub fn $fixed_slice<const RSLICE: usize, const CSLICE: usize>($me: $Me, irow: usize, icol: usize) pub fn $fixed_slice<const RSLICE: usize, const CSLICE: usize>($me: $Me, irow: usize, icol: usize)
-> $MatrixSlice<'_, T, Const<RSLICE>, Const<CSLICE>, S::RStride, S::CStride> { -> $MatrixView<'_, T, Const<RSLICE>, Const<CSLICE>, S::RStride, S::CStride> {
$me.assert_slice_index((irow, icol), (RSLICE, CSLICE), (0, 0)); $me.assert_slice_index((irow, icol), (RSLICE, CSLICE), (0, 0));
let shape = (Const::<RSLICE>, Const::<CSLICE>); let shape = (Const::<RSLICE>, Const::<CSLICE>);
@ -539,7 +539,7 @@ macro_rules! matrix_slice_impl (
/// the original matrix. /// the original matrix.
#[inline] #[inline]
pub fn $fixed_slice_with_steps<const RSLICE: usize, const CSLICE: usize>($me: $Me, start: (usize, usize), steps: (usize, usize)) pub fn $fixed_slice_with_steps<const RSLICE: usize, const CSLICE: usize>($me: $Me, start: (usize, usize), steps: (usize, usize))
-> $MatrixSlice<'_, T, Const<RSLICE>, Const<CSLICE>, Dynamic, Dynamic> { -> $MatrixView<'_, T, Const<RSLICE>, Const<CSLICE>, Dynamic, Dynamic> {
let shape = (Const::<RSLICE>, Const::<CSLICE>); let shape = (Const::<RSLICE>, Const::<CSLICE>);
$me.$generic_slice_with_steps(start, shape, steps) $me.$generic_slice_with_steps(start, shape, steps)
} }
@ -547,7 +547,7 @@ macro_rules! matrix_slice_impl (
/// Creates a slice that may or may not have a fixed size and stride. /// Creates a slice that may or may not have a fixed size and stride.
#[inline] #[inline]
pub fn $generic_slice<RSlice, CSlice>($me: $Me, start: (usize, usize), shape: (RSlice, CSlice)) pub fn $generic_slice<RSlice, CSlice>($me: $Me, start: (usize, usize), shape: (RSlice, CSlice))
-> $MatrixSlice<'_, T, RSlice, CSlice, S::RStride, S::CStride> -> $MatrixView<'_, T, RSlice, CSlice, S::RStride, S::CStride>
where RSlice: Dim, where RSlice: Dim,
CSlice: Dim { CSlice: Dim {
@ -565,7 +565,7 @@ macro_rules! matrix_slice_impl (
start: (usize, usize), start: (usize, usize),
shape: (RSlice, CSlice), shape: (RSlice, CSlice),
steps: (usize, usize)) steps: (usize, usize))
-> $MatrixSlice<'_, T, RSlice, CSlice, Dynamic, Dynamic> -> $MatrixView<'_, T, RSlice, CSlice, Dynamic, Dynamic>
where RSlice: Dim, where RSlice: Dim,
CSlice: Dim { CSlice: Dim {
@ -591,8 +591,8 @@ macro_rules! matrix_slice_impl (
/// Panics if the ranges overlap or if the first range is empty. /// Panics if the ranges overlap or if the first range is empty.
#[inline] #[inline]
pub fn $rows_range_pair<Range1: SliceRange<R>, Range2: SliceRange<R>>($me: $Me, r1: Range1, r2: Range2) pub fn $rows_range_pair<Range1: SliceRange<R>, Range2: SliceRange<R>>($me: $Me, r1: Range1, r2: Range2)
-> ($MatrixSlice<'_, T, Range1::Size, C, S::RStride, S::CStride>, -> ($MatrixView<'_, T, Range1::Size, C, S::RStride, S::CStride>,
$MatrixSlice<'_, T, Range2::Size, C, S::RStride, S::CStride>) { $MatrixView<'_, T, Range2::Size, C, S::RStride, S::CStride>) {
let (nrows, ncols) = $me.shape_generic(); let (nrows, ncols) = $me.shape_generic();
let strides = $me.data.strides(); let strides = $me.data.strides();
@ -627,8 +627,8 @@ macro_rules! matrix_slice_impl (
/// Panics if the ranges overlap or if the first range is empty. /// Panics if the ranges overlap or if the first range is empty.
#[inline] #[inline]
pub fn $columns_range_pair<Range1: SliceRange<C>, Range2: SliceRange<C>>($me: $Me, r1: Range1, r2: Range2) pub fn $columns_range_pair<Range1: SliceRange<C>, Range2: SliceRange<C>>($me: $Me, r1: Range1, r2: Range2)
-> ($MatrixSlice<'_, T, R, Range1::Size, S::RStride, S::CStride>, -> ($MatrixView<'_, T, R, Range1::Size, S::RStride, S::CStride>,
$MatrixSlice<'_, T, R, Range2::Size, S::RStride, S::CStride>) { $MatrixView<'_, T, R, Range2::Size, S::RStride, S::CStride>) {
let (nrows, ncols) = $me.shape_generic(); let (nrows, ncols) = $me.shape_generic();
let strides = $me.data.strides(); let strides = $me.data.strides();
@ -661,16 +661,37 @@ macro_rules! matrix_slice_impl (
); );
/// A matrix slice. /// A matrix slice.
///
/// This type alias exists only for legacy purposes and is deprecated. It will be removed
/// in a future release. Please use [`MatrixView`] instead.
/// See [issue #1076](https://github.com/dimforge/nalgebra/issues/1076)
/// for the rationale.
#[deprecated = "Use MatrixView instead."]
pub type MatrixSlice<'a, T, R, C, RStride = U1, CStride = R> = pub type MatrixSlice<'a, T, R, C, RStride = U1, CStride = R> =
MatrixView<'a, T, R, C, RStride, CStride>;
/// A matrix view.
pub type MatrixView<'a, T, R, C, RStride = U1, CStride = R> =
Matrix<T, R, C, ViewStorage<'a, T, R, C, RStride, CStride>>; Matrix<T, R, C, ViewStorage<'a, T, R, C, RStride, CStride>>;
/// A mutable matrix slice. /// A mutable matrix slice.
///
/// This type alias exists only for legacy purposes and is deprecated. It will be removed
/// in a future release. Please use [`MatrixViewMut`] instead.
/// See [issue #1076](https://github.com/dimforge/nalgebra/issues/1076)
/// for the rationale.
#[deprecated = "Use MatrixViewMut instead."]
pub type MatrixSliceMut<'a, T, R, C, RStride = U1, CStride = R> = pub type MatrixSliceMut<'a, T, R, C, RStride = U1, CStride = R> =
MatrixViewMut<'a, T, R, C, RStride, CStride>;
/// A mutable matrix view.
pub type MatrixViewMut<'a, T, R, C, RStride = U1, CStride = R> =
Matrix<T, R, C, ViewStorageMut<'a, T, R, C, RStride, CStride>>; Matrix<T, R, C, ViewStorageMut<'a, T, R, C, RStride, CStride>>;
/// # Slicing based on index and length /// # Slicing based on index and length
impl<T, R: Dim, C: Dim, S: RawStorage<T, R, C>> Matrix<T, R, C, S> { impl<T, R: Dim, C: Dim, S: RawStorage<T, R, C>> Matrix<T, R, C, S> {
matrix_slice_impl!( matrix_slice_impl!(
self: &Self, MatrixSlice, ViewStorage, RawStorage.get_address_unchecked(), &self.data; self: &Self, MatrixView, ViewStorage, RawStorage.get_address_unchecked(), &self.data;
row, row,
row_part, row_part,
rows, rows,
@ -700,7 +721,7 @@ impl<T, R: Dim, C: Dim, S: RawStorage<T, R, C>> Matrix<T, R, C, S> {
/// # Mutable slicing based on index and length /// # Mutable slicing based on index and length
impl<T, R: Dim, C: Dim, S: RawStorageMut<T, R, C>> Matrix<T, R, C, S> { impl<T, R: Dim, C: Dim, S: RawStorageMut<T, R, C>> Matrix<T, R, C, S> {
matrix_slice_impl!( matrix_slice_impl!(
self: &mut Self, MatrixSliceMut, ViewStorageMut, RawStorageMut.get_address_unchecked_mut(), &mut self.data; self: &mut Self, MatrixViewMut, ViewStorageMut, RawStorageMut.get_address_unchecked_mut(), &mut self.data;
row_mut, row_mut,
row_part_mut, row_part_mut,
rows_mut, rows_mut,
@ -872,7 +893,7 @@ impl<T, R: Dim, C: Dim, S: RawStorage<T, R, C>> Matrix<T, R, C, S> {
&self, &self,
rows: RowRange, rows: RowRange,
cols: ColRange, cols: ColRange,
) -> MatrixSlice<'_, T, RowRange::Size, ColRange::Size, S::RStride, S::CStride> ) -> MatrixView<'_, T, RowRange::Size, ColRange::Size, S::RStride, S::CStride>
where where
RowRange: SliceRange<R>, RowRange: SliceRange<R>,
ColRange: SliceRange<C>, ColRange: SliceRange<C>,
@ -890,7 +911,7 @@ impl<T, R: Dim, C: Dim, S: RawStorage<T, R, C>> Matrix<T, R, C, S> {
pub fn rows_range<RowRange: SliceRange<R>>( pub fn rows_range<RowRange: SliceRange<R>>(
&self, &self,
rows: RowRange, rows: RowRange,
) -> MatrixSlice<'_, T, RowRange::Size, C, S::RStride, S::CStride> { ) -> MatrixView<'_, T, RowRange::Size, C, S::RStride, S::CStride> {
self.slice_range(rows, ..) self.slice_range(rows, ..)
} }
@ -900,7 +921,7 @@ impl<T, R: Dim, C: Dim, S: RawStorage<T, R, C>> Matrix<T, R, C, S> {
pub fn columns_range<ColRange: SliceRange<C>>( pub fn columns_range<ColRange: SliceRange<C>>(
&self, &self,
cols: ColRange, cols: ColRange,
) -> MatrixSlice<'_, T, R, ColRange::Size, S::RStride, S::CStride> { ) -> MatrixView<'_, T, R, ColRange::Size, S::RStride, S::CStride> {
self.slice_range(.., cols) self.slice_range(.., cols)
} }
} }
@ -914,7 +935,7 @@ impl<T, R: Dim, C: Dim, S: RawStorageMut<T, R, C>> Matrix<T, R, C, S> {
&mut self, &mut self,
rows: RowRange, rows: RowRange,
cols: ColRange, cols: ColRange,
) -> MatrixSliceMut<'_, T, RowRange::Size, ColRange::Size, S::RStride, S::CStride> ) -> MatrixViewMut<'_, T, RowRange::Size, ColRange::Size, S::RStride, S::CStride>
where where
RowRange: SliceRange<R>, RowRange: SliceRange<R>,
ColRange: SliceRange<C>, ColRange: SliceRange<C>,
@ -931,7 +952,7 @@ impl<T, R: Dim, C: Dim, S: RawStorageMut<T, R, C>> Matrix<T, R, C, S> {
pub fn rows_range_mut<RowRange: SliceRange<R>>( pub fn rows_range_mut<RowRange: SliceRange<R>>(
&mut self, &mut self,
rows: RowRange, rows: RowRange,
) -> MatrixSliceMut<'_, T, RowRange::Size, C, S::RStride, S::CStride> { ) -> MatrixViewMut<'_, T, RowRange::Size, C, S::RStride, S::CStride> {
self.slice_range_mut(rows, ..) self.slice_range_mut(rows, ..)
} }
@ -940,20 +961,20 @@ impl<T, R: Dim, C: Dim, S: RawStorageMut<T, R, C>> Matrix<T, R, C, S> {
pub fn columns_range_mut<ColRange: SliceRange<C>>( pub fn columns_range_mut<ColRange: SliceRange<C>>(
&mut self, &mut self,
cols: ColRange, cols: ColRange,
) -> MatrixSliceMut<'_, T, R, ColRange::Size, S::RStride, S::CStride> { ) -> MatrixViewMut<'_, T, R, ColRange::Size, S::RStride, S::CStride> {
self.slice_range_mut(.., cols) self.slice_range_mut(.., cols)
} }
} }
impl<'a, T, R, C, RStride, CStride> From<MatrixSliceMut<'a, T, R, C, RStride, CStride>> impl<'a, T, R, C, RStride, CStride> From<MatrixViewMut<'a, T, R, C, RStride, CStride>>
for MatrixSlice<'a, T, R, C, RStride, CStride> for MatrixView<'a, T, R, C, RStride, CStride>
where where
R: Dim, R: Dim,
C: Dim, C: Dim,
RStride: Dim, RStride: Dim,
CStride: Dim, CStride: Dim,
{ {
fn from(slice_mut: MatrixSliceMut<'a, T, R, C, RStride, CStride>) -> Self { fn from(slice_mut: MatrixViewMut<'a, T, R, C, RStride, CStride>) -> Self {
let data = ViewStorage { let data = ViewStorage {
ptr: slice_mut.data.ptr, ptr: slice_mut.data.ptr,
shape: slice_mut.data.shape, shape: slice_mut.data.shape,

View File

@ -14,7 +14,7 @@ use simba::simd::{SimdBool, SimdOption, SimdRealField};
use crate::base::dimension::{U1, U3, U4}; use crate::base::dimension::{U1, U3, U4};
use crate::base::storage::{CStride, RStride}; use crate::base::storage::{CStride, RStride};
use crate::base::{ use crate::base::{
Matrix3, Matrix4, MatrixSlice, MatrixSliceMut, Normed, Scalar, Unit, Vector3, Vector4, Matrix3, Matrix4, MatrixView, MatrixViewMut, Normed, Scalar, Unit, Vector3, Vector4,
}; };
use crate::geometry::{Point3, Rotation}; use crate::geometry::{Point3, Rotation};
@ -191,7 +191,7 @@ where
/// ``` /// ```
#[inline] #[inline]
#[must_use] #[must_use]
pub fn vector(&self) -> MatrixSlice<'_, T, U3, U1, RStride<T, U4, U1>, CStride<T, U4, U1>> { pub fn vector(&self) -> MatrixView<'_, T, U3, U1, RStride<T, U4, U1>, CStride<T, U4, U1>> {
self.coords.fixed_rows::<3>(0) self.coords.fixed_rows::<3>(0)
} }
@ -584,7 +584,7 @@ where
#[inline] #[inline]
pub fn vector_mut( pub fn vector_mut(
&mut self, &mut self,
) -> MatrixSliceMut<'_, T, U3, U1, RStride<T, U4, U1>, CStride<T, U4, U1>> { ) -> MatrixViewMut<'_, T, U3, U1, RStride<T, U4, U1>, CStride<T, U4, U1>> {
self.coords.fixed_rows_mut::<3>(0) self.coords.fixed_rows_mut::<3>(0)
} }