Use view* instead of slice* methods in src/
This commit is contained in:
parent
0319d236af
commit
34f4537376
|
@ -393,7 +393,7 @@ where
|
||||||
let col2 = a.column(0);
|
let col2 = a.column(0);
|
||||||
let val = unsafe { x.vget_unchecked(0).clone() };
|
let val = unsafe { x.vget_unchecked(0).clone() };
|
||||||
self.axpy(alpha.clone() * val, &col2, beta);
|
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 {
|
for j in 1..dim2 {
|
||||||
let col2 = a.column(j);
|
let col2 = a.column(j);
|
||||||
|
@ -892,7 +892,7 @@ where
|
||||||
let val = unsafe { conjugate(y.vget_unchecked(j).clone()) };
|
let val = unsafe { conjugate(y.vget_unchecked(j).clone()) };
|
||||||
let subdim = Dynamic::new(dim1 - j);
|
let subdim = Dynamic::new(dim1 - j);
|
||||||
// TODO: avoid bound checks.
|
// 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,
|
alpha.clone() * val,
|
||||||
&x.rows_range(j..),
|
&x.rows_range(j..),
|
||||||
beta.clone(),
|
beta.clone(),
|
||||||
|
|
|
@ -59,7 +59,7 @@ where
|
||||||
SB: Storage<T, DimNameDiff<D, U1>>,
|
SB: Storage<T, DimNameDiff<D, U1>>,
|
||||||
{
|
{
|
||||||
let mut res = Self::identity();
|
let mut res = Self::identity();
|
||||||
res.generic_slice_mut(
|
res.generic_view_mut(
|
||||||
(0, D::dim() - 1),
|
(0, D::dim() - 1),
|
||||||
(DimNameDiff::<D, U1>::name(), Const::<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>>,
|
DefaultAllocator: Allocator<T, DimNameDiff<D, U1>>,
|
||||||
{
|
{
|
||||||
let scale = self
|
let scale = self
|
||||||
.generic_slice(
|
.generic_view(
|
||||||
(D::dim() - 1, 0),
|
(D::dim() - 1, 0),
|
||||||
(Const::<1>, DimNameDiff::<D, U1>::name()),
|
(Const::<1>, DimNameDiff::<D, U1>::name()),
|
||||||
)
|
)
|
||||||
.tr_dot(shift);
|
.tr_dot(shift);
|
||||||
let post_translation = self.generic_slice(
|
let post_translation = self.generic_view(
|
||||||
(0, 0),
|
(0, 0),
|
||||||
(DimNameDiff::<D, U1>::name(), DimNameDiff::<D, U1>::name()),
|
(DimNameDiff::<D, U1>::name(), DimNameDiff::<D, U1>::name()),
|
||||||
) * shift;
|
) * shift;
|
||||||
|
|
||||||
self[(D::dim() - 1, D::dim() - 1)] += scale;
|
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),
|
(0, D::dim() - 1),
|
||||||
(DimNameDiff::<D, U1>::name(), Const::<1>),
|
(DimNameDiff::<D, U1>::name(), Const::<1>),
|
||||||
);
|
);
|
||||||
|
@ -415,11 +415,11 @@ where
|
||||||
&self,
|
&self,
|
||||||
v: &OVector<T, DimNameDiff<D, U1>>,
|
v: &OVector<T, DimNameDiff<D, U1>>,
|
||||||
) -> OVector<T, DimNameDiff<D, U1>> {
|
) -> OVector<T, DimNameDiff<D, U1>> {
|
||||||
let transform = self.generic_slice(
|
let transform = self.generic_view(
|
||||||
(0, 0),
|
(0, 0),
|
||||||
(DimNameDiff::<D, U1>::name(), DimNameDiff::<D, U1>::name()),
|
(DimNameDiff::<D, U1>::name(), DimNameDiff::<D, U1>::name()),
|
||||||
);
|
);
|
||||||
let normalizer = self.generic_slice(
|
let normalizer = self.generic_view(
|
||||||
(D::dim() - 1, 0),
|
(D::dim() - 1, 0),
|
||||||
(Const::<1>, DimNameDiff::<D, U1>::name()),
|
(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.
|
/// Transforms the given point, assuming the matrix `self` uses homogeneous coordinates.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn transform_point(&self, pt: &Point<T, 2>) -> Point<T, 2> {
|
pub fn transform_point(&self, pt: &Point<T, 2>) -> Point<T, 2> {
|
||||||
let transform = self.fixed_slice::<2, 2>(0, 0);
|
let transform = self.fixed_view::<2, 2>(0, 0);
|
||||||
let translation = self.fixed_slice::<2, 1>(0, 2);
|
let translation = self.fixed_view::<2, 1>(0, 2);
|
||||||
let normalizer = self.fixed_slice::<1, 2>(2, 0);
|
let normalizer = self.fixed_view::<1, 2>(2, 0);
|
||||||
let n = normalizer.tr_dot(&pt.coords) + unsafe { self.get_unchecked((2, 2)).clone() };
|
let n = normalizer.tr_dot(&pt.coords) + unsafe { self.get_unchecked((2, 2)).clone() };
|
||||||
|
|
||||||
if !n.is_zero() {
|
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.
|
/// Transforms the given point, assuming the matrix `self` uses homogeneous coordinates.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn transform_point(&self, pt: &Point<T, 3>) -> Point<T, 3> {
|
pub fn transform_point(&self, pt: &Point<T, 3>) -> Point<T, 3> {
|
||||||
let transform = self.fixed_slice::<3, 3>(0, 0);
|
let transform = self.fixed_view::<3, 3>(0, 0);
|
||||||
let translation = self.fixed_slice::<3, 1>(0, 3);
|
let translation = self.fixed_view::<3, 1>(0, 3);
|
||||||
let normalizer = self.fixed_slice::<1, 3>(3, 0);
|
let normalizer = self.fixed_view::<1, 3>(3, 0);
|
||||||
let n = normalizer.tr_dot(&pt.coords) + unsafe { self.get_unchecked((3, 3)).clone() };
|
let n = normalizer.tr_dot(&pt.coords) + unsafe { self.get_unchecked((3, 3)).clone() };
|
||||||
|
|
||||||
if !n.is_zero() {
|
if !n.is_zero() {
|
||||||
|
|
|
@ -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 {
|
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()));
|
.fill_with(|| MaybeUninit::new(val.clone()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -446,7 +446,7 @@ impl<T, R: Dim, C: Dim, S: RawStorage<T, R, C>> Matrix<T, R, C, S> {
|
||||||
/// ```
|
/// ```
|
||||||
/// # use nalgebra::DMatrix;
|
/// # use nalgebra::DMatrix;
|
||||||
/// let mat = DMatrix::<f32>::zeros(10, 10);
|
/// 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.
|
/// // The column strides is the number of steps (here 2) multiplied by the corresponding dimension.
|
||||||
/// assert_eq!(mat.strides(), (1, 10));
|
/// 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 dim = DimSum::<D, U1>::from_usize(self.nrows() + 1);
|
||||||
let mut res = OMatrix::identity_generic(dim, dim);
|
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);
|
.copy_from(self);
|
||||||
res
|
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() {
|
if v[v.len() - 1].is_zero() {
|
||||||
let nrows = D::from_usize(v.len() - 1);
|
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 {
|
} else {
|
||||||
None
|
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>);
|
let mut res = Matrix::uninit(hnrows, Const::<1>);
|
||||||
// This is basically a copy_from except that we warp the copied
|
// This is basically a copy_from except that we warp the copied
|
||||||
// values into MaybeUninit.
|
// 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));
|
.zip_apply(self, |out, e| *out = MaybeUninit::new(e));
|
||||||
res[(len, 0)] = MaybeUninit::new(element);
|
res[(len, 0)] = MaybeUninit::new(element);
|
||||||
|
|
||||||
|
|
|
@ -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.
|
/// Returns a view 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) -> $MatrixView<'_, 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_view((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.
|
||||||
|
@ -961,7 +961,7 @@ impl<T, R: Dim, C: Dim, S: RawStorage<T, R, C>> Matrix<T, R, C, S> {
|
||||||
ColRange: SliceRange<C>,
|
ColRange: SliceRange<C>,
|
||||||
{
|
{
|
||||||
let (nrows, ncols) = self.shape_generic();
|
let (nrows, ncols) = self.shape_generic();
|
||||||
self.generic_slice(
|
self.generic_view(
|
||||||
(rows.begin(nrows), cols.begin(ncols)),
|
(rows.begin(nrows), cols.begin(ncols)),
|
||||||
(rows.size(nrows), cols.size(ncols)),
|
(rows.size(nrows), cols.size(ncols)),
|
||||||
)
|
)
|
||||||
|
|
|
@ -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>>,
|
DefaultAllocator: Allocator<T, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>,
|
||||||
{
|
{
|
||||||
let mut res: OMatrix<T, _, _> = crate::convert_ref(&self.rotation);
|
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);
|
.copy_from(&self.translation.vector);
|
||||||
|
|
||||||
res
|
res
|
||||||
|
|
|
@ -153,8 +153,8 @@ where
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn is_in_subset(m: &OMatrix<T2, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>) -> bool {
|
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 rot = m.fixed_view::<D, D>(0, 0);
|
||||||
let bottom = m.fixed_slice::<1, D>(D, 0);
|
let bottom = m.fixed_view::<1, D>(D, 0);
|
||||||
|
|
||||||
// Scalar types agree.
|
// Scalar types agree.
|
||||||
m.iter().all(|e| SupersetOf::<T1>::is_in_subset(e)) &&
|
m.iter().all(|e| SupersetOf::<T1>::is_in_subset(e)) &&
|
||||||
|
@ -168,7 +168,7 @@ where
|
||||||
fn from_superset_unchecked(
|
fn from_superset_unchecked(
|
||||||
m: &OMatrix<T2, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>,
|
m: &OMatrix<T2, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>,
|
||||||
) -> Self {
|
) -> 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 {
|
let t = Translation {
|
||||||
vector: crate::convert_unchecked(t),
|
vector: crate::convert_unchecked(t),
|
||||||
};
|
};
|
||||||
|
|
|
@ -207,7 +207,7 @@ where
|
||||||
let mut res = crate::Matrix::uninit(DimNameSum::<D, U1>::name(), Const::<1>);
|
let mut res = crate::Matrix::uninit(DimNameSum::<D, U1>::name(), Const::<1>);
|
||||||
// This is basically a copy_from except that we warp the copied
|
// This is basically a copy_from except that we warp the copied
|
||||||
// values into MaybeUninit.
|
// 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));
|
.zip_apply(&self.coords, |out, e| *out = MaybeUninit::new(e));
|
||||||
res[(len, 0)] = MaybeUninit::new(T::one());
|
res[(len, 0)] = MaybeUninit::new(T::one());
|
||||||
|
|
||||||
|
|
|
@ -113,7 +113,7 @@ where
|
||||||
DefaultAllocator: Allocator<T, DimNameSum<D, U1>>,
|
DefaultAllocator: Allocator<T, DimNameSum<D, U1>>,
|
||||||
{
|
{
|
||||||
if !v[D::dim()].is_zero() {
|
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))
|
Some(Self::from(coords))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
|
@ -66,7 +66,7 @@ where
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_superset_unchecked(v: &OVector<T2, DimNameSum<D, U1>>) -> Self {
|
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 {
|
Self {
|
||||||
coords: crate::convert_unchecked(coords),
|
coords: crate::convert_unchecked(coords),
|
||||||
}
|
}
|
||||||
|
|
|
@ -261,7 +261,7 @@ impl<T: Scalar, const D: usize> Rotation<T, D> {
|
||||||
// adding the additional traits `DimAdd` and `IsNotStaticOne`. Maybe
|
// adding the additional traits `DimAdd` and `IsNotStaticOne`. Maybe
|
||||||
// these things will get nicer once specialization lands in Rust.
|
// these things will get nicer once specialization lands in Rust.
|
||||||
let mut res = OMatrix::<T, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>::identity();
|
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
|
res
|
||||||
}
|
}
|
||||||
|
|
|
@ -211,8 +211,8 @@ where
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn is_in_subset(m: &OMatrix<T2, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>) -> bool {
|
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 rot = m.fixed_view::<D, D>(0, 0);
|
||||||
let bottom = m.fixed_slice::<1, D>(D, 0);
|
let bottom = m.fixed_view::<1, D>(D, 0);
|
||||||
|
|
||||||
// Scalar types agree.
|
// Scalar types agree.
|
||||||
m.iter().all(|e| SupersetOf::<T1>::is_in_subset(e)) &&
|
m.iter().all(|e| SupersetOf::<T1>::is_in_subset(e)) &&
|
||||||
|
@ -226,7 +226,7 @@ where
|
||||||
fn from_superset_unchecked(
|
fn from_superset_unchecked(
|
||||||
m: &OMatrix<T2, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>,
|
m: &OMatrix<T2, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>,
|
||||||
) -> Self {
|
) -> 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()))
|
Self::from_matrix_unchecked(crate::convert_unchecked(r.into_owned()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -102,7 +102,7 @@ where
|
||||||
fn from_superset_unchecked(
|
fn from_superset_unchecked(
|
||||||
m: &OMatrix<T2, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>,
|
m: &OMatrix<T2, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let v = m.fixed_slice::<D, D>(0, 0).diagonal();
|
let v = m.fixed_view::<D, D>(0, 0).diagonal();
|
||||||
Self {
|
Self {
|
||||||
vector: crate::convert_unchecked(v),
|
vector: crate::convert_unchecked(v),
|
||||||
}
|
}
|
||||||
|
|
|
@ -304,7 +304,7 @@ impl<T: SimdRealField, R, const D: usize> Similarity<T, R, D> {
|
||||||
{
|
{
|
||||||
let mut res = self.isometry.to_homogeneous();
|
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()
|
*e *= self.scaling.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -106,7 +106,7 @@ where
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn is_in_subset(m: &OMatrix<T2, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>) -> bool {
|
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
|
if rot
|
||||||
.fixed_columns_mut::<1>(0)
|
.fixed_columns_mut::<1>(0)
|
||||||
.try_normalize_mut(T2::zero())
|
.try_normalize_mut(T2::zero())
|
||||||
|
@ -128,7 +128,7 @@ where
|
||||||
rot.fixed_columns_mut::<1>(2).neg_mut();
|
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.
|
// Scalar types agree.
|
||||||
m.iter().all(|e| SupersetOf::<T1>::is_in_subset(e)) &&
|
m.iter().all(|e| SupersetOf::<T1>::is_in_subset(e)) &&
|
||||||
// The normalized block part is a rotation.
|
// The normalized block part is a rotation.
|
||||||
|
@ -145,22 +145,22 @@ where
|
||||||
m: &OMatrix<T2, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>,
|
m: &OMatrix<T2, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let mut mm = m.clone_owned();
|
let mut mm = m.clone_owned();
|
||||||
let na = mm.fixed_slice_mut::<D, 1>(0, 0).normalize_mut();
|
let na = mm.fixed_view_mut::<D, 1>(0, 0).normalize_mut();
|
||||||
let nb = mm.fixed_slice_mut::<D, 1>(0, 1).normalize_mut();
|
let nb = mm.fixed_view_mut::<D, 1>(0, 1).normalize_mut();
|
||||||
let nc = mm.fixed_slice_mut::<D, 1>(0, 2).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.
|
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?
|
// TODO: could we avoid the explicit computation of the determinant?
|
||||||
// (its sign is needed to see if the scaling factor is negative).
|
// (its sign is needed to see if the scaling factor is negative).
|
||||||
if mm.fixed_slice::<D, D>(0, 0).determinant() < T2::zero() {
|
if mm.fixed_view::<D, D>(0, 0).determinant() < T2::zero() {
|
||||||
mm.fixed_slice_mut::<D, 1>(0, 0).neg_mut();
|
mm.fixed_view_mut::<D, 1>(0, 0).neg_mut();
|
||||||
mm.fixed_slice_mut::<D, 1>(0, 1).neg_mut();
|
mm.fixed_view_mut::<D, 1>(0, 1).neg_mut();
|
||||||
mm.fixed_slice_mut::<D, 1>(0, 2).neg_mut();
|
mm.fixed_view_mut::<D, 1>(0, 2).neg_mut();
|
||||||
scale = -scale;
|
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 {
|
let t = Translation {
|
||||||
vector: crate::convert_unchecked(t),
|
vector: crate::convert_unchecked(t),
|
||||||
};
|
};
|
||||||
|
|
|
@ -120,10 +120,10 @@ md_impl_all!(
|
||||||
[ref val] => self * &rhs;
|
[ref val] => self * &rhs;
|
||||||
[val ref] => &self * rhs;
|
[val ref] => &self * rhs;
|
||||||
[ref ref] => {
|
[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() {
|
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);
|
let n = normalizer.tr_dot(rhs);
|
||||||
|
|
||||||
if !n.is_zero() {
|
if !n.is_zero() {
|
||||||
|
@ -148,11 +148,11 @@ md_impl_all!(
|
||||||
[ref val] => self * &rhs;
|
[ref val] => self * &rhs;
|
||||||
[val ref] => &self * rhs;
|
[val ref] => &self * rhs;
|
||||||
[ref ref] => {
|
[ref ref] => {
|
||||||
let transform = self.matrix().fixed_slice::<D, D>(0, 0);
|
let transform = self.matrix().fixed_view::<D, D>(0, 0);
|
||||||
let translation = self.matrix().fixed_slice::<D, 1>(0, D);
|
let translation = self.matrix().fixed_view::<D, 1>(0, D);
|
||||||
|
|
||||||
if C::has_normalizer() {
|
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)]
|
#[allow(clippy::suspicious_arithmetic_impl)]
|
||||||
let n = normalizer.tr_dot(&rhs.coords) + unsafe { self.matrix().get_unchecked((D, D)).clone() };
|
let n = normalizer.tr_dot(&rhs.coords) + unsafe { self.matrix().get_unchecked((D, D)).clone() };
|
||||||
|
|
||||||
|
|
|
@ -150,7 +150,7 @@ impl<T: Scalar, const D: usize> Translation<T, D> {
|
||||||
DefaultAllocator: Allocator<T, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>,
|
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();
|
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
|
res
|
||||||
}
|
}
|
||||||
|
|
|
@ -159,7 +159,7 @@ where
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn is_in_subset(m: &OMatrix<T2, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>) -> bool {
|
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.
|
// Scalar types agree.
|
||||||
m.iter().all(|e| SupersetOf::<T1>::is_in_subset(e)) &&
|
m.iter().all(|e| SupersetOf::<T1>::is_in_subset(e)) &&
|
||||||
|
@ -173,7 +173,7 @@ where
|
||||||
fn from_superset_unchecked(
|
fn from_superset_unchecked(
|
||||||
m: &OMatrix<T2, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>,
|
m: &OMatrix<T2, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let t = m.fixed_slice::<D, 1>(0, D);
|
let t = m.fixed_view::<D, 1>(0, D);
|
||||||
Self {
|
Self {
|
||||||
vector: crate::convert_unchecked(t.into_owned()),
|
vector: crate::convert_unchecked(t.into_owned()),
|
||||||
}
|
}
|
||||||
|
|
|
@ -202,7 +202,7 @@ where
|
||||||
);
|
);
|
||||||
|
|
||||||
let start = self.axis_shift();
|
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(
|
.set_partial_diagonal(
|
||||||
self.off_diagonal
|
self.off_diagonal
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -226,11 +226,11 @@ where
|
||||||
let shift = self.axis_shift().0;
|
let shift = self.axis_shift().0;
|
||||||
|
|
||||||
for i in (0..dim - shift).rev() {
|
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.
|
// TODO: sometimes, the axis might have a zero magnitude.
|
||||||
let refl = Reflection::new(Unit::new_unchecked(axis), T::zero());
|
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 {
|
let sign = if self.upper_diagonal {
|
||||||
self.diagonal[i].clone().signum()
|
self.diagonal[i].clone().signum()
|
||||||
|
@ -260,13 +260,13 @@ where
|
||||||
let shift = self.axis_shift().1;
|
let shift = self.axis_shift().1;
|
||||||
|
|
||||||
for i in (0..min_nrows_ncols.value() - shift).rev() {
|
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..);
|
let mut axis_packed = axis_packed.rows_range_mut(i + shift..);
|
||||||
axis_packed.tr_copy_from(&axis);
|
axis_packed.tr_copy_from(&axis);
|
||||||
// TODO: sometimes, the axis might have a zero magnitude.
|
// TODO: sometimes, the axis might have a zero magnitude.
|
||||||
let refl = Reflection::new(Unit::new_unchecked(axis_packed), T::zero());
|
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 {
|
let sign = if self.upper_diagonal {
|
||||||
self.off_diagonal[i].clone().signum()
|
self.off_diagonal[i].clone().signum()
|
||||||
|
@ -346,7 +346,7 @@ where
|
||||||
// *b.vget_unchecked_mut(i) = coeff;
|
// *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());
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
|
@ -67,7 +67,7 @@ where
|
||||||
*matrix.get_unchecked_mut((j, j)) = denom.clone();
|
*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;
|
col /= denom;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -228,7 +228,7 @@ where
|
||||||
*matrix.get_unchecked_mut((j, j)) = denom.clone();
|
*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;
|
col /= denom;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -283,17 +283,17 @@ where
|
||||||
self.chol.shape_generic().0.add(Const::<1>),
|
self.chol.shape_generic().0.add(Const::<1>),
|
||||||
self.chol.shape_generic().1.add(Const::<1>),
|
self.chol.shape_generic().1.add(Const::<1>),
|
||||||
);
|
);
|
||||||
chol.slice_range_mut(..j, ..j)
|
chol.view_range_mut(..j, ..j)
|
||||||
.copy_from(&self.chol.slice_range(..j, ..j));
|
.copy_from(&self.chol.view_range(..j, ..j));
|
||||||
chol.slice_range_mut(..j, j + 1..)
|
chol.view_range_mut(..j, j + 1..)
|
||||||
.copy_from(&self.chol.slice_range(..j, j..));
|
.copy_from(&self.chol.view_range(..j, j..));
|
||||||
chol.slice_range_mut(j + 1.., ..j)
|
chol.view_range_mut(j + 1.., ..j)
|
||||||
.copy_from(&self.chol.slice_range(j.., ..j));
|
.copy_from(&self.chol.view_range(j.., ..j));
|
||||||
chol.slice_range_mut(j + 1.., j + 1..)
|
chol.view_range_mut(j + 1.., j + 1..)
|
||||||
.copy_from(&self.chol.slice_range(j.., j..));
|
.copy_from(&self.chol.view_range(j.., j..));
|
||||||
|
|
||||||
// update the jth row
|
// 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 col_j = col[j].clone();
|
||||||
let (mut new_rowj_adjoint, mut new_colj) = col.rows_range_pair_mut(..j, j + 1..);
|
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!"
|
"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
|
// update the center element
|
||||||
let center_element = T::sqrt(col_j - T::from_real(new_rowj_adjoint.norm_squared()));
|
let center_element = T::sqrt(col_j - T::from_real(new_rowj_adjoint.norm_squared()));
|
||||||
chol[(j, j)] = center_element.clone();
|
chol[(j, j)] = center_element.clone();
|
||||||
|
|
||||||
// update the jth column
|
// 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 = (col_jplus - bottom_left_corner * new_rowj.adjoint()) / center_element;
|
||||||
new_colj.gemm(
|
new_colj.gemm(
|
||||||
-T::one() / center_element.clone(),
|
-T::one() / center_element.clone(),
|
||||||
|
@ -317,10 +317,10 @@ where
|
||||||
&new_rowj_adjoint,
|
&new_rowj_adjoint,
|
||||||
T::one() / center_element,
|
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
|
// 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(
|
Self::xx_rank_one_update(
|
||||||
&mut bottom_right_corner,
|
&mut bottom_right_corner,
|
||||||
&mut new_colj,
|
&mut new_colj,
|
||||||
|
@ -348,17 +348,17 @@ where
|
||||||
self.chol.shape_generic().0.sub(Const::<1>),
|
self.chol.shape_generic().0.sub(Const::<1>),
|
||||||
self.chol.shape_generic().1.sub(Const::<1>),
|
self.chol.shape_generic().1.sub(Const::<1>),
|
||||||
);
|
);
|
||||||
chol.slice_range_mut(..j, ..j)
|
chol.view_range_mut(..j, ..j)
|
||||||
.copy_from(&self.chol.slice_range(..j, ..j));
|
.copy_from(&self.chol.view_range(..j, ..j));
|
||||||
chol.slice_range_mut(..j, j..)
|
chol.view_range_mut(..j, j..)
|
||||||
.copy_from(&self.chol.slice_range(..j, j + 1..));
|
.copy_from(&self.chol.view_range(..j, j + 1..));
|
||||||
chol.slice_range_mut(j.., ..j)
|
chol.view_range_mut(j.., ..j)
|
||||||
.copy_from(&self.chol.slice_range(j + 1.., ..j));
|
.copy_from(&self.chol.view_range(j + 1.., ..j));
|
||||||
chol.slice_range_mut(j.., j..)
|
chol.view_range_mut(j.., j..)
|
||||||
.copy_from(&self.chol.slice_range(j + 1.., j + 1..));
|
.copy_from(&self.chol.view_range(j + 1.., j + 1..));
|
||||||
|
|
||||||
// updates the bottom right corner
|
// 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 workspace = self.chol.column(j).clone_owned();
|
||||||
let mut old_colj = workspace.rows_range_mut(j + 1..);
|
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());
|
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())`.
|
/// 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`
|
/// 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>(
|
fn xx_rank_one_update<Dm, Sm, Rx, Sx>(
|
||||||
chol: &mut Matrix<T, Dm, Dm, Sm>,
|
chol: &mut Matrix<T, Dm, Dm, Sm>,
|
||||||
x: &mut Vector<T, Rx, Sx>,
|
x: &mut Vector<T, Rx, Sx>,
|
||||||
|
@ -404,7 +404,7 @@ where
|
||||||
beta += sigma_xj2 / diag2;
|
beta += sigma_xj2 / diag2;
|
||||||
// updates the terms of L
|
// updates the terms of L
|
||||||
let mut xjplus = x.rows_range_mut(j + 1..);
|
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;
|
// temp_jplus -= (wj / T::from_real(diag)) * col_j;
|
||||||
xjplus.axpy(-xj.clone() / T::from_real(diag.clone()), &col_j, T::one());
|
xjplus.axpy(-xj.clone() / T::from_real(diag.clone()), &col_j, T::one());
|
||||||
if gamma != crate::zero::<T::RealField>() {
|
if gamma != crate::zero::<T::RealField>() {
|
||||||
|
|
|
@ -78,7 +78,7 @@ where
|
||||||
let mut diag = Matrix::uninit(min_nrows_ncols, Const::<1>);
|
let mut diag = Matrix::uninit(min_nrows_ncols, Const::<1>);
|
||||||
|
|
||||||
for i in 0..min_nrows_ncols.value() {
|
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;
|
let col_piv = piv.1 + i;
|
||||||
matrix.swap_columns(i, col_piv);
|
matrix.swap_columns(i, col_piv);
|
||||||
p.append_permutation(i, col_piv);
|
p.append_permutation(i, col_piv);
|
||||||
|
@ -144,11 +144,11 @@ where
|
||||||
let dim = self.diag.len();
|
let dim = self.diag.len();
|
||||||
|
|
||||||
for i in (0..dim).rev() {
|
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.
|
// TODO: sometimes, the axis might have a zero magnitude.
|
||||||
let refl = Reflection::new(Unit::new_unchecked(axis), T::zero());
|
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());
|
refl.reflect_with_sign(&mut res_rows, self.diag[i].clone().signum());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,7 +191,7 @@ where
|
||||||
let dim = self.diag.len();
|
let dim = self.diag.len();
|
||||||
|
|
||||||
for i in 0..dim {
|
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 refl = Reflection::new(Unit::new_unchecked(axis), T::zero());
|
||||||
|
|
||||||
let mut rhs_rows = rhs.rows_range_mut(i..);
|
let mut rhs_rows = rhs.rows_range_mut(i..);
|
||||||
|
@ -281,7 +281,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
b.rows_range_mut(..i)
|
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
for i in 0..min_nrows_ncols.value() {
|
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 row_piv = piv.0 + i;
|
||||||
let col_piv = piv.1 + i;
|
let col_piv = piv.1 + i;
|
||||||
let diag = matrix[(row_piv, col_piv)].clone();
|
let diag = matrix[(row_piv, col_piv)].clone();
|
||||||
|
|
|
@ -113,7 +113,7 @@ where
|
||||||
let dim = self.hess.nrows();
|
let dim = self.hess.nrows();
|
||||||
self.hess.fill_lower_triangle(T::zero(), 2);
|
self.hess.fill_lower_triangle(T::zero(), 2);
|
||||||
self.hess
|
self.hess
|
||||||
.slice_mut((1, 0), (dim - 1, dim - 1))
|
.view_mut((1, 0), (dim - 1, dim - 1))
|
||||||
.set_partial_diagonal(
|
.set_partial_diagonal(
|
||||||
self.subdiag
|
self.subdiag
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -132,7 +132,7 @@ where
|
||||||
let dim = self.hess.nrows();
|
let dim = self.hess.nrows();
|
||||||
let mut res = self.hess.clone();
|
let mut res = self.hess.clone();
|
||||||
res.fill_lower_triangle(T::zero(), 2);
|
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(
|
.set_partial_diagonal(
|
||||||
self.subdiag
|
self.subdiag
|
||||||
.iter()
|
.iter()
|
||||||
|
|
|
@ -128,10 +128,10 @@ where
|
||||||
let mut res = OMatrix::identity_generic(dim, dim);
|
let mut res = OMatrix::identity_generic(dim, dim);
|
||||||
|
|
||||||
for i in (0..dim.value() - 1).rev() {
|
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 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());
|
refl.reflect_with_sign(&mut res_rows, signs[i].clone().signum());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,7 @@ where
|
||||||
out.fill_with_identity();
|
out.fill_with_identity();
|
||||||
|
|
||||||
for i in 0..dim {
|
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();
|
let diag = matrix[(piv, i)].clone();
|
||||||
|
|
||||||
if diag.is_zero() {
|
if diag.is_zero() {
|
||||||
|
@ -100,7 +100,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
for i in 0..min_nrows_ncols.value() {
|
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();
|
let diag = matrix[(piv, i)].clone();
|
||||||
|
|
||||||
if diag.is_zero() {
|
if diag.is_zero() {
|
||||||
|
@ -338,7 +338,7 @@ where
|
||||||
T: Scalar + Field,
|
T: Scalar + Field,
|
||||||
S: StorageMut<T, R, C>,
|
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;
|
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>,
|
S: StorageMut<T, R, C>,
|
||||||
{
|
{
|
||||||
let piv = piv - i;
|
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;
|
let inv_diag = T::one() / diag;
|
||||||
|
|
||||||
|
|
|
@ -116,11 +116,11 @@ where
|
||||||
let dim = self.diag.len();
|
let dim = self.diag.len();
|
||||||
|
|
||||||
for i in (0..dim).rev() {
|
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.
|
// TODO: sometimes, the axis might have a zero magnitude.
|
||||||
let refl = Reflection::new(Unit::new_unchecked(axis), T::zero());
|
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());
|
refl.reflect_with_sign(&mut res_rows, self.diag[i].clone().signum());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,7 +161,7 @@ where
|
||||||
let dim = self.diag.len();
|
let dim = self.diag.len();
|
||||||
|
|
||||||
for i in 0..dim {
|
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 refl = Reflection::new(Unit::new_unchecked(axis), T::zero());
|
||||||
|
|
||||||
let mut rhs_rows = rhs.rows_range_mut(i..);
|
let mut rhs_rows = rhs.rows_range_mut(i..);
|
||||||
|
@ -247,7 +247,7 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
b.rows_range_mut(..i)
|
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -174,19 +174,19 @@ where
|
||||||
{
|
{
|
||||||
let krows = cmp::min(k + 4, end + 1);
|
let krows = cmp::min(k + 4, end + 1);
|
||||||
let mut work = work.rows_mut(0, krows);
|
let mut work = work.rows_mut(0, krows);
|
||||||
refl.reflect(&mut t.generic_slice_mut(
|
refl.reflect(&mut t.generic_view_mut(
|
||||||
(k, k),
|
(k, k),
|
||||||
(Const::<3>, Dynamic::new(dim.value() - k)),
|
(Const::<3>, Dynamic::new(dim.value() - k)),
|
||||||
));
|
));
|
||||||
refl.reflect_rows(
|
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,
|
&mut work,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(ref mut q) = q {
|
if let Some(ref mut q) = q {
|
||||||
refl.reflect_rows(
|
refl.reflect_rows(
|
||||||
&mut q.generic_slice_mut((0, k), (dim, Const::<3>)),
|
&mut q.generic_view_mut((0, k), (dim, Const::<3>)),
|
||||||
work,
|
work,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -211,38 +211,38 @@ where
|
||||||
|
|
||||||
{
|
{
|
||||||
let mut work = work.rows_mut(0, end + 1);
|
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),
|
(m, m),
|
||||||
(Const::<2>, Dynamic::new(dim.value() - m)),
|
(Const::<2>, Dynamic::new(dim.value() - m)),
|
||||||
));
|
));
|
||||||
refl.reflect_rows(
|
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,
|
&mut work,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(ref mut q) = q {
|
if let Some(ref mut q) = q {
|
||||||
refl.reflect_rows(
|
refl.reflect_rows(
|
||||||
&mut q.generic_slice_mut((0, m), (dim, Const::<2>)),
|
&mut q.generic_view_mut((0, m), (dim, Const::<2>)),
|
||||||
work,
|
work,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Decouple the 2x2 block if it has real eigenvalues.
|
// 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();
|
let inv_rot = rot.inverse();
|
||||||
inv_rot.rotate(&mut t.generic_slice_mut(
|
inv_rot.rotate(&mut t.generic_view_mut(
|
||||||
(start, start),
|
(start, start),
|
||||||
(Const::<2>, Dynamic::new(dim.value() - start)),
|
(Const::<2>, Dynamic::new(dim.value() - start)),
|
||||||
));
|
));
|
||||||
rot.rotate_rows(
|
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();
|
t[(end, start)] = T::zero();
|
||||||
|
|
||||||
if let Some(ref mut q) = q {
|
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 dim = m.shape_generic().0;
|
||||||
let mut q = None;
|
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) => {
|
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();
|
let inv_rot = rot.inverse();
|
||||||
inv_rot.rotate(&mut m);
|
inv_rot.rotate(&mut m);
|
||||||
rot.rotate_rows(&mut m);
|
rot.rotate_rows(&mut m);
|
||||||
|
@ -530,7 +530,7 @@ where
|
||||||
if self.nrows() == 2 {
|
if self.nrows() == 2 {
|
||||||
// TODO: can we avoid this slicing
|
// TODO: can we avoid this slicing
|
||||||
// (which is needed here just to transform D to U2)?
|
// (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) {
|
return match compute_2x2_eigvals(&me) {
|
||||||
Some((a, b)) => {
|
Some((a, b)) => {
|
||||||
work[0] = a;
|
work[0] = a;
|
||||||
|
|
|
@ -93,7 +93,7 @@ impl<T: ComplexField, D: Dim, S: Storage<T, D, D>> SquareMatrix<T, D, S> {
|
||||||
}
|
}
|
||||||
|
|
||||||
b.rows_range_mut(i + 1..)
|
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
|
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 {
|
for i in 0..dim - 1 {
|
||||||
let coeff = unsafe { bcol.vget_unchecked(i).clone() } / diag.clone();
|
let coeff = unsafe { bcol.vget_unchecked(i).clone() } / diag.clone();
|
||||||
bcol.rows_range_mut(i + 1..)
|
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)
|
b.rows_range_mut(..i)
|
||||||
.axpy(-coeff, &self.slice_range(..i, i), T::one());
|
.axpy(-coeff, &self.view_range(..i, i), T::one());
|
||||||
}
|
}
|
||||||
|
|
||||||
true
|
true
|
||||||
|
@ -387,7 +387,7 @@ impl<T: ComplexField, D: Dim, S: Storage<T, D, D>> SquareMatrix<T, D, S> {
|
||||||
let dim = self.nrows();
|
let dim = self.nrows();
|
||||||
|
|
||||||
for i in (0..dim).rev() {
|
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 {
|
unsafe {
|
||||||
let b_i = b.vget_unchecked_mut(i);
|
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();
|
let dim = self.nrows();
|
||||||
|
|
||||||
for i in 0..dim {
|
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 {
|
unsafe {
|
||||||
let b_i = b.vget_unchecked_mut(i);
|
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..)
|
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 {
|
for i in 0..dim - 1 {
|
||||||
let coeff = unsafe { bcol.vget_unchecked(i).clone() } / diag.clone();
|
let coeff = unsafe { bcol.vget_unchecked(i).clone() } / diag.clone();
|
||||||
bcol.rows_range_mut(i + 1..)
|
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)
|
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();
|
let dim = self.nrows();
|
||||||
|
|
||||||
for i in (0..dim).rev() {
|
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 {
|
unsafe {
|
||||||
let b_i = b.vget_unchecked_mut(i);
|
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>,
|
ShapeConstraint: SameNumberOfRows<R2, D>,
|
||||||
{
|
{
|
||||||
for i in 0..self.nrows() {
|
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 {
|
unsafe {
|
||||||
let b_i = b.vget_unchecked_mut(i);
|
let b_i = b.vget_unchecked_mut(i);
|
||||||
|
|
Loading…
Reference in New Issue