Fix most clippy warnings

This commit is contained in:
Violeta Hernández 2021-06-18 02:45:37 -05:00 committed by GitHub
parent 38add0b00d
commit 281b140365
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
39 changed files with 318 additions and 298 deletions

View File

@ -278,6 +278,7 @@ where
}
}
#[allow(clippy::too_many_arguments)]
fn array_axcpy<T>(
y: &mut [T],
a: T,
@ -334,6 +335,7 @@ where
/// assert_eq!(vec1, Vector3::new(6.0, 12.0, 18.0));
/// ```
#[inline]
#[allow(clippy::many_single_char_names)]
pub fn axcpy<D2: Dim, SB>(&mut self, a: T, x: &Vector<T, D2, SB>, c: T, b: T)
where
SB: Storage<T, D2>,

View File

@ -906,6 +906,7 @@ macro_rules! componentwise_constructors_impl(
impl<T> Matrix<T, Const<$R>, Const<$C>, ArrayStorage<T, $R, $C>> {
/// Initializes this matrix from its components.
#[inline]
#[allow(clippy::too_many_arguments)]
pub const fn new($($($args: T),*),*) -> Self {
unsafe {
Self::from_data_statically_unchecked(

View File

@ -2,7 +2,6 @@
use alloc::vec::Vec;
use simba::scalar::{SubsetOf, SupersetOf};
use std::convert::{AsMut, AsRef, From, Into};
use std::mem;
use simba::simd::{PrimitiveSimdValue, SimdValue};
@ -110,11 +109,11 @@ impl<T: Scalar, const D: usize> From<[T; D]> for SVector<T, D> {
}
}
impl<T: Scalar, const D: usize> Into<[T; D]> for SVector<T, D> {
impl<T: Scalar, const D: usize> From<SVector<T, D>> for [T; D] {
#[inline]
fn into(self) -> [T; D] {
fn from(vec: SVector<T, D>) -> Self {
// TODO: unfortunately, we must clone because we can move out of an array.
self.data.0[0].clone()
vec.data.0[0].clone()
}
}
@ -128,13 +127,13 @@ where
}
}
impl<T: Scalar, const D: usize> Into<[T; D]> for RowSVector<T, D>
impl<T: Scalar, const D: usize> From<RowSVector<T, D>> for [T; D]
where
Const<D>: IsNotStaticOne,
{
#[inline]
fn into(self) -> [T; D] {
self.transpose().into()
fn from(vec: RowSVector<T, D>) -> [T; D] {
vec.transpose().into()
}
}
@ -146,7 +145,7 @@ macro_rules! impl_from_into_asref_1D(
#[inline]
fn as_ref(&self) -> &[T; $SZ] {
unsafe {
mem::transmute(self.data.ptr())
&*(self.data.ptr() as *const [T; $SZ])
}
}
}
@ -157,7 +156,7 @@ macro_rules! impl_from_into_asref_1D(
#[inline]
fn as_mut(&mut self) -> &mut [T; $SZ] {
unsafe {
mem::transmute(self.data.ptr_mut())
&mut *(self.data.ptr_mut() as *mut [T; $SZ])
}
}
}
@ -186,10 +185,10 @@ impl<T: Scalar, const R: usize, const C: usize> From<[[T; R]; C]> for SMatrix<T,
}
}
impl<T: Scalar, const R: usize, const C: usize> Into<[[T; R]; C]> for SMatrix<T, R, C> {
impl<T: Scalar, const R: usize, const C: usize> From<SMatrix<T, R, C>> for [[T; R]; C] {
#[inline]
fn into(self) -> [[T; R]; C] {
self.data.0
fn from(vec: SMatrix<T, R, C>) -> Self {
vec.data.0
}
}
@ -200,7 +199,7 @@ macro_rules! impl_from_into_asref_2D(
#[inline]
fn as_ref(&self) -> &[[T; $SZRows]; $SZCols] {
unsafe {
mem::transmute(self.data.ptr())
&*(self.data.ptr() as *const [[T; $SZRows]; $SZCols])
}
}
}
@ -210,7 +209,7 @@ macro_rules! impl_from_into_asref_2D(
#[inline]
fn as_mut(&mut self) -> &mut [[T; $SZRows]; $SZCols] {
unsafe {
mem::transmute(self.data.ptr_mut())
&mut *(self.data.ptr_mut() as *mut [[T; $SZRows]; $SZCols])
}
}
}
@ -427,21 +426,21 @@ impl<'a, T: Scalar> From<Vec<T>> for DVector<T> {
}
}
impl<'a, T: Scalar + Copy, R: Dim, C: Dim, S: ContiguousStorage<T, R, C>> Into<&'a [T]>
for &'a Matrix<T, R, C, S>
impl<'a, T: Scalar + Copy, R: Dim, C: Dim, S: ContiguousStorage<T, R, C>>
From<&'a Matrix<T, R, C, S>> for &'a [T]
{
#[inline]
fn into(self) -> &'a [T] {
self.as_slice()
fn from(matrix: &'a Matrix<T, R, C, S>) -> Self {
matrix.as_slice()
}
}
impl<'a, T: Scalar + Copy, R: Dim, C: Dim, S: ContiguousStorageMut<T, R, C>> Into<&'a mut [T]>
for &'a mut Matrix<T, R, C, S>
impl<'a, T: Scalar + Copy, R: Dim, C: Dim, S: ContiguousStorageMut<T, R, C>>
From<&'a mut Matrix<T, R, C, S>> for &'a mut [T]
{
#[inline]
fn into(self) -> &'a mut [T] {
self.as_mut_slice()
fn from(matrix: &'a mut Matrix<T, R, C, S>) -> Self {
matrix.as_mut_slice()
}
}

View File

@ -4,7 +4,6 @@
//! components using their names. For example, if `v` is a 3D vector, one can write `v.z` instead
//! of `v[2]`.
use std::mem;
use std::ops::{Deref, DerefMut};
use crate::base::dimension::{U1, U2, U3, U4, U5, U6};
@ -38,7 +37,7 @@ macro_rules! deref_impl(
#[inline]
fn deref(&self) -> &Self::Target {
unsafe { mem::transmute(self.data.ptr()) }
unsafe { &*(self.data.ptr() as *const Self::Target) }
}
}
@ -46,7 +45,7 @@ macro_rules! deref_impl(
where S: ContiguousStorageMut<T, $R, $C> {
#[inline]
fn deref_mut(&mut self) -> &mut Self::Target {
unsafe { mem::transmute(self.data.ptr_mut()) }
unsafe { &mut *(self.data.ptr_mut() as *mut Self::Target) }
}
}
}

View File

@ -96,6 +96,10 @@ macro_rules! iterator {
let stride = self.strides.0.value();
self.ptr = self.ptr.add(stride);
}
// We want either `& *last` or `&mut *last` here, depending
// on the mutability of `$Ref`.
#[allow(clippy::transmute_ptr_to_ref)]
Some(mem::transmute(old))
}
}
@ -139,13 +143,13 @@ macro_rules! iterator {
let inner_remaining = self.size % inner_size;
// Compute pointer to last element
let last = self.ptr.offset(
(outer_remaining * outer_stride + inner_remaining * inner_stride)
as isize,
);
let last = self
.ptr
.add((outer_remaining * outer_stride + inner_remaining * inner_stride));
// We want either `& *last` or `&mut *last` here, depending
// on the mutability of `$Ref`.
#[allow(clippy::transmute_ptr_to_ref)]
Some(mem::transmute(last))
}
}

View File

@ -567,6 +567,7 @@ impl<T: Scalar, R: Dim, C: Dim, S: Storage<T, R, C>> Matrix<T, R, C, S> {
/// Tests whether `self` and `rhs` are exactly equal.
#[inline]
#[must_use]
#[allow(clippy::should_implement_trait)]
pub fn eq<R2, C2, SB>(&self, other: &Matrix<T, R2, C2, SB>) -> bool
where
T: PartialEq,

View File

@ -529,7 +529,7 @@ macro_rules! left_scalar_mul_impl(
// for rhs in res.iter_mut() {
for rhs in res.as_mut_slice().iter_mut() {
*rhs = self * *rhs
*rhs *= self
}
res

View File

@ -1,6 +1,5 @@
#[cfg(feature = "abomonation-serialize")]
use std::io::{Result as IOResult, Write};
use std::mem;
use std::ops::Deref;
#[cfg(feature = "serde-serialize-no-std")]
@ -228,8 +227,8 @@ impl<T> Unit<T> {
/// Wraps the given reference, assuming it is already normalized.
#[inline]
pub fn from_ref_unchecked<'a>(value: &'a T) -> &'a Self {
unsafe { mem::transmute(value) }
pub fn from_ref_unchecked(value: &T) -> &Self {
unsafe { &*(value as *const T as *const Self) }
}
/// Retrieves the underlying value.
@ -332,7 +331,7 @@ impl<T> Deref for Unit<T> {
#[inline]
fn deref(&self) -> &T {
unsafe { mem::transmute(self) }
unsafe { &*(self as *const Self as *const T) }
}
}

View File

@ -143,9 +143,9 @@ impl<T, R: Dim, C: Dim> VecStorage<T, R, C> {
}
}
impl<T, R: Dim, C: Dim> Into<Vec<T>> for VecStorage<T, R, C> {
fn into(self) -> Vec<T> {
self.data
impl<T, R: Dim, C: Dim> From<VecStorage<T, R, C>> for Vec<T> {
fn from(vec: VecStorage<T, R, C>) -> Self {
vec.data
}
}

View File

@ -1,3 +1,6 @@
// The macros break if the references are taken out, for some reason.
#![allow(clippy::op_ref)]
use crate::{
Isometry3, Matrix4, Normed, OVector, Point3, Quaternion, Scalar, SimdRealField, Translation3,
Unit, UnitQuaternion, Vector3, Zero, U8,
@ -273,7 +276,7 @@ where
impl<T: RealField> DualQuaternion<T> {
fn to_vector(&self) -> OVector<T, U8> {
self.as_ref().clone().into()
(*self.as_ref()).into()
}
}
@ -618,9 +621,9 @@ where
let other = {
let dot_product = self.as_ref().real.coords.dot(&other.as_ref().real.coords);
if dot_product < T::zero() {
-other.clone()
-*other
} else {
other.clone()
*other
}
};

View File

@ -186,9 +186,9 @@ where
pub fn from_parts(translation: Translation3<T>, rotation: UnitQuaternion<T>) -> Self {
let half: T = crate::convert(0.5f64);
UnitDualQuaternion::new_unchecked(DualQuaternion {
real: rotation.clone().into_inner(),
real: rotation.into_inner(),
dual: Quaternion::from_parts(T::zero(), translation.vector)
* rotation.clone().into_inner()
* rotation.into_inner()
* half,
})
}

View File

@ -1,3 +1,6 @@
// The macros break if the references are taken out, for some reason.
#![allow(clippy::op_ref)]
/*
* This file provides:
*
@ -49,7 +52,6 @@ use crate::{
DualQuaternion, Isometry3, Point, Point3, Quaternion, SimdRealField, Translation3, Unit,
UnitDualQuaternion, UnitQuaternion, Vector, Vector3, U3,
};
use std::mem;
use std::ops::{
Add, AddAssign, Div, DivAssign, Index, IndexMut, Mul, MulAssign, Neg, Sub, SubAssign,
};
@ -57,14 +59,14 @@ use std::ops::{
impl<T: SimdRealField> AsRef<[T; 8]> for DualQuaternion<T> {
#[inline]
fn as_ref(&self) -> &[T; 8] {
unsafe { mem::transmute(self) }
unsafe { &*(self as *const Self as *const [T; 8]) }
}
}
impl<T: SimdRealField> AsMut<[T; 8]> for DualQuaternion<T> {
#[inline]
fn as_mut(&mut self) -> &mut [T; 8] {
unsafe { mem::transmute(self) }
unsafe { &mut *(self as *mut Self as *mut [T; 8]) }
}
}
@ -564,7 +566,7 @@ dual_quaternion_op_impl!(
(U4, U1), (U3, U1);
self: &'a UnitDualQuaternion<T>, rhs: &'b Translation3<T>,
Output = UnitDualQuaternion<T> => U3, U1;
self * UnitDualQuaternion::<T>::from_parts(rhs.clone(), UnitQuaternion::identity());
self * UnitDualQuaternion::<T>::from_parts(*rhs, UnitQuaternion::identity());
'a, 'b);
dual_quaternion_op_impl!(
@ -580,7 +582,7 @@ dual_quaternion_op_impl!(
(U4, U1), (U3, U3);
self: UnitDualQuaternion<T>, rhs: &'b Translation3<T>,
Output = UnitDualQuaternion<T> => U3, U1;
self * UnitDualQuaternion::<T>::from_parts(rhs.clone(), UnitQuaternion::identity());
self * UnitDualQuaternion::<T>::from_parts(*rhs, UnitQuaternion::identity());
'b);
dual_quaternion_op_impl!(
@ -632,7 +634,7 @@ dual_quaternion_op_impl!(
(U3, U1), (U4, U1);
self: &'b Translation3<T>, rhs: &'a UnitDualQuaternion<T>,
Output = UnitDualQuaternion<T> => U3, U1;
UnitDualQuaternion::<T>::from_parts(self.clone(), UnitQuaternion::identity()) * rhs;
UnitDualQuaternion::<T>::from_parts(*self, UnitQuaternion::identity()) * rhs;
'a, 'b);
dual_quaternion_op_impl!(
@ -640,7 +642,7 @@ dual_quaternion_op_impl!(
(U3, U1), (U4, U1);
self: &'a Translation3<T>, rhs: UnitDualQuaternion<T>,
Output = UnitDualQuaternion<T> => U3, U1;
UnitDualQuaternion::<T>::from_parts(self.clone(), UnitQuaternion::identity()) * rhs;
UnitDualQuaternion::<T>::from_parts(*self, UnitQuaternion::identity()) * rhs;
'a);
dual_quaternion_op_impl!(
@ -664,7 +666,7 @@ dual_quaternion_op_impl!(
(U3, U1), (U4, U1);
self: &'b Translation3<T>, rhs: &'a UnitDualQuaternion<T>,
Output = UnitDualQuaternion<T> => U3, U1;
UnitDualQuaternion::<T>::from_parts(self.clone(), UnitQuaternion::identity()) / rhs;
UnitDualQuaternion::<T>::from_parts(*self, UnitQuaternion::identity()) / rhs;
'a, 'b);
dual_quaternion_op_impl!(
@ -672,7 +674,7 @@ dual_quaternion_op_impl!(
(U3, U1), (U4, U1);
self: &'a Translation3<T>, rhs: UnitDualQuaternion<T>,
Output = UnitDualQuaternion<T> => U3, U1;
UnitDualQuaternion::<T>::from_parts(self.clone(), UnitQuaternion::identity()) / rhs;
UnitDualQuaternion::<T>::from_parts(*self, UnitQuaternion::identity()) / rhs;
'a);
dual_quaternion_op_impl!(
@ -860,7 +862,7 @@ dual_quaternion_op_impl!(
Output = Point3<T> => U3, U1;
{
let two: T = crate::convert(2.0f64);
let q_point = Quaternion::from_parts(T::zero(), rhs.coords.clone());
let q_point = Quaternion::from_parts(T::zero(), rhs.coords);
Point::from(
((self.as_ref().real * q_point + self.as_ref().dual * two) * self.as_ref().real.conjugate())
.vector()
@ -1115,7 +1117,7 @@ dual_quaternion_op_impl!(
MulAssign, mul_assign;
(U4, U1), (U4, U1);
self: UnitDualQuaternion<T>, rhs: &'b UnitQuaternion<T>;
*self *= rhs.clone(); 'b);
*self *= *rhs; 'b);
// UnitDualQuaternion ÷= UnitQuaternion
dual_quaternion_op_impl!(
@ -1151,7 +1153,7 @@ dual_quaternion_op_impl!(
MulAssign, mul_assign;
(U4, U1), (U4, U1);
self: UnitDualQuaternion<T>, rhs: &'b Translation3<T>;
*self *= rhs.clone(); 'b);
*self *= *rhs; 'b);
// UnitDualQuaternion ÷= Translation3
dual_quaternion_op_impl!(

View File

@ -270,7 +270,7 @@ where
#[must_use]
pub fn inv_mul(&self, rhs: &Isometry<T, R, D>) -> Self {
let inv_rot1 = self.rotation.inverse();
let tr_12 = rhs.translation.vector.clone() - self.translation.vector.clone();
let tr_12 = rhs.translation.vector - self.translation.vector;
Isometry::from_parts(
inv_rot1.transform_vector(&tr_12).into(),
inv_rot1 * rhs.rotation.clone(),
@ -435,7 +435,7 @@ where
#[must_use]
pub fn inverse_transform_point(&self, pt: &Point<T, D>) -> Point<T, D> {
self.rotation
.inverse_transform_point(&(pt - &self.translation.vector))
.inverse_transform_point(&(pt - self.translation.vector))
}
/// Transform the given vector by the inverse of this isometry, ignoring the

View File

@ -239,7 +239,7 @@ where
{
#[inline]
fn from(arr: [Isometry<T::Element, R::Element, D>; 2]) -> Self {
let tra = Translation::from([arr[0].translation.clone(), arr[1].translation.clone()]);
let tra = Translation::from([arr[0].translation, arr[1].translation]);
let rot = R::from([arr[0].rotation, arr[0].rotation]);
Self::from_parts(tra, rot)
@ -258,10 +258,10 @@ where
#[inline]
fn from(arr: [Isometry<T::Element, R::Element, D>; 4]) -> Self {
let tra = Translation::from([
arr[0].translation.clone(),
arr[1].translation.clone(),
arr[2].translation.clone(),
arr[3].translation.clone(),
arr[0].translation,
arr[1].translation,
arr[2].translation,
arr[3].translation,
]);
let rot = R::from([
arr[0].rotation,
@ -286,14 +286,14 @@ where
#[inline]
fn from(arr: [Isometry<T::Element, R::Element, D>; 8]) -> Self {
let tra = Translation::from([
arr[0].translation.clone(),
arr[1].translation.clone(),
arr[2].translation.clone(),
arr[3].translation.clone(),
arr[4].translation.clone(),
arr[5].translation.clone(),
arr[6].translation.clone(),
arr[7].translation.clone(),
arr[0].translation,
arr[1].translation,
arr[2].translation,
arr[3].translation,
arr[4].translation,
arr[5].translation,
arr[6].translation,
arr[7].translation,
]);
let rot = R::from([
arr[0].rotation,
@ -322,22 +322,22 @@ where
#[inline]
fn from(arr: [Isometry<T::Element, R::Element, D>; 16]) -> Self {
let tra = Translation::from([
arr[0].translation.clone(),
arr[1].translation.clone(),
arr[2].translation.clone(),
arr[3].translation.clone(),
arr[4].translation.clone(),
arr[5].translation.clone(),
arr[6].translation.clone(),
arr[7].translation.clone(),
arr[8].translation.clone(),
arr[9].translation.clone(),
arr[10].translation.clone(),
arr[11].translation.clone(),
arr[12].translation.clone(),
arr[13].translation.clone(),
arr[14].translation.clone(),
arr[15].translation.clone(),
arr[0].translation,
arr[1].translation,
arr[2].translation,
arr[3].translation,
arr[4].translation,
arr[5].translation,
arr[6].translation,
arr[7].translation,
arr[8].translation,
arr[9].translation,
arr[10].translation,
arr[11].translation,
arr[12].translation,
arr[13].translation,
arr[14].translation,
arr[15].translation,
]);
let rot = R::from([
arr[0].rotation,

View File

@ -1,3 +1,6 @@
// The macros break if the references are taken out, for some reason.
#![allow(clippy::op_ref)]
use num::{One, Zero};
use std::ops::{Div, DivAssign, Mul, MulAssign};
@ -198,7 +201,7 @@ md_assign_impl_all!(
const D; for; where;
self: Isometry<T, Rotation<T, D>, D>, rhs: Rotation<T, D>;
[val] => self.rotation *= rhs;
[ref] => self.rotation *= rhs.clone();
[ref] => self.rotation *= *rhs;
);
md_assign_impl_all!(
@ -365,9 +368,9 @@ isometry_from_composition_impl_all!(
D;
self: Rotation<T, D>, right: Translation<T, D>, Output = Isometry<T, Rotation<T, D>, D>;
[val val] => Isometry::from_parts(Translation::from(&self * right.vector), self);
[ref val] => Isometry::from_parts(Translation::from(self * right.vector), self.clone());
[ref val] => Isometry::from_parts(Translation::from(self * right.vector), *self);
[val ref] => Isometry::from_parts(Translation::from(&self * &right.vector), self);
[ref ref] => Isometry::from_parts(Translation::from(self * &right.vector), self.clone());
[ref ref] => Isometry::from_parts(Translation::from(self * &right.vector), *self);
);
// UnitQuaternion × Translation
@ -389,9 +392,9 @@ isometry_from_composition_impl_all!(
self: Isometry<T, Rotation<T, D>, D>, rhs: Rotation<T, D>,
Output = Isometry<T, Rotation<T, D>, D>;
[val val] => Isometry::from_parts(self.translation, self.rotation * rhs);
[ref val] => Isometry::from_parts(self.translation.clone(), self.rotation.clone() * rhs); // TODO: do not clone.
[val ref] => Isometry::from_parts(self.translation, self.rotation * rhs.clone());
[ref ref] => Isometry::from_parts(self.translation.clone(), self.rotation.clone() * rhs.clone());
[ref val] => Isometry::from_parts(self.translation, self.rotation * rhs);
[val ref] => Isometry::from_parts(self.translation, self.rotation * *rhs);
[ref ref] => Isometry::from_parts(self.translation, self.rotation * *rhs);
);
// Rotation × Isometry
@ -416,9 +419,9 @@ isometry_from_composition_impl_all!(
self: Isometry<T, Rotation<T, D>, D>, rhs: Rotation<T, D>,
Output = Isometry<T, Rotation<T, D>, D>;
[val val] => Isometry::from_parts(self.translation, self.rotation / rhs);
[ref val] => Isometry::from_parts(self.translation.clone(), self.rotation.clone() / rhs); // TODO: do not clone.
[val ref] => Isometry::from_parts(self.translation, self.rotation / rhs.clone());
[ref ref] => Isometry::from_parts(self.translation.clone(), self.rotation.clone() / rhs.clone());
[ref val] => Isometry::from_parts(self.translation, self.rotation / rhs);
[val ref] => Isometry::from_parts(self.translation, self.rotation / *rhs);
[ref ref] => Isometry::from_parts(self.translation, self.rotation / *rhs);
);
// Rotation ÷ Isometry
@ -441,9 +444,9 @@ isometry_from_composition_impl_all!(
self: Isometry<T, UnitQuaternion<T>, 3>, rhs: UnitQuaternion<T>,
Output = Isometry<T, UnitQuaternion<T>, 3>;
[val val] => Isometry::from_parts(self.translation, self.rotation * rhs);
[ref val] => Isometry::from_parts(self.translation.clone(), self.rotation * rhs); // TODO: do not clone.
[ref val] => Isometry::from_parts(self.translation, self.rotation * rhs);
[val ref] => Isometry::from_parts(self.translation, self.rotation * *rhs);
[ref ref] => Isometry::from_parts(self.translation.clone(), self.rotation * *rhs);
[ref ref] => Isometry::from_parts(self.translation, self.rotation * *rhs);
);
// UnitQuaternion × Isometry
@ -468,9 +471,9 @@ isometry_from_composition_impl_all!(
self: Isometry<T, UnitQuaternion<T>, 3>, rhs: UnitQuaternion<T>,
Output = Isometry<T, UnitQuaternion<T>, 3>;
[val val] => Isometry::from_parts(self.translation, self.rotation / rhs);
[ref val] => Isometry::from_parts(self.translation.clone(), self.rotation / rhs); // TODO: do not clone.
[ref val] => Isometry::from_parts(self.translation, self.rotation / rhs);
[val ref] => Isometry::from_parts(self.translation, self.rotation / *rhs);
[ref ref] => Isometry::from_parts(self.translation.clone(), self.rotation / *rhs);
[ref ref] => Isometry::from_parts(self.translation, self.rotation / *rhs);
);
// UnitQuaternion ÷ Isometry
@ -492,9 +495,9 @@ isometry_from_composition_impl_all!(
D;
self: Translation<T, D>, right: Rotation<T, D>, Output = Isometry<T, Rotation<T, D>, D>;
[val val] => Isometry::from_parts(self, right);
[ref val] => Isometry::from_parts(self.clone(), right);
[val ref] => Isometry::from_parts(self, right.clone());
[ref ref] => Isometry::from_parts(self.clone(), right.clone());
[ref val] => Isometry::from_parts(*self, right);
[val ref] => Isometry::from_parts(self, *right);
[ref ref] => Isometry::from_parts(*self, *right);
);
// Translation × UnitQuaternion
@ -503,9 +506,9 @@ isometry_from_composition_impl_all!(
;
self: Translation<T, 3>, right: UnitQuaternion<T>, Output = Isometry<T, UnitQuaternion<T>, 3>;
[val val] => Isometry::from_parts(self, right);
[ref val] => Isometry::from_parts(self.clone(), right);
[ref val] => Isometry::from_parts(*self, right);
[val ref] => Isometry::from_parts(self, *right);
[ref ref] => Isometry::from_parts(self.clone(), *right);
[ref ref] => Isometry::from_parts(*self, *right);
);
// Isometry × UnitComplex
@ -515,9 +518,9 @@ isometry_from_composition_impl_all!(
self: Isometry<T, UnitComplex<T>, 2>, rhs: UnitComplex<T>,
Output = Isometry<T, UnitComplex<T>, 2>;
[val val] => Isometry::from_parts(self.translation, self.rotation * rhs);
[ref val] => Isometry::from_parts(self.translation.clone(), self.rotation * rhs); // TODO: do not clone.
[ref val] => Isometry::from_parts(self.translation, self.rotation * rhs);
[val ref] => Isometry::from_parts(self.translation, self.rotation * *rhs);
[ref ref] => Isometry::from_parts(self.translation.clone(), self.rotation * *rhs);
[ref ref] => Isometry::from_parts(self.translation, self.rotation * *rhs);
);
// Isometry ÷ UnitComplex
@ -527,7 +530,7 @@ isometry_from_composition_impl_all!(
self: Isometry<T, UnitComplex<T>, 2>, rhs: UnitComplex<T>,
Output = Isometry<T, UnitComplex<T>, 2>;
[val val] => Isometry::from_parts(self.translation, self.rotation / rhs);
[ref val] => Isometry::from_parts(self.translation.clone(), self.rotation / rhs); // TODO: do not clone.
[ref val] => Isometry::from_parts(self.translation, self.rotation / rhs);
[val ref] => Isometry::from_parts(self.translation, self.rotation / *rhs);
[ref ref] => Isometry::from_parts(self.translation.clone(), self.rotation / *rhs);
[ref ref] => Isometry::from_parts(self.translation, self.rotation / *rhs);
);

View File

@ -8,7 +8,6 @@ use rand::{
#[cfg(feature = "serde-serialize-no-std")]
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::fmt;
use std::mem;
use simba::scalar::RealField;
@ -258,7 +257,7 @@ impl<T: RealField> Orthographic3<T> {
#[inline]
#[must_use]
pub fn as_projective(&self) -> &Projective3<T> {
unsafe { mem::transmute(self) }
unsafe { &*(self as *const Orthographic3<T> as *const Projective3<T>) }
}
/// This transformation seen as a `Projective3`.

View File

@ -9,7 +9,6 @@ use rand::{
#[cfg(feature = "serde-serialize-no-std")]
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use std::fmt;
use std::mem;
use simba::scalar::RealField;
@ -140,7 +139,7 @@ impl<T: RealField> Perspective3<T> {
#[inline]
#[must_use]
pub fn as_projective(&self) -> &Projective3<T> {
unsafe { mem::transmute(self) }
unsafe { &*(self as *const Perspective3<T> as *const Projective3<T>) }
}
/// This transformation seen as a `Projective3`.
@ -256,8 +255,9 @@ impl<T: RealField> Perspective3<T> {
#[inline]
pub fn set_fovy(&mut self, fovy: T) {
let old_m22 = self.matrix[(1, 1)];
self.matrix[(1, 1)] = T::one() / (fovy / crate::convert(2.0)).tan();
self.matrix[(0, 0)] = self.matrix[(0, 0)] * (self.matrix[(1, 1)] / old_m22);
let new_m22 = T::one() / (fovy / crate::convert(2.0)).tan();
self.matrix[(1, 1)] = new_m22;
self.matrix[(0, 0)] *= new_m22 / old_m22;
}
/// Updates this perspective matrix with a new near plane offset of the view frustum.

View File

@ -90,10 +90,10 @@ impl<T: Scalar, const D: usize> From<[T; D]> for Point<T, D> {
}
}
impl<T: Scalar, const D: usize> Into<[T; D]> for Point<T, D> {
impl<T: Scalar, const D: usize> From<Point<T, D>> for [T; D] {
#[inline]
fn into(self) -> [T; D] {
self.coords.into()
fn from(p: Point<T, D>) -> Self {
p.coords.into()
}
}

View File

@ -1,4 +1,3 @@
use std::mem;
use std::ops::{Deref, DerefMut};
use simba::simd::SimdValue;
@ -13,13 +12,13 @@ impl<T: Scalar + SimdValue> Deref for Quaternion<T> {
#[inline]
fn deref(&self) -> &Self::Target {
unsafe { mem::transmute(self) }
unsafe { &*(self as *const Self as *const Self::Target) }
}
}
impl<T: Scalar + SimdValue> DerefMut for Quaternion<T> {
#[inline]
fn deref_mut(&mut self) -> &mut Self::Target {
unsafe { mem::transmute(self) }
unsafe { &mut *(self as *mut Self as *mut Self::Target) }
}
}

View File

@ -1,3 +1,6 @@
// The macros break if the references are taken out, for some reason.
#![allow(clippy::op_ref)]
/*
* This file provides:
* ===================

View File

@ -267,10 +267,7 @@ where
{
#[inline]
fn from(arr: [Rotation<T::Element, D>; 2]) -> Self {
Self::from_matrix_unchecked(OMatrix::from([
arr[0].clone().into_inner(),
arr[1].clone().into_inner(),
]))
Self::from_matrix_unchecked(OMatrix::from([arr[0].into_inner(), arr[1].into_inner()]))
}
}
@ -283,10 +280,10 @@ where
#[inline]
fn from(arr: [Rotation<T::Element, D>; 4]) -> Self {
Self::from_matrix_unchecked(OMatrix::from([
arr[0].clone().into_inner(),
arr[1].clone().into_inner(),
arr[2].clone().into_inner(),
arr[3].clone().into_inner(),
arr[0].into_inner(),
arr[1].into_inner(),
arr[2].into_inner(),
arr[3].into_inner(),
]))
}
}
@ -300,14 +297,14 @@ where
#[inline]
fn from(arr: [Rotation<T::Element, D>; 8]) -> Self {
Self::from_matrix_unchecked(OMatrix::from([
arr[0].clone().into_inner(),
arr[1].clone().into_inner(),
arr[2].clone().into_inner(),
arr[3].clone().into_inner(),
arr[4].clone().into_inner(),
arr[5].clone().into_inner(),
arr[6].clone().into_inner(),
arr[7].clone().into_inner(),
arr[0].into_inner(),
arr[1].into_inner(),
arr[2].into_inner(),
arr[3].into_inner(),
arr[4].into_inner(),
arr[5].into_inner(),
arr[6].into_inner(),
arr[7].into_inner(),
]))
}
}
@ -321,22 +318,22 @@ where
#[inline]
fn from(arr: [Rotation<T::Element, D>; 16]) -> Self {
Self::from_matrix_unchecked(OMatrix::from([
arr[0].clone().into_inner(),
arr[1].clone().into_inner(),
arr[2].clone().into_inner(),
arr[3].clone().into_inner(),
arr[4].clone().into_inner(),
arr[5].clone().into_inner(),
arr[6].clone().into_inner(),
arr[7].clone().into_inner(),
arr[8].clone().into_inner(),
arr[9].clone().into_inner(),
arr[10].clone().into_inner(),
arr[11].clone().into_inner(),
arr[12].clone().into_inner(),
arr[13].clone().into_inner(),
arr[14].clone().into_inner(),
arr[15].clone().into_inner(),
arr[0].into_inner(),
arr[1].into_inner(),
arr[2].into_inner(),
arr[3].into_inner(),
arr[4].into_inner(),
arr[5].into_inner(),
arr[6].into_inner(),
arr[7].into_inner(),
arr[8].into_inner(),
arr[9].into_inner(),
arr[10].into_inner(),
arr[11].into_inner(),
arr[12].into_inner(),
arr[13].into_inner(),
arr[14].into_inner(),
arr[15].into_inner(),
]))
}
}

View File

@ -857,11 +857,7 @@ impl<T: SimdRealField> Rotation3<T> {
where
T: RealField,
{
if let Some(axis) = self.axis() {
Some((axis, self.angle()))
} else {
None
}
self.axis().map(|axis| (axis, self.angle()))
}
/// The rotation angle needed to make `self` and `other` coincide.

View File

@ -178,7 +178,7 @@ where
);
Self::from_parts(
Translation::from(&self.isometry.translation.vector * scaling),
Translation::from(self.isometry.translation.vector * scaling),
self.isometry.rotation.clone(),
self.scaling * scaling,
)

View File

@ -197,7 +197,7 @@ where
{
#[inline]
fn from(arr: [Similarity<T::Element, R::Element, D>; 2]) -> Self {
let iso = Isometry::from([arr[0].isometry.clone(), arr[1].isometry.clone()]);
let iso = Isometry::from([arr[0].isometry, arr[1].isometry]);
let scale = T::from([arr[0].scaling(), arr[1].scaling()]);
Self::from_isometry(iso, scale)
@ -216,10 +216,10 @@ where
#[inline]
fn from(arr: [Similarity<T::Element, R::Element, D>; 4]) -> Self {
let iso = Isometry::from([
arr[0].isometry.clone(),
arr[1].isometry.clone(),
arr[2].isometry.clone(),
arr[3].isometry.clone(),
arr[0].isometry,
arr[1].isometry,
arr[2].isometry,
arr[3].isometry,
]);
let scale = T::from([
arr[0].scaling(),
@ -244,14 +244,14 @@ where
#[inline]
fn from(arr: [Similarity<T::Element, R::Element, D>; 8]) -> Self {
let iso = Isometry::from([
arr[0].isometry.clone(),
arr[1].isometry.clone(),
arr[2].isometry.clone(),
arr[3].isometry.clone(),
arr[4].isometry.clone(),
arr[5].isometry.clone(),
arr[6].isometry.clone(),
arr[7].isometry.clone(),
arr[0].isometry,
arr[1].isometry,
arr[2].isometry,
arr[3].isometry,
arr[4].isometry,
arr[5].isometry,
arr[6].isometry,
arr[7].isometry,
]);
let scale = T::from([
arr[0].scaling(),
@ -280,22 +280,22 @@ where
#[inline]
fn from(arr: [Similarity<T::Element, R::Element, D>; 16]) -> Self {
let iso = Isometry::from([
arr[0].isometry.clone(),
arr[1].isometry.clone(),
arr[2].isometry.clone(),
arr[3].isometry.clone(),
arr[4].isometry.clone(),
arr[5].isometry.clone(),
arr[6].isometry.clone(),
arr[7].isometry.clone(),
arr[8].isometry.clone(),
arr[9].isometry.clone(),
arr[10].isometry.clone(),
arr[11].isometry.clone(),
arr[12].isometry.clone(),
arr[13].isometry.clone(),
arr[14].isometry.clone(),
arr[15].isometry.clone(),
arr[0].isometry,
arr[1].isometry,
arr[2].isometry,
arr[3].isometry,
arr[4].isometry,
arr[5].isometry,
arr[6].isometry,
arr[7].isometry,
arr[8].isometry,
arr[9].isometry,
arr[10].isometry,
arr[11].isometry,
arr[12].isometry,
arr[13].isometry,
arr[14].isometry,
arr[15].isometry,
]);
let scale = T::from([
arr[0].scaling(),

View File

@ -1,3 +1,6 @@
// The macros break if the references are taken out, for some reason.
#![allow(clippy::op_ref)]
use num::{One, Zero};
use std::ops::{Div, DivAssign, Mul, MulAssign};
@ -219,7 +222,7 @@ md_assign_impl_all!(
const D; for; where;
self: Similarity<T, Rotation<T, D>, D>, rhs: Rotation<T, D>;
[val] => self.isometry.rotation *= rhs;
[ref] => self.isometry.rotation *= rhs.clone();
[ref] => self.isometry.rotation *= *rhs;
);
md_assign_impl_all!(

View File

@ -399,11 +399,9 @@ where
#[inline]
#[must_use = "Did you mean to use try_inverse_mut()?"]
pub fn try_inverse(self) -> Option<Transform<T, C, D>> {
if let Some(m) = self.matrix.try_inverse() {
Some(Transform::from_matrix_unchecked(m))
} else {
None
}
self.matrix
.try_inverse()
.map(Transform::from_matrix_unchecked)
}
/// Inverts this transformation. Use `.try_inverse` if this transform has the `TGeneral`

View File

@ -1,3 +1,6 @@
// The macros break if the references are taken out, for some reason.
#![allow(clippy::op_ref)]
use num::{One, Zero};
use std::ops::{Div, DivAssign, Index, IndexMut, Mul, MulAssign};

View File

@ -38,7 +38,7 @@ where
}
}
impl<T: Scalar + Copy, const D: usize> Copy for Translation<T, D> where Owned<T, Const<D>>: Copy {}
impl<T: Scalar + Copy, const D: usize> Copy for Translation<T, D> {}
impl<T: Scalar, const D: usize> Clone for Translation<T, D>
where

View File

@ -77,7 +77,7 @@ where
{
#[inline]
fn to_superset(&self) -> UnitDualQuaternion<T2> {
let dq = UnitDualQuaternion::<T1>::from_parts(self.clone(), UnitQuaternion::identity());
let dq = UnitDualQuaternion::<T1>::from_parts(*self, UnitQuaternion::identity());
dq.to_superset()
}
@ -212,16 +212,14 @@ impl<T: Scalar, const D: usize> From<[T; D]> for Translation<T, D> {
impl<T: Scalar, const D: usize> From<Point<T, D>> for Translation<T, D> {
#[inline]
fn from(pt: Point<T, D>) -> Self {
Translation {
vector: pt.coords.into(),
}
Translation { vector: pt.coords }
}
}
impl<T: Scalar, const D: usize> Into<[T; D]> for Translation<T, D> {
impl<T: Scalar, const D: usize> From<Translation<T, D>> for [T; D] {
#[inline]
fn into(self) -> [T; D] {
self.vector.into()
fn from(t: Translation<T, D>) -> Self {
t.vector.into()
}
}

View File

@ -1,4 +1,3 @@
use std::mem;
use std::ops::{Deref, DerefMut};
use crate::base::coordinates::{X, XY, XYZ, XYZW, XYZWA, XYZWAB};
@ -19,15 +18,14 @@ macro_rules! deref_impl(
#[inline]
fn deref(&self) -> &Self::Target {
unsafe { mem::transmute(self) }
unsafe { &*(self as *const Translation<T, $D> as *const Self::Target) }
}
}
impl<T: Scalar> DerefMut for Translation<T, $D>
{
impl<T: Scalar> DerefMut for Translation<T, $D> {
#[inline]
fn deref_mut(&mut self) -> &mut Self::Target {
unsafe { mem::transmute(self) }
unsafe { &mut *(self as *mut Translation<T, $D> as *mut Self::Target) }
}
}
}

View File

@ -1,3 +1,6 @@
// The macros break if the references are taken out, for some reason.
#![allow(clippy::op_ref)]
use std::ops::{Div, DivAssign, Mul, MulAssign};
use crate::base::storage::Storage;
@ -315,9 +318,9 @@ complex_op_impl_all!(
self: Translation<T, 2>, right: UnitComplex<T>,
Output = Isometry<T, UnitComplex<T>, 2>;
[val val] => Isometry::from_parts(self, right);
[ref val] => Isometry::from_parts(self.clone(), right);
[ref val] => Isometry::from_parts(*self, right);
[val ref] => Isometry::from_parts(self, *right);
[ref ref] => Isometry::from_parts(self.clone(), *right);
[ref ref] => Isometry::from_parts(*self, *right);
);
// UnitComplex ×= UnitComplex
@ -327,7 +330,7 @@ where
{
#[inline]
fn mul_assign(&mut self, rhs: UnitComplex<T>) {
*self = &*self * rhs
*self = *self * rhs
}
}
@ -337,7 +340,7 @@ where
{
#[inline]
fn mul_assign(&mut self, rhs: &'b UnitComplex<T>) {
*self = &*self * rhs
*self = *self * rhs
}
}
@ -348,7 +351,7 @@ where
{
#[inline]
fn div_assign(&mut self, rhs: UnitComplex<T>) {
*self = &*self / rhs
*self = *self / rhs
}
}
@ -358,7 +361,7 @@ where
{
#[inline]
fn div_assign(&mut self, rhs: &'b UnitComplex<T>) {
*self = &*self / rhs
*self = *self / rhs
}
}
@ -369,7 +372,7 @@ where
{
#[inline]
fn mul_assign(&mut self, rhs: Rotation<T, 2>) {
*self = &*self * rhs
*self = *self * rhs
}
}
@ -379,7 +382,7 @@ where
{
#[inline]
fn mul_assign(&mut self, rhs: &'b Rotation<T, 2>) {
*self = &*self * rhs
*self = *self * rhs
}
}
@ -390,7 +393,7 @@ where
{
#[inline]
fn div_assign(&mut self, rhs: Rotation<T, 2>) {
*self = &*self / rhs
*self = *self / rhs
}
}
@ -400,7 +403,7 @@ where
{
#[inline]
fn div_assign(&mut self, rhs: &'b Rotation<T, 2>) {
*self = &*self / rhs
*self = *self / rhs
}
}

View File

@ -1,3 +1,4 @@
#![allow(clippy::type_complexity)]
/*!
# nalgebra
@ -199,19 +200,15 @@ where
while val < min {
val += width
}
val
} else if val > max {
val -= width;
while val > max {
val -= width
}
}
val
} else {
val
}
}
/// Returns a reference to the input value clamped to the interval `[min, max]`.
@ -393,7 +390,7 @@ pub fn center<T: SimdComplexField, const D: usize>(
p1: &Point<T, D>,
p2: &Point<T, D>,
) -> Point<T, D> {
((&p1.coords + &p2.coords) * convert::<_, T>(0.5)).into()
((p1.coords + p2.coords) * convert::<_, T>(0.5)).into()
}
/// The distance between two points.
@ -407,7 +404,7 @@ pub fn distance<T: SimdComplexField, const D: usize>(
p1: &Point<T, D>,
p2: &Point<T, D>,
) -> T::SimdRealField {
(&p2.coords - &p1.coords).norm()
(p2.coords - p1.coords).norm()
}
/// The squared distance between two points.
@ -421,7 +418,7 @@ pub fn distance_squared<T: SimdComplexField, const D: usize>(
p1: &Point<T, D>,
p2: &Point<T, D>,
) -> T::SimdRealField {
(&p2.coords - &p1.coords).norm_squared()
(p2.coords - p1.coords).norm_squared()
}
/*

View File

@ -8,17 +8,17 @@ use crate::base::dimension::Dim;
use crate::base::storage::Storage;
use crate::base::{Const, DefaultAllocator, OMatrix, OVector};
/// Applies in-place a modified Parlett and Reinsch matrix balancing with 2-norm to the matrix `m` and returns
/// Applies in-place a modified Parlett and Reinsch matrix balancing with 2-norm to the matrix and returns
/// the corresponding diagonal transformation.
///
/// See https://arxiv.org/pdf/1401.5766.pdf
pub fn balance_parlett_reinsch<T: RealField, D: Dim>(m: &mut OMatrix<T, D, D>) -> OVector<T, D>
pub fn balance_parlett_reinsch<T: RealField, D: Dim>(matrix: &mut OMatrix<T, D, D>) -> OVector<T, D>
where
DefaultAllocator: Allocator<T, D, D> + Allocator<T, D>,
{
assert!(m.is_square(), "Unable to balance a non-square matrix.");
assert!(matrix.is_square(), "Unable to balance a non-square matrix.");
let dim = m.data.shape().0;
let dim = matrix.data.shape().0;
let radix: T = crate::convert(2.0f64);
let mut d = OVector::from_element_generic(dim, Const::<1>, T::one());
@ -28,36 +28,37 @@ where
converged = true;
for i in 0..dim.value() {
let mut c = m.column(i).norm_squared();
let mut r = m.row(i).norm_squared();
let mut n_col = matrix.column(i).norm_squared();
let mut n_row = matrix.row(i).norm_squared();
let mut f = T::one();
let s = c + r;
c = c.sqrt();
r = r.sqrt();
let s = n_col + n_row;
n_col = n_col.sqrt();
n_row = n_row.sqrt();
if c.is_zero() || r.is_zero() {
if n_col.is_zero() || n_row.is_zero() {
continue;
}
while c < r / radix {
c *= radix;
r /= radix;
while n_col < n_row / radix {
n_col *= radix;
n_row /= radix;
f *= radix;
}
while c >= r * radix {
c /= radix;
r *= radix;
while n_col >= n_row * radix {
n_col /= radix;
n_row *= radix;
f /= radix;
}
let eps: T = crate::convert(0.95);
if c * c + r * r < eps * s {
#[allow(clippy::suspicious_operation_groupings)]
if n_col * n_col + n_row * n_row < eps * s {
converged = false;
d[i] *= f;
m.column_mut(i).mul_assign(f);
m.row_mut(i).div_assign(f);
matrix.column_mut(i).mul_assign(f);
matrix.row_mut(i).div_assign(f);
}
}
}

View File

@ -442,31 +442,31 @@ where
return self.map(|v| v.exp());
}
let mut h = ExpmPadeHelper::new(self.clone(), true);
let mut helper = ExpmPadeHelper::new(self.clone(), true);
let eta_1 = T::RealField::max(h.d4_loose(), h.d6_loose());
if eta_1 < convert(1.495_585_217_958_292e-2) && ell(&h.a, 3) == 0 {
let (u, v) = h.pade3();
let eta_1 = T::RealField::max(helper.d4_loose(), helper.d6_loose());
if eta_1 < convert(1.495_585_217_958_292e-2) && ell(&helper.a, 3) == 0 {
let (u, v) = helper.pade3();
return solve_p_q(u, v);
}
let eta_2 = T::RealField::max(h.d4_tight(), h.d6_loose());
if eta_2 < convert(2.539_398_330_063_230e-1) && ell(&h.a, 5) == 0 {
let (u, v) = h.pade5();
let eta_2 = T::RealField::max(helper.d4_tight(), helper.d6_loose());
if eta_2 < convert(2.539_398_330_063_23e-1) && ell(&helper.a, 5) == 0 {
let (u, v) = helper.pade5();
return solve_p_q(u, v);
}
let eta_3 = T::RealField::max(h.d6_tight(), h.d8_loose());
if eta_3 < convert(9.504_178_996_162_932e-1) && ell(&h.a, 7) == 0 {
let (u, v) = h.pade7();
let eta_3 = T::RealField::max(helper.d6_tight(), helper.d8_loose());
if eta_3 < convert(9.504_178_996_162_932e-1) && ell(&helper.a, 7) == 0 {
let (u, v) = helper.pade7();
return solve_p_q(u, v);
}
if eta_3 < convert(2.097_847_961_257_068e+0) && ell(&h.a, 9) == 0 {
let (u, v) = h.pade9();
if eta_3 < convert(2.097_847_961_257_068e0) && ell(&helper.a, 9) == 0 {
let (u, v) = helper.pade9();
return solve_p_q(u, v);
}
let eta_4 = T::RealField::max(h.d8_loose(), h.d10_loose());
let eta_4 = T::RealField::max(helper.d8_loose(), helper.d10_loose());
let eta_5 = T::RealField::min(eta_3, eta_4);
let theta_13 = convert(4.25);
@ -482,9 +482,12 @@ where
}
};
s += ell(&(&h.a * convert::<f64, T>(2.0_f64.powf(-(s as f64)))), 13);
s += ell(
&(&helper.a * convert::<f64, T>(2.0_f64.powf(-(s as f64)))),
13,
);
let (u, v) = h.pade13_scaled(s);
let (u, v) = helper.pade13_scaled(s);
let mut x = solve_p_q(u, v);
for _ in 0..s {

View File

@ -31,11 +31,9 @@ where
// If e is negative, we compute the inverse matrix, then raise it to the
// power of -e.
if e < zero {
if !self.try_inverse_mut() {
if e < zero && !self.try_inverse_mut() {
return false;
}
}
let one = I::one();
let two = I::from(2u8).unwrap();

View File

@ -1,3 +1,4 @@
#![allow(clippy::suspicious_operation_groupings)]
#[cfg(feature = "serde-serialize-no-std")]
use serde::{Deserialize, Serialize};

View File

@ -121,11 +121,15 @@ where
matrix.unscale_mut(m_amax);
}
let b = Bidiagonal::new(matrix);
let mut u = if compute_u { Some(b.u()) } else { None };
let mut v_t = if compute_v { Some(b.v_t()) } else { None };
let mut diagonal = b.diagonal();
let mut off_diagonal = b.off_diagonal();
let bi_matrix = Bidiagonal::new(matrix);
let mut u = if compute_u { Some(bi_matrix.u()) } else { None };
let mut v_t = if compute_v {
Some(bi_matrix.v_t())
} else {
None
};
let mut diagonal = bi_matrix.diagonal();
let mut off_diagonal = bi_matrix.off_diagonal();
let mut niter = 0;
let (mut start, mut end) = Self::delimit_subproblem(
@ -133,7 +137,7 @@ where
&mut off_diagonal,
&mut u,
&mut v_t,
b.is_upper_diagonal(),
bi_matrix.is_upper_diagonal(),
dim - 1,
eps,
);
@ -142,6 +146,7 @@ where
let subdim = end - start + 1;
// Solve the subproblem.
#[allow(clippy::comparison_chain)]
if subdim > 2 {
let m = end - 1;
let n = end;
@ -201,7 +206,7 @@ where
subm[(0, 0)] = norm2;
if let Some(ref mut v_t) = v_t {
if b.is_upper_diagonal() {
if bi_matrix.is_upper_diagonal() {
rot1.rotate(&mut v_t.fixed_rows_mut::<2>(k));
} else {
rot2.rotate(&mut v_t.fixed_rows_mut::<2>(k));
@ -209,7 +214,7 @@ where
}
if let Some(ref mut u) = u {
if b.is_upper_diagonal() {
if bi_matrix.is_upper_diagonal() {
rot2.inverse().rotate_rows(&mut u.fixed_columns_mut::<2>(k));
} else {
rot1.inverse().rotate_rows(&mut u.fixed_columns_mut::<2>(k));
@ -236,8 +241,10 @@ where
diagonal[start],
off_diagonal[start],
diagonal[start + 1],
compute_u && b.is_upper_diagonal() || compute_v && !b.is_upper_diagonal(),
compute_v && b.is_upper_diagonal() || compute_u && !b.is_upper_diagonal(),
compute_u && bi_matrix.is_upper_diagonal()
|| compute_v && !bi_matrix.is_upper_diagonal(),
compute_v && bi_matrix.is_upper_diagonal()
|| compute_u && !bi_matrix.is_upper_diagonal(),
);
let u2 = u2.map(|u2| GivensRotation::new_unchecked(u2.c(), T::from_real(u2.s())));
let v2 = v2.map(|v2| GivensRotation::new_unchecked(v2.c(), T::from_real(v2.s())));
@ -247,7 +254,7 @@ where
off_diagonal[start] = T::RealField::zero();
if let Some(ref mut u) = u {
let rot = if b.is_upper_diagonal() {
let rot = if bi_matrix.is_upper_diagonal() {
u2.unwrap()
} else {
v2.unwrap()
@ -256,7 +263,7 @@ where
}
if let Some(ref mut v_t) = v_t {
let rot = if b.is_upper_diagonal() {
let rot = if bi_matrix.is_upper_diagonal() {
v2.unwrap()
} else {
u2.unwrap()
@ -273,7 +280,7 @@ where
&mut off_diagonal,
&mut u,
&mut v_t,
b.is_upper_diagonal(),
bi_matrix.is_upper_diagonal(),
end,
eps,
);

View File

@ -87,7 +87,7 @@ where
}
fn do_decompose(
mut m: OMatrix<T, D, D>,
mut matrix: OMatrix<T, D, D>,
eigenvectors: bool,
eps: T::RealField,
max_niter: usize,
@ -97,33 +97,33 @@ where
DefaultAllocator: Allocator<T, DimDiff<D, U1>> + Allocator<T::RealField, DimDiff<D, U1>>,
{
assert!(
m.is_square(),
matrix.is_square(),
"Unable to compute the eigendecomposition of a non-square matrix."
);
let dim = m.nrows();
let m_amax = m.camax();
let dim = matrix.nrows();
let m_amax = matrix.camax();
if !m_amax.is_zero() {
m.unscale_mut(m_amax);
matrix.unscale_mut(m_amax);
}
let (mut q, mut diag, mut off_diag);
let (mut q_mat, mut diag, mut off_diag);
if eigenvectors {
let res = SymmetricTridiagonal::new(m).unpack();
q = Some(res.0);
let res = SymmetricTridiagonal::new(matrix).unpack();
q_mat = Some(res.0);
diag = res.1;
off_diag = res.2;
} else {
let res = SymmetricTridiagonal::new(m).unpack_tridiagonal();
q = None;
let res = SymmetricTridiagonal::new(matrix).unpack_tridiagonal();
q_mat = None;
diag = res.0;
off_diag = res.1;
}
if dim == 1 {
diag.scale_mut(m_amax);
return Some((diag, q));
return Some((diag, q_mat));
}
let mut niter = 0;
@ -132,11 +132,12 @@ where
while end != start {
let subdim = end - start + 1;
#[allow(clippy::comparison_chain)]
if subdim > 2 {
let m = end - 1;
let n = end;
let mut v = Vector2::new(
let mut vec = Vector2::new(
diag[start] - wilkinson_shift(diag[m], diag[n], off_diag[m]),
off_diag[start],
);
@ -144,7 +145,7 @@ where
for i in start..n {
let j = i + 1;
if let Some((rot, norm)) = GivensRotation::cancel_y(&v) {
if let Some((rot, norm)) = GivensRotation::cancel_y(&vec) {
if i > start {
// Not the first iteration.
off_diag[i - 1] = norm;
@ -165,12 +166,12 @@ where
off_diag[i] = cs * (mii - mjj) + mij * (cc - ss);
if i != n - 1 {
v.x = off_diag[i];
v.y = -rot.s() * off_diag[i + 1];
vec.x = off_diag[i];
vec.y = -rot.s() * off_diag[i + 1];
off_diag[i + 1] *= rot.c();
}
if let Some(ref mut q) = q {
if let Some(ref mut q) = q_mat {
let rot = GivensRotation::new_unchecked(rot.c(), T::from_real(rot.s()));
rot.inverse().rotate_rows(&mut q.fixed_columns_mut::<2>(i));
}
@ -195,7 +196,7 @@ where
diag[start] = eigvals[0];
diag[start + 1] = eigvals[1];
if let Some(ref mut q) = q {
if let Some(ref mut q) = q_mat {
if let Some((rot, _)) = GivensRotation::try_new(basis.x, basis.y, eps) {
let rot = GivensRotation::new_unchecked(rot.c(), T::from_real(rot.s()));
rot.rotate_rows(&mut q.fixed_columns_mut::<2>(start));
@ -219,7 +220,7 @@ where
diag.scale_mut(m_amax);
Some((diag, q))
Some((diag, q_mat))
}
fn delimit_subproblem(

View File

@ -26,18 +26,20 @@ fn convolve_same_check() {
// Panic Tests
// These really only apply to dynamic sized vectors
assert!(panic::catch_unwind(|| {
DVector::from_vec(vec![1.0, 2.0])
let _ = DVector::from_vec(vec![1.0, 2.0])
.convolve_same(DVector::from_vec(vec![1.0, 2.0, 3.0, 4.0]));
})
.is_err());
assert!(panic::catch_unwind(|| {
DVector::<f32>::from_vec(vec![]).convolve_same(DVector::from_vec(vec![1.0, 2.0, 3.0, 4.0]));
let _ = DVector::<f32>::from_vec(vec![])
.convolve_same(DVector::from_vec(vec![1.0, 2.0, 3.0, 4.0]));
})
.is_err());
assert!(panic::catch_unwind(|| {
DVector::from_vec(vec![1.0, 2.0, 3.0, 4.0]).convolve_same(DVector::<f32>::from_vec(vec![]));
let _ = DVector::from_vec(vec![1.0, 2.0, 3.0, 4.0])
.convolve_same(DVector::<f32>::from_vec(vec![]));
})
.is_err());
}