Use view* instead of slice* methods in src/

This commit is contained in:
Andreas Longva 2022-11-14 14:14:42 +01:00
parent 0319d236af
commit 34f4537376
28 changed files with 125 additions and 125 deletions

View File

@ -393,7 +393,7 @@ where
let col2 = a.column(0);
let val = unsafe { x.vget_unchecked(0).clone() };
self.axpy(alpha.clone() * val, &col2, beta);
self[0] += alpha.clone() * dot(&a.slice_range(1.., 0), &x.rows_range(1..));
self[0] += alpha.clone() * dot(&a.view_range(1.., 0), &x.rows_range(1..));
for j in 1..dim2 {
let col2 = a.column(j);
@ -892,7 +892,7 @@ where
let val = unsafe { conjugate(y.vget_unchecked(j).clone()) };
let subdim = Dynamic::new(dim1 - j);
// TODO: avoid bound checks.
self.generic_slice_mut((j, j), (subdim, Const::<1>)).axpy(
self.generic_view_mut((j, j), (subdim, Const::<1>)).axpy(
alpha.clone() * val,
&x.rows_range(j..),
beta.clone(),

View File

@ -59,7 +59,7 @@ where
SB: Storage<T, DimNameDiff<D, U1>>,
{
let mut res = Self::identity();
res.generic_slice_mut(
res.generic_view_mut(
(0, D::dim() - 1),
(DimNameDiff::<D, U1>::name(), Const::<1>),
)
@ -382,19 +382,19 @@ impl<T: Scalar + Zero + One + ClosedMul + ClosedAdd, D: DimName, S: Storage<T, D
DefaultAllocator: Allocator<T, DimNameDiff<D, U1>>,
{
let scale = self
.generic_slice(
.generic_view(
(D::dim() - 1, 0),
(Const::<1>, DimNameDiff::<D, U1>::name()),
)
.tr_dot(shift);
let post_translation = self.generic_slice(
let post_translation = self.generic_view(
(0, 0),
(DimNameDiff::<D, U1>::name(), DimNameDiff::<D, U1>::name()),
) * shift;
self[(D::dim() - 1, D::dim() - 1)] += scale;
let mut translation = self.generic_slice_mut(
let mut translation = self.generic_view_mut(
(0, D::dim() - 1),
(DimNameDiff::<D, U1>::name(), Const::<1>),
);
@ -415,11 +415,11 @@ where
&self,
v: &OVector<T, DimNameDiff<D, U1>>,
) -> OVector<T, DimNameDiff<D, U1>> {
let transform = self.generic_slice(
let transform = self.generic_view(
(0, 0),
(DimNameDiff::<D, U1>::name(), DimNameDiff::<D, U1>::name()),
);
let normalizer = self.generic_slice(
let normalizer = self.generic_view(
(D::dim() - 1, 0),
(Const::<1>, DimNameDiff::<D, U1>::name()),
);
@ -437,9 +437,9 @@ impl<T: RealField, S: Storage<T, Const<3>, Const<3>>> SquareMatrix<T, Const<3>,
/// Transforms the given point, assuming the matrix `self` uses homogeneous coordinates.
#[inline]
pub fn transform_point(&self, pt: &Point<T, 2>) -> Point<T, 2> {
let transform = self.fixed_slice::<2, 2>(0, 0);
let translation = self.fixed_slice::<2, 1>(0, 2);
let normalizer = self.fixed_slice::<1, 2>(2, 0);
let transform = self.fixed_view::<2, 2>(0, 0);
let translation = self.fixed_view::<2, 1>(0, 2);
let normalizer = self.fixed_view::<1, 2>(2, 0);
let n = normalizer.tr_dot(&pt.coords) + unsafe { self.get_unchecked((2, 2)).clone() };
if !n.is_zero() {
@ -454,9 +454,9 @@ impl<T: RealField, S: Storage<T, Const<4>, Const<4>>> SquareMatrix<T, Const<4>,
/// Transforms the given point, assuming the matrix `self` uses homogeneous coordinates.
#[inline]
pub fn transform_point(&self, pt: &Point<T, 3>) -> Point<T, 3> {
let transform = self.fixed_slice::<3, 3>(0, 0);
let translation = self.fixed_slice::<3, 1>(0, 3);
let normalizer = self.fixed_slice::<1, 3>(3, 0);
let transform = self.fixed_view::<3, 3>(0, 0);
let translation = self.fixed_view::<3, 1>(0, 3);
let normalizer = self.fixed_view::<1, 3>(3, 0);
let n = normalizer.tr_dot(&pt.coords) + unsafe { self.get_unchecked((3, 3)).clone() };
if !n.is_zero() {

View File

@ -938,7 +938,7 @@ impl<T: Scalar, R: Dim, C: Dim, S: Storage<T, R, C>> Matrix<T, R, C, S> {
}
if new_nrows.value() > nrows {
res.slice_range_mut(nrows.., ..cmp::min(ncols, new_ncols.value()))
res.view_range_mut(nrows.., ..cmp::min(ncols, new_ncols.value()))
.fill_with(|| MaybeUninit::new(val.clone()));
}

View File

@ -446,7 +446,7 @@ impl<T, R: Dim, C: Dim, S: RawStorage<T, R, C>> Matrix<T, R, C, S> {
/// ```
/// # use nalgebra::DMatrix;
/// let mat = DMatrix::<f32>::zeros(10, 10);
/// let slice = mat.slice_with_steps((0, 0), (5, 3), (1, 2));
/// let view = mat.view_with_steps((0, 0), (5, 3), (1, 2));
/// // The column strides is the number of steps (here 2) multiplied by the corresponding dimension.
/// assert_eq!(mat.strides(), (1, 10));
/// ```
@ -1633,7 +1633,7 @@ impl<T: Scalar + Zero + One, D: DimAdd<U1> + IsNotStaticOne, S: RawStorage<T, D,
);
let dim = DimSum::<D, U1>::from_usize(self.nrows() + 1);
let mut res = OMatrix::identity_generic(dim, dim);
res.generic_slice_mut::<D, D>((0, 0), self.shape_generic())
res.generic_view_mut::<D, D>((0, 0), self.shape_generic())
.copy_from(self);
res
}
@ -1661,7 +1661,7 @@ impl<T: Scalar + Zero, D: DimAdd<U1>, S: RawStorage<T, D>> Vector<T, D, S> {
{
if v[v.len() - 1].is_zero() {
let nrows = D::from_usize(v.len() - 1);
Some(v.generic_slice((0, 0), (nrows, Const::<1>)).into_owned())
Some(v.generic_view((0, 0), (nrows, Const::<1>)).into_owned())
} else {
None
}
@ -1681,7 +1681,7 @@ impl<T: Scalar, D: DimAdd<U1>, S: RawStorage<T, D>> Vector<T, D, S> {
let mut res = Matrix::uninit(hnrows, Const::<1>);
// This is basically a copy_from except that we warp the copied
// values into MaybeUninit.
res.generic_slice_mut((0, 0), self.shape_generic())
res.generic_view_mut((0, 0), self.shape_generic())
.zip_apply(self, |out, e| *out = MaybeUninit::new(e));
res[(len, 0)] = MaybeUninit::new(element);

View File

@ -324,7 +324,7 @@ macro_rules! matrix_view_impl (
/// Returns a view containing the `n` first elements of the i-th row of this matrix.
#[inline]
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_view((i, 0), (Const::<1>, Dynamic::new(n)))
}
/// Extracts from this matrix a set of consecutive rows.
@ -961,7 +961,7 @@ impl<T, R: Dim, C: Dim, S: RawStorage<T, R, C>> Matrix<T, R, C, S> {
ColRange: SliceRange<C>,
{
let (nrows, ncols) = self.shape_generic();
self.generic_slice(
self.generic_view(
(rows.begin(nrows), cols.begin(ncols)),
(rows.size(nrows), cols.size(ncols)),
)

View File

@ -428,7 +428,7 @@ impl<T: SimdRealField, R, const D: usize> Isometry<T, R, D> {
DefaultAllocator: Allocator<T, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>,
{
let mut res: OMatrix<T, _, _> = crate::convert_ref(&self.rotation);
res.fixed_slice_mut::<D, 1>(0, D)
res.fixed_view_mut::<D, 1>(0, D)
.copy_from(&self.translation.vector);
res

View File

@ -153,8 +153,8 @@ where
#[inline]
fn is_in_subset(m: &OMatrix<T2, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>) -> bool {
let rot = m.fixed_slice::<D, D>(0, 0);
let bottom = m.fixed_slice::<1, D>(D, 0);
let rot = m.fixed_view::<D, D>(0, 0);
let bottom = m.fixed_view::<1, D>(D, 0);
// Scalar types agree.
m.iter().all(|e| SupersetOf::<T1>::is_in_subset(e)) &&
@ -168,7 +168,7 @@ where
fn from_superset_unchecked(
m: &OMatrix<T2, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>,
) -> Self {
let t = m.fixed_slice::<D, 1>(0, D).into_owned();
let t = m.fixed_view::<D, 1>(0, D).into_owned();
let t = Translation {
vector: crate::convert_unchecked(t),
};

View File

@ -207,7 +207,7 @@ where
let mut res = crate::Matrix::uninit(DimNameSum::<D, U1>::name(), Const::<1>);
// This is basically a copy_from except that we warp the copied
// values into MaybeUninit.
res.generic_slice_mut((0, 0), self.coords.shape_generic())
res.generic_view_mut((0, 0), self.coords.shape_generic())
.zip_apply(&self.coords, |out, e| *out = MaybeUninit::new(e));
res[(len, 0)] = MaybeUninit::new(T::one());

View File

@ -113,7 +113,7 @@ where
DefaultAllocator: Allocator<T, DimNameSum<D, U1>>,
{
if !v[D::dim()].is_zero() {
let coords = v.generic_slice((0, 0), (D::name(), Const::<1>)) / v[D::dim()].clone();
let coords = v.generic_view((0, 0), (D::name(), Const::<1>)) / v[D::dim()].clone();
Some(Self::from(coords))
} else {
None

View File

@ -66,7 +66,7 @@ where
#[inline]
fn from_superset_unchecked(v: &OVector<T2, DimNameSum<D, U1>>) -> Self {
let coords = v.generic_slice((0, 0), (D::name(), Const::<1>)) / v[D::dim()].clone();
let coords = v.generic_view((0, 0), (D::name(), Const::<1>)) / v[D::dim()].clone();
Self {
coords: crate::convert_unchecked(coords),
}

View File

@ -261,7 +261,7 @@ impl<T: Scalar, const D: usize> Rotation<T, D> {
// adding the additional traits `DimAdd` and `IsNotStaticOne`. Maybe
// these things will get nicer once specialization lands in Rust.
let mut res = OMatrix::<T, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>::identity();
res.fixed_slice_mut::<D, D>(0, 0).copy_from(&self.matrix);
res.fixed_view_mut::<D, D>(0, 0).copy_from(&self.matrix);
res
}

View File

@ -211,8 +211,8 @@ where
#[inline]
fn is_in_subset(m: &OMatrix<T2, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>) -> bool {
let rot = m.fixed_slice::<D, D>(0, 0);
let bottom = m.fixed_slice::<1, D>(D, 0);
let rot = m.fixed_view::<D, D>(0, 0);
let bottom = m.fixed_view::<1, D>(D, 0);
// Scalar types agree.
m.iter().all(|e| SupersetOf::<T1>::is_in_subset(e)) &&
@ -226,7 +226,7 @@ where
fn from_superset_unchecked(
m: &OMatrix<T2, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>,
) -> Self {
let r = m.fixed_slice::<D, D>(0, 0);
let r = m.fixed_view::<D, D>(0, 0);
Self::from_matrix_unchecked(crate::convert_unchecked(r.into_owned()))
}
}

View File

@ -102,7 +102,7 @@ where
fn from_superset_unchecked(
m: &OMatrix<T2, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>,
) -> Self {
let v = m.fixed_slice::<D, D>(0, 0).diagonal();
let v = m.fixed_view::<D, D>(0, 0).diagonal();
Self {
vector: crate::convert_unchecked(v),
}

View File

@ -304,7 +304,7 @@ impl<T: SimdRealField, R, const D: usize> Similarity<T, R, D> {
{
let mut res = self.isometry.to_homogeneous();
for e in res.fixed_slice_mut::<D, D>(0, 0).iter_mut() {
for e in res.fixed_view_mut::<D, D>(0, 0).iter_mut() {
*e *= self.scaling.clone()
}

View File

@ -106,7 +106,7 @@ where
#[inline]
fn is_in_subset(m: &OMatrix<T2, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>) -> bool {
let mut rot = m.fixed_slice::<D, D>(0, 0).clone_owned();
let mut rot = m.fixed_view::<D, D>(0, 0).clone_owned();
if rot
.fixed_columns_mut::<1>(0)
.try_normalize_mut(T2::zero())
@ -128,7 +128,7 @@ where
rot.fixed_columns_mut::<1>(2).neg_mut();
}
let bottom = m.fixed_slice::<1, D>(D, 0);
let bottom = m.fixed_view::<1, D>(D, 0);
// Scalar types agree.
m.iter().all(|e| SupersetOf::<T1>::is_in_subset(e)) &&
// The normalized block part is a rotation.
@ -145,22 +145,22 @@ where
m: &OMatrix<T2, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>,
) -> Self {
let mut mm = m.clone_owned();
let na = mm.fixed_slice_mut::<D, 1>(0, 0).normalize_mut();
let nb = mm.fixed_slice_mut::<D, 1>(0, 1).normalize_mut();
let nc = mm.fixed_slice_mut::<D, 1>(0, 2).normalize_mut();
let na = mm.fixed_view_mut::<D, 1>(0, 0).normalize_mut();
let nb = mm.fixed_view_mut::<D, 1>(0, 1).normalize_mut();
let nc = mm.fixed_view_mut::<D, 1>(0, 2).normalize_mut();
let mut scale = (na + nb + nc) / crate::convert(3.0); // We take the mean, for robustness.
// TODO: could we avoid the explicit computation of the determinant?
// (its sign is needed to see if the scaling factor is negative).
if mm.fixed_slice::<D, D>(0, 0).determinant() < T2::zero() {
mm.fixed_slice_mut::<D, 1>(0, 0).neg_mut();
mm.fixed_slice_mut::<D, 1>(0, 1).neg_mut();
mm.fixed_slice_mut::<D, 1>(0, 2).neg_mut();
if mm.fixed_view::<D, D>(0, 0).determinant() < T2::zero() {
mm.fixed_view_mut::<D, 1>(0, 0).neg_mut();
mm.fixed_view_mut::<D, 1>(0, 1).neg_mut();
mm.fixed_view_mut::<D, 1>(0, 2).neg_mut();
scale = -scale;
}
let t = m.fixed_slice::<D, 1>(0, D).into_owned();
let t = m.fixed_view::<D, 1>(0, D).into_owned();
let t = Translation {
vector: crate::convert_unchecked(t),
};

View File

@ -120,10 +120,10 @@ md_impl_all!(
[ref val] => self * &rhs;
[val ref] => &self * rhs;
[ref ref] => {
let transform = self.matrix().fixed_slice::<D, D>(0, 0);
let transform = self.matrix().fixed_view::<D, D>(0, 0);
if C::has_normalizer() {
let normalizer = self.matrix().fixed_slice::<1, D>(D, 0);
let normalizer = self.matrix().fixed_view::<1, D>(D, 0);
let n = normalizer.tr_dot(rhs);
if !n.is_zero() {
@ -148,11 +148,11 @@ md_impl_all!(
[ref val] => self * &rhs;
[val ref] => &self * rhs;
[ref ref] => {
let transform = self.matrix().fixed_slice::<D, D>(0, 0);
let translation = self.matrix().fixed_slice::<D, 1>(0, D);
let transform = self.matrix().fixed_view::<D, D>(0, 0);
let translation = self.matrix().fixed_view::<D, 1>(0, D);
if C::has_normalizer() {
let normalizer = self.matrix().fixed_slice::<1, D>(D, 0);
let normalizer = self.matrix().fixed_view::<1, D>(D, 0);
#[allow(clippy::suspicious_arithmetic_impl)]
let n = normalizer.tr_dot(&rhs.coords) + unsafe { self.matrix().get_unchecked((D, D)).clone() };

View File

@ -150,7 +150,7 @@ impl<T: Scalar, const D: usize> Translation<T, D> {
DefaultAllocator: Allocator<T, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>,
{
let mut res = OMatrix::<T, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>::identity();
res.fixed_slice_mut::<D, 1>(0, D).copy_from(&self.vector);
res.fixed_view_mut::<D, 1>(0, D).copy_from(&self.vector);
res
}

View File

@ -159,7 +159,7 @@ where
#[inline]
fn is_in_subset(m: &OMatrix<T2, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>) -> bool {
let id = m.generic_slice((0, 0), (DimNameSum::<Const<D>, U1>::name(), Const::<D>));
let id = m.generic_view((0, 0), (DimNameSum::<Const<D>, U1>::name(), Const::<D>));
// Scalar types agree.
m.iter().all(|e| SupersetOf::<T1>::is_in_subset(e)) &&
@ -173,7 +173,7 @@ where
fn from_superset_unchecked(
m: &OMatrix<T2, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>,
) -> Self {
let t = m.fixed_slice::<D, 1>(0, D);
let t = m.fixed_view::<D, 1>(0, D);
Self {
vector: crate::convert_unchecked(t.into_owned()),
}

View File

@ -202,7 +202,7 @@ where
);
let start = self.axis_shift();
res.slice_mut(start, (d.value() - 1, d.value() - 1))
res.view_mut(start, (d.value() - 1, d.value() - 1))
.set_partial_diagonal(
self.off_diagonal
.iter()
@ -226,11 +226,11 @@ where
let shift = self.axis_shift().0;
for i in (0..dim - shift).rev() {
let axis = self.uv.slice_range(i + shift.., i);
let axis = self.uv.view_range(i + shift.., i);
// TODO: sometimes, the axis might have a zero magnitude.
let refl = Reflection::new(Unit::new_unchecked(axis), T::zero());
let mut res_rows = res.slice_range_mut(i + shift.., i..);
let mut res_rows = res.view_range_mut(i + shift.., i..);
let sign = if self.upper_diagonal {
self.diagonal[i].clone().signum()
@ -260,13 +260,13 @@ where
let shift = self.axis_shift().1;
for i in (0..min_nrows_ncols.value() - shift).rev() {
let axis = self.uv.slice_range(i, i + shift..);
let axis = self.uv.view_range(i, i + shift..);
let mut axis_packed = axis_packed.rows_range_mut(i + shift..);
axis_packed.tr_copy_from(&axis);
// TODO: sometimes, the axis might have a zero magnitude.
let refl = Reflection::new(Unit::new_unchecked(axis_packed), T::zero());
let mut res_rows = res.slice_range_mut(i.., i + shift..);
let mut res_rows = res.view_range_mut(i.., i + shift..);
let sign = if self.upper_diagonal {
self.off_diagonal[i].clone().signum()
@ -346,7 +346,7 @@ where
// *b.vget_unchecked_mut(i) = coeff;
// }
//
// b.rows_range_mut(.. i).axpy(-coeff, &self.uv.slice_range(.. i, i), T::one());
// b.rows_range_mut(.. i).axpy(-coeff, &self.uv.view_range(.. i, i), T::one());
// }
// }
// }

View File

@ -67,7 +67,7 @@ where
*matrix.get_unchecked_mut((j, j)) = denom.clone();
}
let mut col = matrix.slice_range_mut(j + 1.., j);
let mut col = matrix.view_range_mut(j + 1.., j);
col /= denom;
}
@ -228,7 +228,7 @@ where
*matrix.get_unchecked_mut((j, j)) = denom.clone();
}
let mut col = matrix.slice_range_mut(j + 1.., j);
let mut col = matrix.view_range_mut(j + 1.., j);
col /= denom;
continue;
}
@ -283,17 +283,17 @@ where
self.chol.shape_generic().0.add(Const::<1>),
self.chol.shape_generic().1.add(Const::<1>),
);
chol.slice_range_mut(..j, ..j)
.copy_from(&self.chol.slice_range(..j, ..j));
chol.slice_range_mut(..j, j + 1..)
.copy_from(&self.chol.slice_range(..j, j..));
chol.slice_range_mut(j + 1.., ..j)
.copy_from(&self.chol.slice_range(j.., ..j));
chol.slice_range_mut(j + 1.., j + 1..)
.copy_from(&self.chol.slice_range(j.., j..));
chol.view_range_mut(..j, ..j)
.copy_from(&self.chol.view_range(..j, ..j));
chol.view_range_mut(..j, j + 1..)
.copy_from(&self.chol.view_range(..j, j..));
chol.view_range_mut(j + 1.., ..j)
.copy_from(&self.chol.view_range(j.., ..j));
chol.view_range_mut(j + 1.., j + 1..)
.copy_from(&self.chol.view_range(j.., j..));
// update the jth row
let top_left_corner = self.chol.slice_range(..j, ..j);
let top_left_corner = self.chol.view_range(..j, ..j);
let col_j = col[j].clone();
let (mut new_rowj_adjoint, mut new_colj) = col.rows_range_pair_mut(..j, j + 1..);
@ -302,14 +302,14 @@ where
"Cholesky::insert_column : Unable to solve lower triangular system!"
);
new_rowj_adjoint.adjoint_to(&mut chol.slice_range_mut(j, ..j));
new_rowj_adjoint.adjoint_to(&mut chol.view_range_mut(j, ..j));
// update the center element
let center_element = T::sqrt(col_j - T::from_real(new_rowj_adjoint.norm_squared()));
chol[(j, j)] = center_element.clone();
// update the jth column
let bottom_left_corner = self.chol.slice_range(j.., ..j);
let bottom_left_corner = self.chol.view_range(j.., ..j);
// new_colj = (col_jplus - bottom_left_corner * new_rowj.adjoint()) / center_element;
new_colj.gemm(
-T::one() / center_element.clone(),
@ -317,10 +317,10 @@ where
&new_rowj_adjoint,
T::one() / center_element,
);
chol.slice_range_mut(j + 1.., j).copy_from(&new_colj);
chol.view_range_mut(j + 1.., j).copy_from(&new_colj);
// update the bottom right corner
let mut bottom_right_corner = chol.slice_range_mut(j + 1.., j + 1..);
let mut bottom_right_corner = chol.view_range_mut(j + 1.., j + 1..);
Self::xx_rank_one_update(
&mut bottom_right_corner,
&mut new_colj,
@ -348,17 +348,17 @@ where
self.chol.shape_generic().0.sub(Const::<1>),
self.chol.shape_generic().1.sub(Const::<1>),
);
chol.slice_range_mut(..j, ..j)
.copy_from(&self.chol.slice_range(..j, ..j));
chol.slice_range_mut(..j, j..)
.copy_from(&self.chol.slice_range(..j, j + 1..));
chol.slice_range_mut(j.., ..j)
.copy_from(&self.chol.slice_range(j + 1.., ..j));
chol.slice_range_mut(j.., j..)
.copy_from(&self.chol.slice_range(j + 1.., j + 1..));
chol.view_range_mut(..j, ..j)
.copy_from(&self.chol.view_range(..j, ..j));
chol.view_range_mut(..j, j..)
.copy_from(&self.chol.view_range(..j, j + 1..));
chol.view_range_mut(j.., ..j)
.copy_from(&self.chol.view_range(j + 1.., ..j));
chol.view_range_mut(j.., j..)
.copy_from(&self.chol.view_range(j + 1.., j + 1..));
// updates the bottom right corner
let mut bottom_right_corner = chol.slice_range_mut(j.., j..);
let mut bottom_right_corner = chol.view_range_mut(j.., j..);
let mut workspace = self.chol.column(j).clone_owned();
let mut old_colj = workspace.rows_range_mut(j + 1..);
Self::xx_rank_one_update(&mut bottom_right_corner, &mut old_colj, T::RealField::one());
@ -370,7 +370,7 @@ where
/// performs a rank one update such that we end up with the decomposition of `M + sigma * (x * x.adjoint())`.
///
/// This helper method is called by `rank_one_update` but also `insert_column` and `remove_column`
/// where it is used on a square slice of the decomposition
/// where it is used on a square view of the decomposition
fn xx_rank_one_update<Dm, Sm, Rx, Sx>(
chol: &mut Matrix<T, Dm, Dm, Sm>,
x: &mut Vector<T, Rx, Sx>,
@ -404,7 +404,7 @@ where
beta += sigma_xj2 / diag2;
// updates the terms of L
let mut xjplus = x.rows_range_mut(j + 1..);
let mut col_j = chol.slice_range_mut(j + 1.., j);
let mut col_j = chol.view_range_mut(j + 1.., j);
// temp_jplus -= (wj / T::from_real(diag)) * col_j;
xjplus.axpy(-xj.clone() / T::from_real(diag.clone()), &col_j, T::one());
if gamma != crate::zero::<T::RealField>() {

View File

@ -78,7 +78,7 @@ where
let mut diag = Matrix::uninit(min_nrows_ncols, Const::<1>);
for i in 0..min_nrows_ncols.value() {
let piv = matrix.slice_range(i.., i..).icamax_full();
let piv = matrix.view_range(i.., i..).icamax_full();
let col_piv = piv.1 + i;
matrix.swap_columns(i, col_piv);
p.append_permutation(i, col_piv);
@ -144,11 +144,11 @@ where
let dim = self.diag.len();
for i in (0..dim).rev() {
let axis = self.col_piv_qr.slice_range(i.., i);
let axis = self.col_piv_qr.view_range(i.., i);
// TODO: sometimes, the axis might have a zero magnitude.
let refl = Reflection::new(Unit::new_unchecked(axis), T::zero());
let mut res_rows = res.slice_range_mut(i.., i..);
let mut res_rows = res.view_range_mut(i.., i..);
refl.reflect_with_sign(&mut res_rows, self.diag[i].clone().signum());
}
@ -191,7 +191,7 @@ where
let dim = self.diag.len();
for i in 0..dim {
let axis = self.col_piv_qr.slice_range(i.., i);
let axis = self.col_piv_qr.view_range(i.., i);
let refl = Reflection::new(Unit::new_unchecked(axis), T::zero());
let mut rhs_rows = rhs.rows_range_mut(i..);
@ -281,7 +281,7 @@ where
}
b.rows_range_mut(..i)
.axpy(-coeff, &self.col_piv_qr.slice_range(..i, i), T::one());
.axpy(-coeff, &self.col_piv_qr.view_range(..i, i), T::one());
}
}

View File

@ -64,7 +64,7 @@ where
}
for i in 0..min_nrows_ncols.value() {
let piv = matrix.slice_range(i.., i..).icamax_full();
let piv = matrix.view_range(i.., i..).icamax_full();
let row_piv = piv.0 + i;
let col_piv = piv.1 + i;
let diag = matrix[(row_piv, col_piv)].clone();

View File

@ -113,7 +113,7 @@ where
let dim = self.hess.nrows();
self.hess.fill_lower_triangle(T::zero(), 2);
self.hess
.slice_mut((1, 0), (dim - 1, dim - 1))
.view_mut((1, 0), (dim - 1, dim - 1))
.set_partial_diagonal(
self.subdiag
.iter()
@ -132,7 +132,7 @@ where
let dim = self.hess.nrows();
let mut res = self.hess.clone();
res.fill_lower_triangle(T::zero(), 2);
res.slice_mut((1, 0), (dim - 1, dim - 1))
res.view_mut((1, 0), (dim - 1, dim - 1))
.set_partial_diagonal(
self.subdiag
.iter()

View File

@ -128,10 +128,10 @@ where
let mut res = OMatrix::identity_generic(dim, dim);
for i in (0..dim.value() - 1).rev() {
let axis = m.slice_range(i + 1.., i);
let axis = m.view_range(i + 1.., i);
let refl = Reflection::new(Unit::new_unchecked(axis), T::zero());
let mut res_rows = res.slice_range_mut(i + 1.., i..);
let mut res_rows = res.view_range_mut(i + 1.., i..);
refl.reflect_with_sign(&mut res_rows, signs[i].clone().signum());
}

View File

@ -64,7 +64,7 @@ where
out.fill_with_identity();
for i in 0..dim {
let piv = matrix.slice_range(i.., i).icamax() + i;
let piv = matrix.view_range(i.., i).icamax() + i;
let diag = matrix[(piv, i)].clone();
if diag.is_zero() {
@ -100,7 +100,7 @@ where
}
for i in 0..min_nrows_ncols.value() {
let piv = matrix.slice_range(i.., i).icamax() + i;
let piv = matrix.view_range(i.., i).icamax() + i;
let diag = matrix[(piv, i)].clone();
if diag.is_zero() {
@ -338,7 +338,7 @@ where
T: Scalar + Field,
S: StorageMut<T, R, C>,
{
let mut submat = matrix.slice_range_mut(i.., i..);
let mut submat = matrix.view_range_mut(i.., i..);
let inv_diag = T::one() / diag;
@ -368,7 +368,7 @@ pub fn gauss_step_swap<T, R: Dim, C: Dim, S>(
S: StorageMut<T, R, C>,
{
let piv = piv - i;
let mut submat = matrix.slice_range_mut(i.., i..);
let mut submat = matrix.view_range_mut(i.., i..);
let inv_diag = T::one() / diag;

View File

@ -116,11 +116,11 @@ where
let dim = self.diag.len();
for i in (0..dim).rev() {
let axis = self.qr.slice_range(i.., i);
let axis = self.qr.view_range(i.., i);
// TODO: sometimes, the axis might have a zero magnitude.
let refl = Reflection::new(Unit::new_unchecked(axis), T::zero());
let mut res_rows = res.slice_range_mut(i.., i..);
let mut res_rows = res.view_range_mut(i.., i..);
refl.reflect_with_sign(&mut res_rows, self.diag[i].clone().signum());
}
@ -161,7 +161,7 @@ where
let dim = self.diag.len();
for i in 0..dim {
let axis = self.qr.slice_range(i.., i);
let axis = self.qr.view_range(i.., i);
let refl = Reflection::new(Unit::new_unchecked(axis), T::zero());
let mut rhs_rows = rhs.rows_range_mut(i..);
@ -247,7 +247,7 @@ where
}
b.rows_range_mut(..i)
.axpy(-coeff, &self.qr.slice_range(..i, i), T::one());
.axpy(-coeff, &self.qr.view_range(..i, i), T::one());
}
}

View File

@ -174,19 +174,19 @@ where
{
let krows = cmp::min(k + 4, end + 1);
let mut work = work.rows_mut(0, krows);
refl.reflect(&mut t.generic_slice_mut(
refl.reflect(&mut t.generic_view_mut(
(k, k),
(Const::<3>, Dynamic::new(dim.value() - k)),
));
refl.reflect_rows(
&mut t.generic_slice_mut((0, k), (Dynamic::new(krows), Const::<3>)),
&mut t.generic_view_mut((0, k), (Dynamic::new(krows), Const::<3>)),
&mut work,
);
}
if let Some(ref mut q) = q {
refl.reflect_rows(
&mut q.generic_slice_mut((0, k), (dim, Const::<3>)),
&mut q.generic_view_mut((0, k), (dim, Const::<3>)),
work,
);
}
@ -211,38 +211,38 @@ where
{
let mut work = work.rows_mut(0, end + 1);
refl.reflect(&mut t.generic_slice_mut(
refl.reflect(&mut t.generic_view_mut(
(m, m),
(Const::<2>, Dynamic::new(dim.value() - m)),
));
refl.reflect_rows(
&mut t.generic_slice_mut((0, m), (Dynamic::new(end + 1), Const::<2>)),
&mut t.generic_view_mut((0, m), (Dynamic::new(end + 1), Const::<2>)),
&mut work,
);
}
if let Some(ref mut q) = q {
refl.reflect_rows(
&mut q.generic_slice_mut((0, m), (dim, Const::<2>)),
&mut q.generic_view_mut((0, m), (dim, Const::<2>)),
work,
);
}
}
} else {
// Decouple the 2x2 block if it has real eigenvalues.
if let Some(rot) = compute_2x2_basis(&t.fixed_slice::<2, 2>(start, start)) {
if let Some(rot) = compute_2x2_basis(&t.fixed_view::<2, 2>(start, start)) {
let inv_rot = rot.inverse();
inv_rot.rotate(&mut t.generic_slice_mut(
inv_rot.rotate(&mut t.generic_view_mut(
(start, start),
(Const::<2>, Dynamic::new(dim.value() - start)),
));
rot.rotate_rows(
&mut t.generic_slice_mut((0, start), (Dynamic::new(end + 1), Const::<2>)),
&mut t.generic_view_mut((0, start), (Dynamic::new(end + 1), Const::<2>)),
);
t[(end, start)] = T::zero();
if let Some(ref mut q) = q {
rot.rotate_rows(&mut q.generic_slice_mut((0, start), (dim, Const::<2>)));
rot.rotate_rows(&mut q.generic_view_mut((0, start), (dim, Const::<2>)));
}
}
@ -427,9 +427,9 @@ where
{
let dim = m.shape_generic().0;
let mut q = None;
match compute_2x2_basis(&m.fixed_slice::<2, 2>(0, 0)) {
match compute_2x2_basis(&m.fixed_view::<2, 2>(0, 0)) {
Some(rot) => {
let mut m = m.fixed_slice_mut::<2, 2>(0, 0);
let mut m = m.fixed_view_mut::<2, 2>(0, 0);
let inv_rot = rot.inverse();
inv_rot.rotate(&mut m);
rot.rotate_rows(&mut m);
@ -530,7 +530,7 @@ where
if self.nrows() == 2 {
// TODO: can we avoid this slicing
// (which is needed here just to transform D to U2)?
let me = self.fixed_slice::<2, 2>(0, 0);
let me = self.fixed_view::<2, 2>(0, 0);
return match compute_2x2_eigvals(&me) {
Some((a, b)) => {
work[0] = a;

View File

@ -93,7 +93,7 @@ impl<T: ComplexField, D: Dim, S: Storage<T, D, D>> SquareMatrix<T, D, S> {
}
b.rows_range_mut(i + 1..)
.axpy(-coeff, &self.slice_range(i + 1.., i), T::one());
.axpy(-coeff, &self.view_range(i + 1.., i), T::one());
}
true
@ -125,7 +125,7 @@ impl<T: ComplexField, D: Dim, S: Storage<T, D, D>> SquareMatrix<T, D, S> {
for i in 0..dim - 1 {
let coeff = unsafe { bcol.vget_unchecked(i).clone() } / diag.clone();
bcol.rows_range_mut(i + 1..)
.axpy(-coeff, &self.slice_range(i + 1.., i), T::one());
.axpy(-coeff, &self.view_range(i + 1.., i), T::one());
}
}
@ -175,7 +175,7 @@ impl<T: ComplexField, D: Dim, S: Storage<T, D, D>> SquareMatrix<T, D, S> {
}
b.rows_range_mut(..i)
.axpy(-coeff, &self.slice_range(..i, i), T::one());
.axpy(-coeff, &self.view_range(..i, i), T::one());
}
true
@ -387,7 +387,7 @@ impl<T: ComplexField, D: Dim, S: Storage<T, D, D>> SquareMatrix<T, D, S> {
let dim = self.nrows();
for i in (0..dim).rev() {
let dot = dot(&self.slice_range(i + 1.., i), &b.slice_range(i + 1.., 0));
let dot = dot(&self.view_range(i + 1.., i), &b.view_range(i + 1.., 0));
unsafe {
let b_i = b.vget_unchecked_mut(i);
@ -422,7 +422,7 @@ impl<T: ComplexField, D: Dim, S: Storage<T, D, D>> SquareMatrix<T, D, S> {
let dim = self.nrows();
for i in 0..dim {
let dot = dot(&self.slice_range(..i, i), &b.slice_range(..i, 0));
let dot = dot(&self.view_range(..i, i), &b.view_range(..i, 0));
unsafe {
let b_i = b.vget_unchecked_mut(i);
@ -514,7 +514,7 @@ impl<T: SimdComplexField, D: Dim, S: Storage<T, D, D>> SquareMatrix<T, D, S> {
}
b.rows_range_mut(i + 1..)
.axpy(-coeff.clone(), &self.slice_range(i + 1.., i), T::one());
.axpy(-coeff.clone(), &self.view_range(i + 1.., i), T::one());
}
}
@ -539,7 +539,7 @@ impl<T: SimdComplexField, D: Dim, S: Storage<T, D, D>> SquareMatrix<T, D, S> {
for i in 0..dim - 1 {
let coeff = unsafe { bcol.vget_unchecked(i).clone() } / diag.clone();
bcol.rows_range_mut(i + 1..)
.axpy(-coeff, &self.slice_range(i + 1.., i), T::one());
.axpy(-coeff, &self.view_range(i + 1.., i), T::one());
}
}
}
@ -575,7 +575,7 @@ impl<T: SimdComplexField, D: Dim, S: Storage<T, D, D>> SquareMatrix<T, D, S> {
}
b.rows_range_mut(..i)
.axpy(-coeff, &self.slice_range(..i, i), T::one());
.axpy(-coeff, &self.view_range(..i, i), T::one());
}
}
@ -744,7 +744,7 @@ impl<T: SimdComplexField, D: Dim, S: Storage<T, D, D>> SquareMatrix<T, D, S> {
let dim = self.nrows();
for i in (0..dim).rev() {
let dot = dot(&self.slice_range(i + 1.., i), &b.slice_range(i + 1.., 0));
let dot = dot(&self.view_range(i + 1.., i), &b.view_range(i + 1.., 0));
unsafe {
let b_i = b.vget_unchecked_mut(i);
@ -768,7 +768,7 @@ impl<T: SimdComplexField, D: Dim, S: Storage<T, D, D>> SquareMatrix<T, D, S> {
ShapeConstraint: SameNumberOfRows<R2, D>,
{
for i in 0..self.nrows() {
let dot = dot(&self.slice_range(..i, i), &b.slice_range(..i, 0));
let dot = dot(&self.view_range(..i, i), &b.view_range(..i, 0));
unsafe {
let b_i = b.vget_unchecked_mut(i);