From dd6c40016ee4f75b66190071b9cbb4f9254320a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Crozet?= Date: Wed, 4 Aug 2021 17:34:25 +0200 Subject: [PATCH] Remove the Copy requirement from SimdRealField. --- nalgebra-glm/src/gtc/type_ptr.rs | 54 ++-- nalgebra-sparse/src/convert/serial.rs | 16 +- nalgebra-sparse/src/cs.rs | 2 +- nalgebra-sparse/src/factorization/cholesky.rs | 2 +- nalgebra-sparse/src/ops/impl_std_ops.rs | 20 +- nalgebra-sparse/src/ops/serial/cs.rs | 27 +- nalgebra-sparse/src/ops/serial/csc.rs | 2 +- src/base/blas.rs | 121 +++++---- src/base/blas_uninit.rs | 24 +- src/base/cg.rs | 54 ++-- src/base/componentwise.rs | 12 +- src/base/construction.rs | 13 +- src/base/conversion.rs | 62 +++-- src/base/edition.rs | 36 +-- src/base/interpolation.rs | 8 +- src/base/matrix.rs | 140 +++++------ src/base/min_max.rs | 28 +-- src/base/norm.rs | 25 +- src/base/ops.rs | 22 +- src/base/properties.rs | 14 +- src/base/scalar.rs | 16 +- src/base/statistics.rs | 13 +- src/base/swizzle.rs | 2 +- src/base/unit.rs | 8 +- src/geometry/dual_quaternion.rs | 75 +++--- src/geometry/dual_quaternion_construction.rs | 4 +- src/geometry/dual_quaternion_conversion.rs | 4 +- src/geometry/dual_quaternion_ops.rs | 44 ++-- src/geometry/isometry.rs | 17 +- src/geometry/isometry_interpolation.rs | 30 ++- src/geometry/isometry_ops.rs | 62 ++--- src/geometry/orthographic.rs | 80 +++--- src/geometry/perspective.rs | 82 +++--- src/geometry/point.rs | 6 +- src/geometry/point_construction.rs | 3 +- src/geometry/point_conversion.rs | 2 +- src/geometry/quaternion.rs | 118 ++++----- src/geometry/quaternion_construction.rs | 97 ++++--- src/geometry/quaternion_conversion.rs | 4 +- src/geometry/quaternion_ops.rs | 8 +- src/geometry/reflection.rs | 16 +- src/geometry/rotation.rs | 6 +- src/geometry/rotation_interpolation.rs | 12 +- src/geometry/rotation_specialization.rs | 116 +++++---- src/geometry/similarity.rs | 29 +-- src/geometry/similarity_ops.rs | 6 +- src/geometry/swizzle.rs | 2 +- src/geometry/transform.rs | 16 +- src/geometry/transform_ops.rs | 22 +- src/geometry/translation.rs | 6 +- src/geometry/translation_conversion.rs | 2 +- src/geometry/unit_complex.rs | 34 +-- src/geometry/unit_complex_construction.rs | 10 +- src/geometry/unit_complex_conversion.rs | 4 +- src/geometry/unit_complex_ops.rs | 36 +-- src/lib.rs | 6 +- src/linalg/balancing.rs | 32 +-- src/linalg/bidiagonal.rs | 20 +- src/linalg/cholesky.rs | 38 +-- src/linalg/col_piv_qr.rs | 16 +- src/linalg/convolution.rs | 10 +- src/linalg/determinant.rs | 32 +-- src/linalg/exp.rs | 101 ++++---- src/linalg/full_piv_lu.rs | 6 +- src/linalg/givens.rs | 55 ++-- src/linalg/hessenberg.rs | 12 +- src/linalg/householder.rs | 16 +- src/linalg/inverse.rs | 237 +++++++++++------- src/linalg/lu.rs | 10 +- src/linalg/qr.rs | 14 +- src/linalg/schur.rs | 101 ++++---- src/linalg/solve.rs | 46 ++-- src/linalg/svd.rs | 115 +++++---- src/linalg/symmetric_eigen.rs | 74 +++--- src/linalg/symmetric_tridiagonal.rs | 4 +- src/linalg/udu.rs | 16 +- src/sparse/cs_matrix.rs | 6 +- src/sparse/cs_matrix_cholesky.rs | 30 +-- src/sparse/cs_matrix_conversion.rs | 2 +- src/sparse/cs_matrix_ops.rs | 18 +- src/sparse/cs_matrix_solve.rs | 8 +- src/third_party/mint/mint_quaternion.rs | 16 +- 82 files changed, 1420 insertions(+), 1295 deletions(-) diff --git a/nalgebra-glm/src/gtc/type_ptr.rs b/nalgebra-glm/src/gtc/type_ptr.rs index bdd72585..3a0a8f43 100644 --- a/nalgebra-glm/src/gtc/type_ptr.rs +++ b/nalgebra-glm/src/gtc/type_ptr.rs @@ -76,12 +76,7 @@ pub fn mat2_to_mat3(m: &TMat2) -> TMat3 { /// Converts a 3x3 matrix to a 2x2 matrix. pub fn mat3_to_mat2(m: &TMat3) -> TMat2 { - TMat2::new( - m.m11.inlined_clone(), - m.m12.inlined_clone(), - m.m21.inlined_clone(), - m.m22.inlined_clone(), - ) + TMat2::new(m.m11.clone(), m.m12.clone(), m.m21.clone(), m.m22.clone()) } /// Converts a 3x3 matrix to a 4x4 matrix. @@ -97,15 +92,15 @@ pub fn mat3_to_mat4(m: &TMat3) -> TMat4 { /// Converts a 4x4 matrix to a 3x3 matrix. pub fn mat4_to_mat3(m: &TMat4) -> TMat3 { TMat3::new( - m.m11.inlined_clone(), - m.m12.inlined_clone(), - m.m13.inlined_clone(), - m.m21.inlined_clone(), - m.m22.inlined_clone(), - m.m23.inlined_clone(), - m.m31.inlined_clone(), - m.m32.inlined_clone(), - m.m33.inlined_clone(), + m.m11.clone(), + m.m12.clone(), + m.m13.clone(), + m.m21.clone(), + m.m22.clone(), + m.m23.clone(), + m.m31.clone(), + m.m32.clone(), + m.m33.clone(), ) } @@ -121,12 +116,7 @@ pub fn mat2_to_mat4(m: &TMat2) -> TMat4 { /// Converts a 4x4 matrix to a 2x2 matrix. pub fn mat4_to_mat2(m: &TMat4) -> TMat2 { - TMat2::new( - m.m11.inlined_clone(), - m.m12.inlined_clone(), - m.m21.inlined_clone(), - m.m22.inlined_clone(), - ) + TMat2::new(m.m11.clone(), m.m12.clone(), m.m21.clone(), m.m22.clone()) } /// Creates a quaternion from a slice arranged as `[x, y, z, w]`. @@ -156,7 +146,7 @@ pub fn make_vec1(v: &TVec1) -> TVec1 { /// * [`vec1_to_vec3`](fn.vec1_to_vec3.html) /// * [`vec1_to_vec4`](fn.vec1_to_vec4.html) pub fn vec2_to_vec1(v: &TVec2) -> TVec1 { - TVec1::new(v.x.inlined_clone()) + TVec1::new(v.x.clone()) } /// Creates a 1D vector from another vector. @@ -170,7 +160,7 @@ pub fn vec2_to_vec1(v: &TVec2) -> TVec1 { /// * [`vec1_to_vec3`](fn.vec1_to_vec3.html) /// * [`vec1_to_vec4`](fn.vec1_to_vec4.html) pub fn vec3_to_vec1(v: &TVec3) -> TVec1 { - TVec1::new(v.x.inlined_clone()) + TVec1::new(v.x.clone()) } /// Creates a 1D vector from another vector. @@ -184,7 +174,7 @@ pub fn vec3_to_vec1(v: &TVec3) -> TVec1 { /// * [`vec1_to_vec3`](fn.vec1_to_vec3.html) /// * [`vec1_to_vec4`](fn.vec1_to_vec4.html) pub fn vec4_to_vec1(v: &TVec4) -> TVec1 { - TVec1::new(v.x.inlined_clone()) + TVec1::new(v.x.clone()) } /// Creates a 2D vector from another vector. @@ -200,7 +190,7 @@ pub fn vec4_to_vec1(v: &TVec4) -> TVec1 { /// * [`vec2_to_vec3`](fn.vec2_to_vec3.html) /// * [`vec2_to_vec4`](fn.vec2_to_vec4.html) pub fn vec1_to_vec2(v: &TVec1) -> TVec2 { - TVec2::new(v.x.inlined_clone(), T::zero()) + TVec2::new(v.x.clone(), T::zero()) } /// Creates a 2D vector from another vector. @@ -229,7 +219,7 @@ pub fn vec2_to_vec2(v: &TVec2) -> TVec2 { /// * [`vec2_to_vec3`](fn.vec2_to_vec3.html) /// * [`vec2_to_vec4`](fn.vec2_to_vec4.html) pub fn vec3_to_vec2(v: &TVec3) -> TVec2 { - TVec2::new(v.x.inlined_clone(), v.y.inlined_clone()) + TVec2::new(v.x.clone(), v.y.clone()) } /// Creates a 2D vector from another vector. @@ -243,7 +233,7 @@ pub fn vec3_to_vec2(v: &TVec3) -> TVec2 { /// * [`vec2_to_vec3`](fn.vec2_to_vec3.html) /// * [`vec2_to_vec4`](fn.vec2_to_vec4.html) pub fn vec4_to_vec2(v: &TVec4) -> TVec2 { - TVec2::new(v.x.inlined_clone(), v.y.inlined_clone()) + TVec2::new(v.x.clone(), v.y.clone()) } /// Creates a 2D vector from a slice. @@ -269,7 +259,7 @@ pub fn make_vec2(ptr: &[T]) -> TVec2 { /// * [`vec1_to_vec2`](fn.vec1_to_vec2.html) /// * [`vec1_to_vec4`](fn.vec1_to_vec4.html) pub fn vec1_to_vec3(v: &TVec1) -> TVec3 { - TVec3::new(v.x.inlined_clone(), T::zero(), T::zero()) + TVec3::new(v.x.clone(), T::zero(), T::zero()) } /// Creates a 3D vector from another vector. @@ -285,7 +275,7 @@ pub fn vec1_to_vec3(v: &TVec1) -> TVec3 { /// * [`vec3_to_vec2`](fn.vec3_to_vec2.html) /// * [`vec3_to_vec4`](fn.vec3_to_vec4.html) pub fn vec2_to_vec3(v: &TVec2) -> TVec3 { - TVec3::new(v.x.inlined_clone(), v.y.inlined_clone(), T::zero()) + TVec3::new(v.x.clone(), v.y.clone(), T::zero()) } /// Creates a 3D vector from another vector. @@ -313,11 +303,7 @@ pub fn vec3_to_vec3(v: &TVec3) -> TVec3 { /// * [`vec3_to_vec2`](fn.vec3_to_vec2.html) /// * [`vec3_to_vec4`](fn.vec3_to_vec4.html) pub fn vec4_to_vec3(v: &TVec4) -> TVec3 { - TVec3::new( - v.x.inlined_clone(), - v.y.inlined_clone(), - v.z.inlined_clone(), - ) + TVec3::new(v.x.clone(), v.y.clone(), v.z.clone()) } /// Creates a 3D vector from another vector. diff --git a/nalgebra-sparse/src/convert/serial.rs b/nalgebra-sparse/src/convert/serial.rs index f84a6583..ecbe1dab 100644 --- a/nalgebra-sparse/src/convert/serial.rs +++ b/nalgebra-sparse/src/convert/serial.rs @@ -30,7 +30,7 @@ where // We use the fact that matrix iteration is guaranteed to be column-major let i = index % dense.nrows(); let j = index / dense.nrows(); - coo.push(i, j, v.inlined_clone()); + coo.push(i, j, v.clone()); } } @@ -44,7 +44,7 @@ where { let mut output = DMatrix::repeat(coo.nrows(), coo.ncols(), T::zero()); for (i, j, v) in coo.triplet_iter() { - output[(i, j)] += v.inlined_clone(); + output[(i, j)] += v.clone(); } output } @@ -71,7 +71,7 @@ where pub fn convert_csr_coo(csr: &CsrMatrix) -> CooMatrix { let mut result = CooMatrix::new(csr.nrows(), csr.ncols()); for (i, j, v) in csr.triplet_iter() { - result.push(i, j, v.inlined_clone()); + result.push(i, j, v.clone()); } result } @@ -84,7 +84,7 @@ where let mut output = DMatrix::zeros(csr.nrows(), csr.ncols()); for (i, j, v) in csr.triplet_iter() { - output[(i, j)] += v.inlined_clone(); + output[(i, j)] += v.clone(); } output @@ -111,7 +111,7 @@ where let v = dense.index((i, j)); if v != &T::zero() { col_idx.push(j); - values.push(v.inlined_clone()); + values.push(v.clone()); } } row_offsets.push(col_idx.len()); @@ -148,7 +148,7 @@ where { let mut coo = CooMatrix::new(csc.nrows(), csc.ncols()); for (i, j, v) in csc.triplet_iter() { - coo.push(i, j, v.inlined_clone()); + coo.push(i, j, v.clone()); } coo } @@ -161,7 +161,7 @@ where let mut output = DMatrix::zeros(csc.nrows(), csc.ncols()); for (i, j, v) in csc.triplet_iter() { - output[(i, j)] += v.inlined_clone(); + output[(i, j)] += v.clone(); } output @@ -185,7 +185,7 @@ where let v = dense.index((i, j)); if v != &T::zero() { row_idx.push(i); - values.push(v.inlined_clone()); + values.push(v.clone()); } } col_offsets.push(row_idx.len()); diff --git a/nalgebra-sparse/src/cs.rs b/nalgebra-sparse/src/cs.rs index e0775b26..cffdd6c7 100644 --- a/nalgebra-sparse/src/cs.rs +++ b/nalgebra-sparse/src/cs.rs @@ -522,7 +522,7 @@ where let entry_offset = target_offsets[source_minor_idx] + *target_lane_count; target_indices[entry_offset] = source_major_idx; unsafe { - target_values.set(entry_offset, val.inlined_clone()); + target_values.set(entry_offset, val.clone()); } *target_lane_count += 1; } diff --git a/nalgebra-sparse/src/factorization/cholesky.rs b/nalgebra-sparse/src/factorization/cholesky.rs index f2e2065b..86a95767 100644 --- a/nalgebra-sparse/src/factorization/cholesky.rs +++ b/nalgebra-sparse/src/factorization/cholesky.rs @@ -225,7 +225,7 @@ impl CscCholesky { let col_j_entries = col_j.row_indices().iter().zip(col_j.values()); for (&z, val) in col_j_entries { if z >= k { - *self.work_x.get_unchecked_mut(z) += val.inlined_clone() * factor; + *self.work_x.get_unchecked_mut(z) += val.clone() * factor; } } } diff --git a/nalgebra-sparse/src/ops/impl_std_ops.rs b/nalgebra-sparse/src/ops/impl_std_ops.rs index 721023a5..107c38ba 100644 --- a/nalgebra-sparse/src/ops/impl_std_ops.rs +++ b/nalgebra-sparse/src/ops/impl_std_ops.rs @@ -141,7 +141,7 @@ macro_rules! impl_scalar_mul { impl_mul!(<'a, T>(a: &'a $matrix_type, b: &'a T) -> $matrix_type { let values: Vec<_> = a.values() .iter() - .map(|v_i| v_i.inlined_clone() * b.inlined_clone()) + .map(|v_i| v_i.clone() * b.clone()) .collect(); $matrix_type::try_from_pattern_and_values(a.pattern().clone(), values).unwrap() }); @@ -151,7 +151,7 @@ macro_rules! impl_scalar_mul { impl_mul!(<'a, T>(a: $matrix_type, b: &'a T) -> $matrix_type { let mut a = a; for value in a.values_mut() { - *value = b.inlined_clone() * value.inlined_clone(); + *value = b.clone() * value.clone(); } a }); @@ -168,7 +168,7 @@ macro_rules! impl_scalar_mul { { fn mul_assign(&mut self, scalar: T) { for val in self.values_mut() { - *val *= scalar.inlined_clone(); + *val *= scalar.clone(); } } } @@ -179,7 +179,7 @@ macro_rules! impl_scalar_mul { { fn mul_assign(&mut self, scalar: &'a T) { for val in self.values_mut() { - *val *= scalar.inlined_clone(); + *val *= scalar.clone(); } } } @@ -199,7 +199,7 @@ macro_rules! impl_neg { fn neg(mut self) -> Self::Output { for v_i in self.values_mut() { - *v_i = -v_i.inlined_clone(); + *v_i = -v_i.clone(); } self } @@ -233,25 +233,25 @@ macro_rules! impl_div { matrix }); impl_bin_op!(Div, div, <'a, T: ClosedDiv>(matrix: $matrix_type, scalar: &T) -> $matrix_type { - matrix / scalar.inlined_clone() + matrix / scalar.clone() }); impl_bin_op!(Div, div, <'a, T: ClosedDiv>(matrix: &'a $matrix_type, scalar: T) -> $matrix_type { let new_values = matrix.values() .iter() - .map(|v_i| v_i.inlined_clone() / scalar.inlined_clone()) + .map(|v_i| v_i.clone() / scalar.clone()) .collect(); $matrix_type::try_from_pattern_and_values(matrix.pattern().clone(), new_values) .unwrap() }); impl_bin_op!(Div, div, <'a, T: ClosedDiv>(matrix: &'a $matrix_type, scalar: &'a T) -> $matrix_type { - matrix / scalar.inlined_clone() + matrix / scalar.clone() }); impl DivAssign for $matrix_type where T : Scalar + ClosedAdd + ClosedMul + ClosedDiv + Zero + One { fn div_assign(&mut self, scalar: T) { - self.values_mut().iter_mut().for_each(|v_i| *v_i /= scalar.inlined_clone()); + self.values_mut().iter_mut().for_each(|v_i| *v_i /= scalar.clone()); } } @@ -259,7 +259,7 @@ macro_rules! impl_div { where T : Scalar + ClosedAdd + ClosedMul + ClosedDiv + Zero + One { fn div_assign(&mut self, scalar: &'a T) { - *self /= scalar.inlined_clone(); + *self /= scalar.clone(); } } } diff --git a/nalgebra-sparse/src/ops/serial/cs.rs b/nalgebra-sparse/src/ops/serial/cs.rs index db057705..86484053 100644 --- a/nalgebra-sparse/src/ops/serial/cs.rs +++ b/nalgebra-sparse/src/ops/serial/cs.rs @@ -34,13 +34,13 @@ where let a_lane_i = a.get_lane(i).unwrap(); let mut c_lane_i = c.get_lane_mut(i).unwrap(); for c_ij in c_lane_i.values_mut() { - *c_ij = beta.inlined_clone() * c_ij.inlined_clone(); + *c_ij = beta.clone() * c_ij.clone(); } for (&k, a_ik) in a_lane_i.minor_indices().iter().zip(a_lane_i.values()) { let b_lane_k = b.get_lane(k).unwrap(); let (mut c_lane_i_cols, mut c_lane_i_values) = c_lane_i.indices_and_values_mut(); - let alpha_aik = alpha.inlined_clone() * a_ik.inlined_clone(); + let alpha_aik = alpha.clone() * a_ik.clone(); for (j, b_kj) in b_lane_k.minor_indices().iter().zip(b_lane_k.values()) { // Determine the location in C to append the value let (c_local_idx, _) = c_lane_i_cols @@ -49,7 +49,7 @@ where .find(|(_, c_col)| *c_col == j) .ok_or_else(spmm_cs_unexpected_entry)?; - c_lane_i_values[c_local_idx] += alpha_aik.inlined_clone() * b_kj.inlined_clone(); + c_lane_i_values[c_local_idx] += alpha_aik.clone() * b_kj.clone(); c_lane_i_cols = &c_lane_i_cols[c_local_idx..]; c_lane_i_values = &mut c_lane_i_values[c_local_idx..]; } @@ -81,7 +81,7 @@ where for (mut c_lane_i, a_lane_i) in c.lane_iter_mut().zip(a.lane_iter()) { if beta != T::one() { for c_ij in c_lane_i.values_mut() { - *c_ij *= beta.inlined_clone(); + *c_ij *= beta.clone(); } } @@ -97,7 +97,7 @@ where .enumerate() .find(|(_, c_col)| *c_col == a_col) .ok_or_else(spadd_cs_unexpected_entry)?; - c_vals[c_idx] += alpha.inlined_clone() * a_val.inlined_clone(); + c_vals[c_idx] += alpha.clone() * a_val.clone(); c_minors = &c_minors[c_idx..]; c_vals = &mut c_vals[c_idx..]; } @@ -106,14 +106,14 @@ where Op::Transpose(a) => { if beta != T::one() { for c_ij in c.values_mut() { - *c_ij *= beta.inlined_clone(); + *c_ij *= beta.clone(); } } for (i, a_lane_i) in a.lane_iter().enumerate() { for (&j, a_val) in a_lane_i.minor_indices().iter().zip(a_lane_i.values()) { - let a_val = a_val.inlined_clone(); - let alpha = alpha.inlined_clone(); + let a_val = a_val.clone(); + let alpha = alpha.clone(); match c.get_entry_mut(j, i).unwrap() { SparseEntryMut::NonZero(c_ji) => *c_ji += alpha * a_val, SparseEntryMut::Zero => return Err(spadd_cs_unexpected_entry()), @@ -149,10 +149,9 @@ pub fn spmm_cs_dense( Op::NoOp(ref b) => b.index((k, j)), Op::Transpose(ref b) => b.index((j, k)), }; - dot_ij += a_ik.inlined_clone() * b_contrib.inlined_clone(); + dot_ij += a_ik.clone() * b_contrib.clone(); } - *c_ij = beta.inlined_clone() * c_ij.inlined_clone() - + alpha.inlined_clone() * dot_ij; + *c_ij = beta.clone() * c_ij.clone() + alpha.clone() * dot_ij; } } } @@ -163,19 +162,19 @@ pub fn spmm_cs_dense( for k in 0..a.pattern().major_dim() { let a_row_k = a.get_lane(k).unwrap(); for (&i, a_ki) in a_row_k.minor_indices().iter().zip(a_row_k.values()) { - let gamma_ki = alpha.inlined_clone() * a_ki.inlined_clone(); + let gamma_ki = alpha.clone() * a_ki.clone(); let mut c_row_i = c.row_mut(i); match b { Op::NoOp(ref b) => { let b_row_k = b.row(k); for (c_ij, b_kj) in c_row_i.iter_mut().zip(b_row_k.iter()) { - *c_ij += gamma_ki.inlined_clone() * b_kj.inlined_clone(); + *c_ij += gamma_ki.clone() * b_kj.clone(); } } Op::Transpose(ref b) => { let b_col_k = b.column(k); for (c_ij, b_jk) in c_row_i.iter_mut().zip(b_col_k.iter()) { - *c_ij += gamma_ki.inlined_clone() * b_jk.inlined_clone(); + *c_ij += gamma_ki.clone() * b_jk.clone(); } } } diff --git a/nalgebra-sparse/src/ops/serial/csc.rs b/nalgebra-sparse/src/ops/serial/csc.rs index 25e59f26..70e61523 100644 --- a/nalgebra-sparse/src/ops/serial/csc.rs +++ b/nalgebra-sparse/src/ops/serial/csc.rs @@ -179,7 +179,7 @@ fn spsolve_csc_lower_triangular_no_transpose( // Note: The remaining entries are below the diagonal for (&i, l_ik) in row_indices.iter().zip(l_values) { let x_ij = &mut x_col_j[i]; - *x_ij -= l_ik.inlined_clone() * x_kj; + *x_ij -= l_ik.clone() * x_kj; } x_col_j[k] = x_kj; diff --git a/src/base/blas.rs b/src/base/blas.rs index 4d5a5b5d..4f56a70e 100644 --- a/src/base/blas.rs +++ b/src/base/blas.rs @@ -47,36 +47,36 @@ where // because the `for` loop below won't be very efficient on those. if (R::is::() || R2::is::()) && (C::is::() || C2::is::()) { unsafe { - let a = conjugate(self.get_unchecked((0, 0)).inlined_clone()) - * rhs.get_unchecked((0, 0)).inlined_clone(); - let b = conjugate(self.get_unchecked((1, 0)).inlined_clone()) - * rhs.get_unchecked((1, 0)).inlined_clone(); + let a = conjugate(self.get_unchecked((0, 0)).clone()) + * rhs.get_unchecked((0, 0)).clone(); + let b = conjugate(self.get_unchecked((1, 0)).clone()) + * rhs.get_unchecked((1, 0)).clone(); return a + b; } } if (R::is::() || R2::is::()) && (C::is::() || C2::is::()) { unsafe { - let a = conjugate(self.get_unchecked((0, 0)).inlined_clone()) - * rhs.get_unchecked((0, 0)).inlined_clone(); - let b = conjugate(self.get_unchecked((1, 0)).inlined_clone()) - * rhs.get_unchecked((1, 0)).inlined_clone(); - let c = conjugate(self.get_unchecked((2, 0)).inlined_clone()) - * rhs.get_unchecked((2, 0)).inlined_clone(); + let a = conjugate(self.get_unchecked((0, 0)).clone()) + * rhs.get_unchecked((0, 0)).clone(); + let b = conjugate(self.get_unchecked((1, 0)).clone()) + * rhs.get_unchecked((1, 0)).clone(); + let c = conjugate(self.get_unchecked((2, 0)).clone()) + * rhs.get_unchecked((2, 0)).clone(); return a + b + c; } } if (R::is::() || R2::is::()) && (C::is::() || C2::is::()) { unsafe { - let mut a = conjugate(self.get_unchecked((0, 0)).inlined_clone()) - * rhs.get_unchecked((0, 0)).inlined_clone(); - let mut b = conjugate(self.get_unchecked((1, 0)).inlined_clone()) - * rhs.get_unchecked((1, 0)).inlined_clone(); - let c = conjugate(self.get_unchecked((2, 0)).inlined_clone()) - * rhs.get_unchecked((2, 0)).inlined_clone(); - let d = conjugate(self.get_unchecked((3, 0)).inlined_clone()) - * rhs.get_unchecked((3, 0)).inlined_clone(); + let mut a = conjugate(self.get_unchecked((0, 0)).clone()) + * rhs.get_unchecked((0, 0)).clone(); + let mut b = conjugate(self.get_unchecked((1, 0)).clone()) + * rhs.get_unchecked((1, 0)).clone(); + let c = conjugate(self.get_unchecked((2, 0)).clone()) + * rhs.get_unchecked((2, 0)).clone(); + let d = conjugate(self.get_unchecked((3, 0)).clone()) + * rhs.get_unchecked((3, 0)).clone(); a += c; b += d; @@ -117,36 +117,36 @@ where while self.nrows() - i >= 8 { acc0 += unsafe { - conjugate(self.get_unchecked((i, j)).inlined_clone()) - * rhs.get_unchecked((i, j)).inlined_clone() + conjugate(self.get_unchecked((i, j)).clone()) + * rhs.get_unchecked((i, j)).clone() }; acc1 += unsafe { - conjugate(self.get_unchecked((i + 1, j)).inlined_clone()) - * rhs.get_unchecked((i + 1, j)).inlined_clone() + conjugate(self.get_unchecked((i + 1, j)).clone()) + * rhs.get_unchecked((i + 1, j)).clone() }; acc2 += unsafe { - conjugate(self.get_unchecked((i + 2, j)).inlined_clone()) - * rhs.get_unchecked((i + 2, j)).inlined_clone() + conjugate(self.get_unchecked((i + 2, j)).clone()) + * rhs.get_unchecked((i + 2, j)).clone() }; acc3 += unsafe { - conjugate(self.get_unchecked((i + 3, j)).inlined_clone()) - * rhs.get_unchecked((i + 3, j)).inlined_clone() + conjugate(self.get_unchecked((i + 3, j)).clone()) + * rhs.get_unchecked((i + 3, j)).clone() }; acc4 += unsafe { - conjugate(self.get_unchecked((i + 4, j)).inlined_clone()) - * rhs.get_unchecked((i + 4, j)).inlined_clone() + conjugate(self.get_unchecked((i + 4, j)).clone()) + * rhs.get_unchecked((i + 4, j)).clone() }; acc5 += unsafe { - conjugate(self.get_unchecked((i + 5, j)).inlined_clone()) - * rhs.get_unchecked((i + 5, j)).inlined_clone() + conjugate(self.get_unchecked((i + 5, j)).clone()) + * rhs.get_unchecked((i + 5, j)).clone() }; acc6 += unsafe { - conjugate(self.get_unchecked((i + 6, j)).inlined_clone()) - * rhs.get_unchecked((i + 6, j)).inlined_clone() + conjugate(self.get_unchecked((i + 6, j)).clone()) + * rhs.get_unchecked((i + 6, j)).clone() }; acc7 += unsafe { - conjugate(self.get_unchecked((i + 7, j)).inlined_clone()) - * rhs.get_unchecked((i + 7, j)).inlined_clone() + conjugate(self.get_unchecked((i + 7, j)).clone()) + * rhs.get_unchecked((i + 7, j)).clone() }; i += 8; } @@ -158,8 +158,8 @@ where for k in i..self.nrows() { res += unsafe { - conjugate(self.get_unchecked((k, j)).inlined_clone()) - * rhs.get_unchecked((k, j)).inlined_clone() + conjugate(self.get_unchecked((k, j)).clone()) + * rhs.get_unchecked((k, j)).clone() } } } @@ -266,8 +266,7 @@ where for j in 0..self.nrows() { for i in 0..self.ncols() { res += unsafe { - self.get_unchecked((j, i)).inlined_clone() - * rhs.get_unchecked((i, j)).inlined_clone() + self.get_unchecked((j, i)).clone() * rhs.get_unchecked((i, j)).clone() } } } @@ -398,9 +397,9 @@ where // TODO: avoid bound checks. let col2 = a.column(0); - let val = unsafe { x.vget_unchecked(0).inlined_clone() }; - self.axpy(alpha.inlined_clone() * val, &col2, beta); - self[0] += alpha.inlined_clone() * dot(&a.slice_range(1.., 0), &x.rows_range(1..)); + let val = unsafe { x.vget_unchecked(0).clone() }; + self.axpy(alpha.clone() * val, &col2, beta); + self[0] += alpha.clone() * dot(&a.slice_range(1.., 0), &x.rows_range(1..)); for j in 1..dim2 { let col2 = a.column(j); @@ -408,11 +407,11 @@ where let val; unsafe { - val = x.vget_unchecked(j).inlined_clone(); - *self.vget_unchecked_mut(j) += alpha.inlined_clone() * dot; + val = x.vget_unchecked(j).clone(); + *self.vget_unchecked_mut(j) += alpha.clone() * dot; } self.rows_range_mut(j + 1..).axpy( - alpha.inlined_clone() * val, + alpha.clone() * val, &col2.rows_range(j + 1..), T::one(), ); @@ -538,13 +537,12 @@ where if beta.is_zero() { for j in 0..ncols2 { let val = unsafe { self.vget_unchecked_mut(j) }; - *val = alpha.inlined_clone() * dot(&a.column(j), x) + *val = alpha.clone() * dot(&a.column(j), x) } } else { for j in 0..ncols2 { let val = unsafe { self.vget_unchecked_mut(j) }; - *val = alpha.inlined_clone() * dot(&a.column(j), x) - + beta.inlined_clone() * val.inlined_clone(); + *val = alpha.clone() * dot(&a.column(j), x) + beta.clone() * val.clone(); } } } @@ -648,9 +646,9 @@ where for j in 0..ncols1 { // TODO: avoid bound checks. - let val = unsafe { conjugate(y.vget_unchecked(j).inlined_clone()) }; + let val = unsafe { conjugate(y.vget_unchecked(j).clone()) }; self.column_mut(j) - .axpy(alpha.inlined_clone() * val, x, beta.inlined_clone()); + .axpy(alpha.clone() * val, x, beta.clone()); } } @@ -813,12 +811,8 @@ where for j1 in 0..ncols1 { // TODO: avoid bound checks. - self.column_mut(j1).gemv_tr( - alpha.inlined_clone(), - a, - &b.column(j1), - beta.inlined_clone(), - ); + self.column_mut(j1) + .gemv_tr(alpha.clone(), a, &b.column(j1), beta.clone()); } } @@ -875,7 +869,8 @@ where for j1 in 0..ncols1 { // TODO: avoid bound checks. - self.column_mut(j1).gemv_ad(alpha, a, &b.column(j1), beta); + self.column_mut(j1) + .gemv_ad(alpha.clone(), a, &b.column(j1), beta.clone()); } } } @@ -909,13 +904,13 @@ where assert!(dim1 == dim2 && dim1 == dim3, "ger: dimensions mismatch."); for j in 0..dim1 { - let val = unsafe { conjugate(y.vget_unchecked(j).inlined_clone()) }; + let val = unsafe { conjugate(y.vget_unchecked(j).clone()) }; let subdim = Dynamic::new(dim1 - j); // TODO: avoid bound checks. self.generic_slice_mut((j, j), (subdim, Const::<1>)).axpy( - alpha.inlined_clone() * val, + alpha.clone() * val, &x.rows_range(j..), - beta.inlined_clone(), + beta.clone(), ); } } @@ -1076,11 +1071,11 @@ where ShapeConstraint: DimEq + DimEq + DimEq + DimEq, { work.gemv(T::one(), lhs, &mid.column(0), T::zero()); - self.ger(alpha.inlined_clone(), work, &lhs.column(0), beta); + self.ger(alpha.clone(), work, &lhs.column(0), beta); for j in 1..mid.ncols() { work.gemv(T::one(), lhs, &mid.column(j), T::zero()); - self.ger(alpha.inlined_clone(), work, &lhs.column(j), T::one()); + self.ger(alpha.clone(), work, &lhs.column(j), T::one()); } } @@ -1170,12 +1165,12 @@ where { work.gemv(T::one(), mid, &rhs.column(0), T::zero()); self.column_mut(0) - .gemv_tr(alpha.inlined_clone(), rhs, work, beta.inlined_clone()); + .gemv_tr(alpha.clone(), rhs, work, beta.clone()); for j in 1..rhs.ncols() { work.gemv(T::one(), mid, &rhs.column(j), T::zero()); self.column_mut(j) - .gemv_tr(alpha.inlined_clone(), rhs, work, beta.inlined_clone()); + .gemv_tr(alpha.clone(), rhs, work, beta.clone()); } } diff --git a/src/base/blas_uninit.rs b/src/base/blas_uninit.rs index 6f4fde7b..7e449d7d 100644 --- a/src/base/blas_uninit.rs +++ b/src/base/blas_uninit.rs @@ -44,8 +44,8 @@ unsafe fn array_axcpy( { for i in 0..len { let y = Status::assume_init_mut(y.get_unchecked_mut(i * stride1)); - *y = a.inlined_clone() * x.get_unchecked(i * stride2).inlined_clone() * c.inlined_clone() - + beta.inlined_clone() * y.inlined_clone(); + *y = + a.clone() * x.get_unchecked(i * stride2).clone() * c.clone() + beta.clone() * y.clone(); } } @@ -66,9 +66,7 @@ fn array_axc( unsafe { Status::init( y.get_unchecked_mut(i * stride1), - a.inlined_clone() - * x.get_unchecked(i * stride2).inlined_clone() - * c.inlined_clone(), + a.clone() * x.get_unchecked(i * stride2).clone() * c.clone(), ); } } @@ -150,24 +148,24 @@ pub unsafe fn gemv_uninit Matrix3 { let zero = T::zero(); let one = T::one(); Matrix3::new( - scaling.x, - zero, - pt.x - pt.x * scaling.x, - zero, - scaling.y, - pt.y - pt.y * scaling.y, - zero, + scaling.x.clone(), + zero.clone(), + pt.x.clone() - pt.x.clone() * scaling.x.clone(), + zero.clone(), + scaling.y.clone(), + pt.y.clone() - pt.y.clone() * scaling.y.clone(), + zero.clone(), zero, one, ) @@ -125,20 +125,20 @@ impl Matrix4 { let zero = T::zero(); let one = T::one(); Matrix4::new( - scaling.x, - zero, - zero, - pt.x - pt.x * scaling.x, - zero, - scaling.y, - zero, - pt.y - pt.y * scaling.y, - zero, - zero, - scaling.z, - pt.z - pt.z * scaling.z, - zero, - zero, + scaling.x.clone(), + zero.clone(), + zero.clone(), + pt.x.clone() - pt.x.clone() * scaling.x.clone(), + zero.clone(), + scaling.y.clone(), + zero.clone(), + pt.y.clone() - pt.y.clone() * scaling.y.clone(), + zero.clone(), + zero.clone(), + scaling.z.clone(), + pt.z.clone() - pt.z.clone() * scaling.z.clone(), + zero.clone(), + zero.clone(), zero, one, ) @@ -336,7 +336,7 @@ impl(i); - to_scale *= scaling[i].inlined_clone(); + to_scale *= scaling[i].clone(); } } @@ -352,7 +352,7 @@ impl(i); - to_scale *= scaling[i].inlined_clone(); + to_scale *= scaling[i].clone(); } } @@ -366,7 +366,7 @@ impl, Const<3>>> SquareMatrix, let transform = self.fixed_slice::<2, 2>(0, 0); let translation = self.fixed_slice::<2, 1>(0, 2); let normalizer = self.fixed_slice::<1, 2>(2, 0); - let n = normalizer.tr_dot(&pt.coords) + unsafe { *self.get_unchecked((2, 2)) }; + let n = normalizer.tr_dot(&pt.coords) + unsafe { self.get_unchecked((2, 2)).clone() }; if !n.is_zero() { (transform * pt + translation) / n @@ -457,7 +457,7 @@ impl, Const<4>>> SquareMatrix, let transform = self.fixed_slice::<3, 3>(0, 0); let translation = self.fixed_slice::<3, 1>(0, 3); let normalizer = self.fixed_slice::<1, 3>(3, 0); - let n = normalizer.tr_dot(&pt.coords) + unsafe { *self.get_unchecked((3, 3)) }; + let n = normalizer.tr_dot(&pt.coords) + unsafe { self.get_unchecked((3, 3)).clone() }; if !n.is_zero() { (transform * pt + translation) / n diff --git a/src/base/componentwise.rs b/src/base/componentwise.rs index 02b2cae6..dad4d5b2 100644 --- a/src/base/componentwise.rs +++ b/src/base/componentwise.rs @@ -64,7 +64,7 @@ macro_rules! component_binop_impl( for j in 0 .. res.ncols() { for i in 0 .. res.nrows() { unsafe { - res.get_unchecked_mut((i, j)).$op_assign(rhs.get_unchecked((i, j)).inlined_clone()); + res.get_unchecked_mut((i, j)).$op_assign(rhs.get_unchecked((i, j)).clone()); } } } @@ -91,7 +91,7 @@ macro_rules! component_binop_impl( for j in 0 .. self.ncols() { for i in 0 .. self.nrows() { unsafe { - let res = alpha.inlined_clone() * a.get_unchecked((i, j)).inlined_clone().$op(b.get_unchecked((i, j)).inlined_clone()); + let res = alpha.clone() * a.get_unchecked((i, j)).clone().$op(b.get_unchecked((i, j)).clone()); *self.get_unchecked_mut((i, j)) = res; } } @@ -101,8 +101,8 @@ macro_rules! component_binop_impl( for j in 0 .. self.ncols() { for i in 0 .. self.nrows() { unsafe { - let res = alpha.inlined_clone() * a.get_unchecked((i, j)).inlined_clone().$op(b.get_unchecked((i, j)).inlined_clone()); - *self.get_unchecked_mut((i, j)) = beta.inlined_clone() * self.get_unchecked((i, j)).inlined_clone() + res; + let res = alpha.clone() * a.get_unchecked((i, j)).clone().$op(b.get_unchecked((i, j)).clone()); + *self.get_unchecked_mut((i, j)) = beta.clone() * self.get_unchecked((i, j)).clone() + res; } } } @@ -124,7 +124,7 @@ macro_rules! component_binop_impl( for j in 0 .. self.ncols() { for i in 0 .. self.nrows() { unsafe { - self.get_unchecked_mut((i, j)).$op_assign(rhs.get_unchecked((i, j)).inlined_clone()); + self.get_unchecked_mut((i, j)).$op_assign(rhs.get_unchecked((i, j)).clone()); } } } @@ -347,7 +347,7 @@ impl> Matrix SA: StorageMut, { for e in self.iter_mut() { - *e += rhs.inlined_clone() + *e += rhs.clone() } } } diff --git a/src/base/construction.rs b/src/base/construction.rs index 3deb66c2..fe4e4b08 100644 --- a/src/base/construction.rs +++ b/src/base/construction.rs @@ -104,8 +104,7 @@ where unsafe { for i in 0..nrows.value() { for j in 0..ncols.value() { - *res.get_unchecked_mut((i, j)) = - MaybeUninit::new(iter.next().unwrap().inlined_clone()) + *res.get_unchecked_mut((i, j)) = MaybeUninit::new(iter.next().unwrap().clone()) } } @@ -166,7 +165,7 @@ where let mut res = Self::zeros_generic(nrows, ncols); for i in 0..crate::min(nrows.value(), ncols.value()) { - unsafe { *res.get_unchecked_mut((i, i)) = elt.inlined_clone() } + unsafe { *res.get_unchecked_mut((i, i)) = elt.clone() } } res @@ -188,7 +187,7 @@ where ); for (i, elt) in elts.iter().enumerate() { - unsafe { *res.get_unchecked_mut((i, i)) = elt.inlined_clone() } + unsafe { *res.get_unchecked_mut((i, i)) = elt.clone() } } res @@ -232,7 +231,7 @@ where // TODO: optimize that. Self::from_fn_generic(R::from_usize(nrows), C::from_usize(ncols), |i, j| { - rows[i][(0, j)].inlined_clone() + rows[i][(0, j)].clone() }) } @@ -274,7 +273,7 @@ where // TODO: optimize that. Self::from_fn_generic(R::from_usize(nrows), C::from_usize(ncols), |i, j| { - columns[j][i].inlined_clone() + columns[j][i].clone() }) } @@ -358,7 +357,7 @@ where for i in 0..diag.len() { unsafe { - *res.get_unchecked_mut((i, i)) = diag.vget_unchecked(i).inlined_clone(); + *res.get_unchecked_mut((i, i)) = diag.vget_unchecked(i).clone(); } } diff --git a/src/base/conversion.rs b/src/base/conversion.rs index ec7fd936..46747f0e 100644 --- a/src/base/conversion.rs +++ b/src/base/conversion.rs @@ -509,11 +509,7 @@ where let (nrows, ncols) = arr[0].shape_generic(); Self::from_fn_generic(nrows, ncols, |i, j| { - [ - arr[0][(i, j)].inlined_clone(), - arr[1][(i, j)].inlined_clone(), - ] - .into() + [arr[0][(i, j)].clone(), arr[1][(i, j)].clone()].into() }) } } @@ -531,10 +527,10 @@ where Self::from_fn_generic(nrows, ncols, |i, j| { [ - arr[0][(i, j)].inlined_clone(), - arr[1][(i, j)].inlined_clone(), - arr[2][(i, j)].inlined_clone(), - arr[3][(i, j)].inlined_clone(), + arr[0][(i, j)].clone(), + arr[1][(i, j)].clone(), + arr[2][(i, j)].clone(), + arr[3][(i, j)].clone(), ] .into() }) @@ -554,14 +550,14 @@ where Self::from_fn_generic(nrows, ncols, |i, j| { [ - arr[0][(i, j)].inlined_clone(), - arr[1][(i, j)].inlined_clone(), - arr[2][(i, j)].inlined_clone(), - arr[3][(i, j)].inlined_clone(), - arr[4][(i, j)].inlined_clone(), - arr[5][(i, j)].inlined_clone(), - arr[6][(i, j)].inlined_clone(), - arr[7][(i, j)].inlined_clone(), + arr[0][(i, j)].clone(), + arr[1][(i, j)].clone(), + arr[2][(i, j)].clone(), + arr[3][(i, j)].clone(), + arr[4][(i, j)].clone(), + arr[5][(i, j)].clone(), + arr[6][(i, j)].clone(), + arr[7][(i, j)].clone(), ] .into() }) @@ -580,22 +576,22 @@ where Self::from_fn_generic(nrows, ncols, |i, j| { [ - arr[0][(i, j)].inlined_clone(), - arr[1][(i, j)].inlined_clone(), - arr[2][(i, j)].inlined_clone(), - arr[3][(i, j)].inlined_clone(), - arr[4][(i, j)].inlined_clone(), - arr[5][(i, j)].inlined_clone(), - arr[6][(i, j)].inlined_clone(), - arr[7][(i, j)].inlined_clone(), - arr[8][(i, j)].inlined_clone(), - arr[9][(i, j)].inlined_clone(), - arr[10][(i, j)].inlined_clone(), - arr[11][(i, j)].inlined_clone(), - arr[12][(i, j)].inlined_clone(), - arr[13][(i, j)].inlined_clone(), - arr[14][(i, j)].inlined_clone(), - arr[15][(i, j)].inlined_clone(), + arr[0][(i, j)].clone(), + arr[1][(i, j)].clone(), + arr[2][(i, j)].clone(), + arr[3][(i, j)].clone(), + arr[4][(i, j)].clone(), + arr[5][(i, j)].clone(), + arr[6][(i, j)].clone(), + arr[7][(i, j)].clone(), + arr[8][(i, j)].clone(), + arr[9][(i, j)].clone(), + arr[10][(i, j)].clone(), + arr[11][(i, j)].clone(), + arr[12][(i, j)].clone(), + arr[13][(i, j)].clone(), + arr[14][(i, j)].clone(), + arr[15][(i, j)].clone(), ] .into() }) diff --git a/src/base/edition.rs b/src/base/edition.rs index bca017c4..9569294e 100644 --- a/src/base/edition.rs +++ b/src/base/edition.rs @@ -70,7 +70,7 @@ impl> Matrix { // Safety: all indices are in range. unsafe { *res.vget_unchecked_mut(destination) = - MaybeUninit::new(src.vget_unchecked(*source).inlined_clone()); + MaybeUninit::new(src.vget_unchecked(*source).clone()); } } } @@ -96,7 +96,7 @@ impl> Matrix { // NOTE: this is basically a copy_frow but wrapping the values insnide of MaybeUninit. res.column_mut(destination) .zip_apply(&self.column(*source), |out, e| { - *out = MaybeUninit::new(e.inlined_clone()) + *out = MaybeUninit::new(e.clone()) }); } @@ -120,7 +120,7 @@ impl> Matrix { assert_eq!(diag.len(), min_nrows_ncols, "Mismatched dimensions."); for i in 0..min_nrows_ncols { - unsafe { *self.get_unchecked_mut((i, i)) = diag.vget_unchecked(i).inlined_clone() } + unsafe { *self.get_unchecked_mut((i, i)) = diag.vget_unchecked(i).clone() } } } @@ -177,7 +177,7 @@ impl> Matrix { T: Scalar, { for e in self.iter_mut() { - *e = val.inlined_clone() + *e = val.clone() } } @@ -201,7 +201,7 @@ impl> Matrix { let n = cmp::min(nrows, ncols); for i in 0..n { - unsafe { *self.get_unchecked_mut((i, i)) = val.inlined_clone() } + unsafe { *self.get_unchecked_mut((i, i)) = val.clone() } } } @@ -213,7 +213,7 @@ impl> Matrix { { assert!(i < self.nrows(), "Row index out of bounds."); for j in 0..self.ncols() { - unsafe { *self.get_unchecked_mut((i, j)) = val.inlined_clone() } + unsafe { *self.get_unchecked_mut((i, j)) = val.clone() } } } @@ -225,7 +225,7 @@ impl> Matrix { { assert!(j < self.ncols(), "Row index out of bounds."); for i in 0..self.nrows() { - unsafe { *self.get_unchecked_mut((i, j)) = val.inlined_clone() } + unsafe { *self.get_unchecked_mut((i, j)) = val.clone() } } } @@ -243,7 +243,7 @@ impl> Matrix { { for j in 0..self.ncols() { for i in (j + shift)..self.nrows() { - unsafe { *self.get_unchecked_mut((i, j)) = val.inlined_clone() } + unsafe { *self.get_unchecked_mut((i, j)) = val.clone() } } } } @@ -264,7 +264,7 @@ impl> Matrix { // TODO: is there a more efficient way to avoid the min ? // (necessary for rectangular matrices) for i in 0..cmp::min(j + 1 - shift, self.nrows()) { - unsafe { *self.get_unchecked_mut((i, j)) = val.inlined_clone() } + unsafe { *self.get_unchecked_mut((i, j)) = val.clone() } } } } @@ -281,7 +281,7 @@ impl> Matrix { for j in 0..dim { for i in j + 1..dim { unsafe { - *self.get_unchecked_mut((i, j)) = self.get_unchecked((j, i)).inlined_clone(); + *self.get_unchecked_mut((i, j)) = self.get_unchecked((j, i)).clone(); } } } @@ -296,7 +296,7 @@ impl> Matrix { for j in 1..self.ncols() { for i in 0..j { unsafe { - *self.get_unchecked_mut((i, j)) = self.get_unchecked((j, i)).inlined_clone(); + *self.get_unchecked_mut((i, j)) = self.get_unchecked((j, i)).clone(); } } } @@ -647,7 +647,7 @@ impl> Matrix { { let mut res = unsafe { self.insert_columns_generic_uninitialized(i, Const::) }; res.fixed_columns_mut::(i) - .fill_with(|| MaybeUninit::new(val.inlined_clone())); + .fill_with(|| MaybeUninit::new(val.clone())); // Safety: the result is now fully initialized. The added columns have // been initialized by the `fill_with` above, and the rest have @@ -665,7 +665,7 @@ impl> Matrix { { let mut res = unsafe { self.insert_columns_generic_uninitialized(i, Dynamic::new(n)) }; res.columns_mut(i, n) - .fill_with(|| MaybeUninit::new(val.inlined_clone())); + .fill_with(|| MaybeUninit::new(val.clone())); // Safety: the result is now fully initialized. The added columns have // been initialized by the `fill_with` above, and the rest have @@ -740,7 +740,7 @@ impl> Matrix { { let mut res = unsafe { self.insert_rows_generic_uninitialized(i, Const::) }; res.fixed_rows_mut::(i) - .fill_with(|| MaybeUninit::new(val.inlined_clone())); + .fill_with(|| MaybeUninit::new(val.clone())); // Safety: the result is now fully initialized. The added rows have // been initialized by the `fill_with` above, and the rest have @@ -758,7 +758,7 @@ impl> Matrix { { let mut res = unsafe { self.insert_rows_generic_uninitialized(i, Dynamic::new(n)) }; res.rows_mut(i, n) - .fill_with(|| MaybeUninit::new(val.inlined_clone())); + .fill_with(|| MaybeUninit::new(val.clone())); // Safety: the result is now fully initialized. The added rows have // been initialized by the `fill_with` above, and the rest have @@ -896,7 +896,7 @@ impl> Matrix { if new_ncols.value() > ncols { res.columns_range_mut(ncols..) - .fill_with(|| MaybeUninit::new(val.inlined_clone())); + .fill_with(|| MaybeUninit::new(val.clone())); } // Safety: the result is now fully initialized by `reallocate_copy` and @@ -933,12 +933,12 @@ impl> Matrix { if new_ncols.value() > ncols { res.columns_range_mut(ncols..) - .fill_with(|| MaybeUninit::new(val.inlined_clone())); + .fill_with(|| MaybeUninit::new(val.clone())); } if new_nrows.value() > nrows { res.slice_range_mut(nrows.., ..cmp::min(ncols, new_ncols.value())) - .fill_with(|| MaybeUninit::new(val.inlined_clone())); + .fill_with(|| MaybeUninit::new(val.clone())); } // Safety: the result is now fully initialized by `reallocate_copy` and diff --git a/src/base/interpolation.rs b/src/base/interpolation.rs index d5661e40..81b1a374 100644 --- a/src/base/interpolation.rs +++ b/src/base/interpolation.rs @@ -26,7 +26,7 @@ impl, { let mut res = self.clone_owned(); - res.axpy(t.inlined_clone(), rhs, T::one() - t); + res.axpy(t.clone(), rhs, T::one() - t); res } @@ -109,14 +109,14 @@ impl> Unit> { return Some(Unit::new_unchecked(self.clone_owned())); } - let hang = c_hang.acos(); - let s_hang = (T::one() - c_hang * c_hang).sqrt(); + let hang = c_hang.clone().acos(); + let s_hang = (T::one() - c_hang.clone() * c_hang).sqrt(); // TODO: what if s_hang is 0.0 ? The result is not well-defined. if relative_eq!(s_hang, T::zero(), epsilon = epsilon) { None } else { - let ta = ((T::one() - t) * hang).sin() / s_hang; + let ta = ((T::one() - t.clone()) * hang.clone()).sin() / s_hang.clone(); let tb = (t * hang).sin() / s_hang; let mut res = self.scale(ta); res.axpy(tb, &**rhs, T::one()); diff --git a/src/base/matrix.rs b/src/base/matrix.rs index ce5f2f18..4dccc439 100644 --- a/src/base/matrix.rs +++ b/src/base/matrix.rs @@ -567,13 +567,13 @@ impl> Matrix { R2: Dim, C2: Dim, SB: Storage, - T::Epsilon: Copy, + T::Epsilon: Clone, ShapeConstraint: SameNumberOfRows + SameNumberOfColumns, { assert!(self.shape() == other.shape()); self.iter() .zip(other.iter()) - .all(|(a, b)| a.relative_eq(b, eps, max_relative)) + .all(|(a, b)| a.relative_eq(b, eps.clone(), max_relative.clone())) } /// Tests whether `self` and `rhs` are exactly equal. @@ -668,7 +668,7 @@ impl> Matrix { for j in 0..res.ncols() { for i in 0..res.nrows() { *res.get_unchecked_mut((i, j)) = - MaybeUninit::new(self.get_unchecked((i, j)).inlined_clone()); + MaybeUninit::new(self.get_unchecked((i, j)).clone()); } } @@ -704,7 +704,7 @@ impl> Matrix { unsafe { Status::init( out.get_unchecked_mut((j, i)), - self.get_unchecked((i, j)).inlined_clone(), + self.get_unchecked((i, j)).clone(), ); } } @@ -758,7 +758,7 @@ impl> Matrix { for i in 0..nrows.value() { // Safety: all indices are in range. unsafe { - let a = self.data.get_unchecked(i, j).inlined_clone(); + let a = self.data.get_unchecked(i, j).clone(); *res.data.get_unchecked_mut(i, j) = MaybeUninit::new(f(a)); } } @@ -827,7 +827,7 @@ impl> Matrix { for i in 0..nrows.value() { // Safety: all indices are in range. unsafe { - let a = self.data.get_unchecked(i, j).inlined_clone(); + let a = self.data.get_unchecked(i, j).clone(); *res.data.get_unchecked_mut(i, j) = MaybeUninit::new(f(i, j, a)); } } @@ -863,8 +863,8 @@ impl> Matrix { for i in 0..nrows.value() { // Safety: all indices are in range. unsafe { - let a = self.data.get_unchecked(i, j).inlined_clone(); - let b = rhs.data.get_unchecked(i, j).inlined_clone(); + let a = self.data.get_unchecked(i, j).clone(); + let b = rhs.data.get_unchecked(i, j).clone(); *res.data.get_unchecked_mut(i, j) = MaybeUninit::new(f(a, b)) } } @@ -912,9 +912,9 @@ impl> Matrix { for i in 0..nrows.value() { // Safety: all indices are in range. unsafe { - let a = self.data.get_unchecked(i, j).inlined_clone(); - let b = b.data.get_unchecked(i, j).inlined_clone(); - let c = c.data.get_unchecked(i, j).inlined_clone(); + let a = self.data.get_unchecked(i, j).clone(); + let b = b.data.get_unchecked(i, j).clone(); + let c = c.data.get_unchecked(i, j).clone(); *res.data.get_unchecked_mut(i, j) = MaybeUninit::new(f(a, b, c)) } } @@ -939,7 +939,7 @@ impl> Matrix { for i in 0..nrows.value() { // Safety: all indices are in range. unsafe { - let a = self.data.get_unchecked(i, j).inlined_clone(); + let a = self.data.get_unchecked(i, j).clone(); res = f(res, a) } } @@ -978,8 +978,8 @@ impl> Matrix { for j in 0..ncols.value() { for i in 0..nrows.value() { unsafe { - let a = self.data.get_unchecked(i, j).inlined_clone(); - let b = rhs.data.get_unchecked(i, j).inlined_clone(); + let a = self.data.get_unchecked(i, j).clone(); + let b = rhs.data.get_unchecked(i, j).clone(); res = f(res, a, b) } } @@ -1033,7 +1033,7 @@ impl> Matrix { for i in 0..nrows { unsafe { let e = self.data.get_unchecked_mut(i, j); - let rhs = rhs.get_unchecked((i, j)).inlined_clone(); + let rhs = rhs.get_unchecked((i, j)).clone(); f(e, rhs) } } @@ -1078,8 +1078,8 @@ impl> Matrix { for i in 0..nrows { unsafe { let e = self.data.get_unchecked_mut(i, j); - let b = b.get_unchecked((i, j)).inlined_clone(); - let c = c.get_unchecked((i, j)).inlined_clone(); + let b = b.get_unchecked((i, j)).clone(); + let c = c.get_unchecked((i, j)).clone(); f(e, b, c) } } @@ -1248,8 +1248,7 @@ impl> Matrix { for j in 0..ncols { for i in 0..nrows { unsafe { - *self.get_unchecked_mut((i, j)) = - slice.get_unchecked(i + j * nrows).inlined_clone(); + *self.get_unchecked_mut((i, j)) = slice.get_unchecked(i + j * nrows).clone(); } } } @@ -1273,7 +1272,7 @@ impl> Matrix { for j in 0..self.ncols() { for i in 0..self.nrows() { unsafe { - *self.get_unchecked_mut((i, j)) = other.get_unchecked((i, j)).inlined_clone(); + *self.get_unchecked_mut((i, j)) = other.get_unchecked((i, j)).clone(); } } } @@ -1298,7 +1297,7 @@ impl> Matrix { for j in 0..ncols { for i in 0..nrows { unsafe { - *self.get_unchecked_mut((i, j)) = other.get_unchecked((j, i)).inlined_clone(); + *self.get_unchecked_mut((i, j)) = other.get_unchecked((j, i)).clone(); } } } @@ -1400,7 +1399,7 @@ impl> Matrix> Matrix, { - self.map(|e| e.simd_unscale(real)) + self.map(|e| e.simd_unscale(real.clone())) } /// Multiplies each component of the complex matrix `self` by the given real. @@ -1485,7 +1484,7 @@ impl> Matrix, { - self.map(|e| e.simd_scale(real)) + self.map(|e| e.simd_scale(real.clone())) } } @@ -1493,19 +1492,19 @@ impl> Matrix> Matrix for i in 0..dim { for j in 0..i { unsafe { - let ref_ij = self.get_unchecked_mut((i, j)) as *mut T; - let ref_ji = self.get_unchecked_mut((j, i)) as *mut T; - let conj_ij = (*ref_ij).simd_conjugate(); - let conj_ji = (*ref_ji).simd_conjugate(); - *ref_ij = conj_ji; - *ref_ji = conj_ij; + let ref_ij = self.get_unchecked((i, j)).clone(); + let ref_ji = self.get_unchecked((j, i)).clone(); + let conj_ij = ref_ij.simd_conjugate(); + let conj_ji = ref_ji.simd_conjugate(); + *self.get_unchecked_mut((i, j)) = conj_ji; + *self.get_unchecked_mut((j, i)) = conj_ij; } } { let diag = unsafe { self.get_unchecked_mut((i, i)) }; - *diag = diag.simd_conjugate(); + *diag = diag.clone().simd_conjugate(); } } } @@ -1577,7 +1576,7 @@ impl> SquareMatrix { // Safety: all indices are in range. unsafe { *res.vget_unchecked_mut(i) = - MaybeUninit::new(f(self.get_unchecked((i, i)).inlined_clone())); + MaybeUninit::new(f(self.get_unchecked((i, i)).clone())); } } @@ -1601,7 +1600,7 @@ impl> SquareMatrix { let mut res = T::zero(); for i in 0..dim.value() { - res += unsafe { self.get_unchecked((i, i)).inlined_clone() }; + res += unsafe { self.get_unchecked((i, i)).clone() }; } res @@ -1723,7 +1722,7 @@ impl AbsDiffEq for Matrix where T: Scalar + AbsDiffEq, S: RawStorage, - T::Epsilon: Copy, + T::Epsilon: Clone, { type Epsilon = T::Epsilon; @@ -1736,7 +1735,7 @@ where fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool { self.iter() .zip(other.iter()) - .all(|(a, b)| a.abs_diff_eq(b, epsilon)) + .all(|(a, b)| a.abs_diff_eq(b, epsilon.clone())) } } @@ -1744,7 +1743,7 @@ impl RelativeEq for Matrix where T: Scalar + RelativeEq, S: Storage, - T::Epsilon: Copy, + T::Epsilon: Clone, { #[inline] fn default_max_relative() -> Self::Epsilon { @@ -1766,7 +1765,7 @@ impl UlpsEq for Matrix where T: Scalar + UlpsEq, S: RawStorage, - T::Epsilon: Copy, + T::Epsilon: Clone, { #[inline] fn default_max_ulps() -> u32 { @@ -1778,7 +1777,7 @@ where assert!(self.shape() == other.shape()); self.iter() .zip(other.iter()) - .all(|(a, b)| a.ulps_eq(b, epsilon, max_ulps)) + .all(|(a, b)| a.ulps_eq(b, epsilon.clone(), max_ulps.clone())) } } @@ -2029,9 +2028,8 @@ impl> Vector { pub fn cross_matrix(&self) -> OMatrix { OMatrix::::new( T::zero(), - -self[2].inlined_clone(), - self[1].inlined_clone(), - self[2].inlined_clone(), + -self[2].clone(), + self[1].clone(), + self[2].clone(), T::zero(), - -self[0].inlined_clone(), - -self[1].inlined_clone(), - self[0].inlined_clone(), + -self[0].clone(), + -self[1].clone(), + self[0].clone(), T::zero(), ) } @@ -2170,7 +2156,7 @@ impl AbsDiffEq for Unit> where T: Scalar + AbsDiffEq, S: RawStorage, - T::Epsilon: Copy, + T::Epsilon: Clone, { type Epsilon = T::Epsilon; @@ -2189,7 +2175,7 @@ impl RelativeEq for Unit> where T: Scalar + RelativeEq, S: Storage, - T::Epsilon: Copy, + T::Epsilon: Clone, { #[inline] fn default_max_relative() -> Self::Epsilon { @@ -2212,7 +2198,7 @@ impl UlpsEq for Unit> where T: Scalar + UlpsEq, S: RawStorage, - T::Epsilon: Copy, + T::Epsilon: Clone, { #[inline] fn default_max_ulps() -> u32 { diff --git a/src/base/min_max.rs b/src/base/min_max.rs index 3d390194..0876fe67 100644 --- a/src/base/min_max.rs +++ b/src/base/min_max.rs @@ -40,8 +40,8 @@ impl> Matrix { T: SimdComplexField, { self.fold_with( - |e| e.unwrap_or(&T::zero()).simd_norm1(), - |a, b| a.simd_max(b.simd_norm1()), + |e| e.unwrap_or(&T::zero()).clone().simd_norm1(), + |a, b| a.simd_max(b.clone().simd_norm1()), ) } @@ -60,8 +60,8 @@ impl> Matrix { T: SimdPartialOrd + Zero, { self.fold_with( - |e| e.map(|e| e.inlined_clone()).unwrap_or_else(T::zero), - |a, b| a.simd_max(b.inlined_clone()), + |e| e.map(|e| e.clone()).unwrap_or_else(T::zero), + |a, b| a.simd_max(b.clone()), ) } @@ -101,10 +101,10 @@ impl> Matrix { { self.fold_with( |e| { - e.map(|e| e.simd_norm1()) + e.map(|e| e.clone().simd_norm1()) .unwrap_or_else(T::SimdRealField::zero) }, - |a, b| a.simd_min(b.simd_norm1()), + |a, b| a.simd_min(b.clone().simd_norm1()), ) } @@ -123,8 +123,8 @@ impl> Matrix { T: SimdPartialOrd + Zero, { self.fold_with( - |e| e.map(|e| e.inlined_clone()).unwrap_or_else(T::zero), - |a, b| a.simd_min(b.inlined_clone()), + |e| e.map(|e| e.clone()).unwrap_or_else(T::zero), + |a, b| a.simd_min(b.clone()), ) } @@ -149,12 +149,12 @@ impl> Matrix { { assert!(!self.is_empty(), "The input matrix must not be empty."); - let mut the_max = unsafe { self.get_unchecked((0, 0)).norm1() }; + let mut the_max = unsafe { self.get_unchecked((0, 0)).clone().norm1() }; let mut the_ij = (0, 0); for j in 0..self.ncols() { for i in 0..self.nrows() { - let val = unsafe { self.get_unchecked((i, j)).norm1() }; + let val = unsafe { self.get_unchecked((i, j)).clone().norm1() }; if val > the_max { the_max = val; @@ -224,11 +224,11 @@ impl> Vector { { assert!(!self.is_empty(), "The input vector must not be empty."); - let mut the_max = unsafe { self.vget_unchecked(0).norm1() }; + let mut the_max = unsafe { self.vget_unchecked(0).clone().norm1() }; let mut the_i = 0; for i in 1..self.nrows() { - let val = unsafe { self.vget_unchecked(i).norm1() }; + let val = unsafe { self.vget_unchecked(i).clone().norm1() }; if val > the_max { the_max = val; @@ -268,7 +268,7 @@ impl> Vector { } } - (the_i, the_max.inlined_clone()) + (the_i, the_max.clone()) } /// Computes the index of the vector component with the largest value. @@ -350,7 +350,7 @@ impl> Vector { } } - (the_i, the_min.inlined_clone()) + (the_i, the_min.clone()) } /// Computes the index of the vector component with the smallest value. diff --git a/src/base/norm.rs b/src/base/norm.rs index c138069d..3968885b 100644 --- a/src/base/norm.rs +++ b/src/base/norm.rs @@ -328,7 +328,7 @@ impl> Matrix { DefaultAllocator: Allocator + Allocator, { let n = self.norm(); - let le = n.simd_le(min_norm); + let le = n.clone().simd_le(min_norm); let val = self.unscale(n); SimdOption::new(val, le) } @@ -377,7 +377,7 @@ impl> Matrix { DefaultAllocator: Allocator + Allocator, { let n = self.norm(); - let scaled = self.scale(max / n); + let scaled = self.scale(max.clone() / n.clone()); let use_scaled = n.simd_gt(max); scaled.select(use_scaled, self.clone_owned()) } @@ -413,7 +413,7 @@ impl> Matrix { T: SimdComplexField, { let n = self.norm(); - self.unscale_mut(n); + self.unscale_mut(n.clone()); n } @@ -433,8 +433,13 @@ impl> Matrix { DefaultAllocator: Allocator + Allocator, { let n = self.norm(); - let le = n.simd_le(min_norm); - self.apply(|e| *e = e.simd_unscale(n).select(le, *e)); + let le = n.clone().simd_le(min_norm); + self.apply(|e| { + *e = e + .clone() + .simd_unscale(n.clone()) + .select(le.clone(), e.clone()) + }); SimdOption::new(n, le) } @@ -451,7 +456,7 @@ impl> Matrix { if n <= min_norm { None } else { - self.unscale_mut(n); + self.unscale_mut(n.clone()); Some(n) } } @@ -572,7 +577,7 @@ where && f(&Self::canonical_basis_element(1)); } else if vs.len() == 1 { let v = &vs[0]; - let res = Self::from_column_slice(&[-v[1], v[0]]); + let res = Self::from_column_slice(&[-v[1].clone(), v[0].clone()]); let _ = f(&res.normalize()); } @@ -588,10 +593,10 @@ where let v = &vs[0]; let mut a; - if v[0].norm1() > v[1].norm1() { - a = Self::from_column_slice(&[v[2], T::zero(), -v[0]]); + if v[0].clone().norm1() > v[1].clone().norm1() { + a = Self::from_column_slice(&[v[2].clone(), T::zero(), -v[0].clone()]); } else { - a = Self::from_column_slice(&[T::zero(), -v[2], v[1]]); + a = Self::from_column_slice(&[T::zero(), -v[2].clone(), v[1].clone()]); }; let _ = a.normalize_mut(); diff --git a/src/base/ops.rs b/src/base/ops.rs index bbeb6d07..5608119e 100644 --- a/src/base/ops.rs +++ b/src/base/ops.rs @@ -116,7 +116,7 @@ where #[inline] pub fn neg_mut(&mut self) { for e in self.iter_mut() { - *e = -e.inlined_clone() + *e = -e.clone() } } } @@ -163,12 +163,12 @@ macro_rules! componentwise_binop_impl( let arr2 = rhs.data.as_slice_unchecked(); let out = out.data.as_mut_slice_unchecked(); for i in 0 .. arr1.len() { - Status::init(out.get_unchecked_mut(i), arr1.get_unchecked(i).inlined_clone().$method(arr2.get_unchecked(i).inlined_clone())); + Status::init(out.get_unchecked_mut(i), arr1.get_unchecked(i).clone().$method(arr2.get_unchecked(i).clone())); } } else { for j in 0 .. self.ncols() { for i in 0 .. self.nrows() { - let val = self.get_unchecked((i, j)).inlined_clone().$method(rhs.get_unchecked((i, j)).inlined_clone()); + let val = self.get_unchecked((i, j)).clone().$method(rhs.get_unchecked((i, j)).clone()); Status::init(out.get_unchecked_mut((i, j)), val); } } @@ -193,12 +193,12 @@ macro_rules! componentwise_binop_impl( let arr2 = rhs.data.as_slice_unchecked(); for i in 0 .. arr2.len() { - arr1.get_unchecked_mut(i).$method_assign(arr2.get_unchecked(i).inlined_clone()); + arr1.get_unchecked_mut(i).$method_assign(arr2.get_unchecked(i).clone()); } } else { for j in 0 .. rhs.ncols() { for i in 0 .. rhs.nrows() { - self.get_unchecked_mut((i, j)).$method_assign(rhs.get_unchecked((i, j)).inlined_clone()) + self.get_unchecked_mut((i, j)).$method_assign(rhs.get_unchecked((i, j)).clone()) } } } @@ -221,14 +221,14 @@ macro_rules! componentwise_binop_impl( let arr2 = rhs.data.as_mut_slice_unchecked(); for i in 0 .. arr1.len() { - let res = arr1.get_unchecked(i).inlined_clone().$method(arr2.get_unchecked(i).inlined_clone()); + let res = arr1.get_unchecked(i).clone().$method(arr2.get_unchecked(i).clone()); *arr2.get_unchecked_mut(i) = res; } } else { for j in 0 .. self.ncols() { for i in 0 .. self.nrows() { let r = rhs.get_unchecked_mut((i, j)); - *r = self.get_unchecked((i, j)).inlined_clone().$method(r.inlined_clone()) + *r = self.get_unchecked((i, j)).clone().$method(r.clone()) } } } @@ -472,7 +472,7 @@ macro_rules! componentwise_scalarop_impl( // for left in res.iter_mut() { for left in res.as_mut_slice().iter_mut() { - *left = left.inlined_clone().$method(rhs.inlined_clone()) + *left = left.clone().$method(rhs.clone()) } res @@ -498,7 +498,7 @@ macro_rules! componentwise_scalarop_impl( fn $method_assign(&mut self, rhs: T) { for j in 0 .. self.ncols() { for i in 0 .. self.nrows() { - unsafe { self.get_unchecked_mut((i, j)).$method_assign(rhs.inlined_clone()) }; + unsafe { self.get_unchecked_mut((i, j)).$method_assign(rhs.clone()) }; } } } @@ -815,11 +815,11 @@ where for j1 in 0..ncols1.value() { for j2 in 0..ncols2.value() { for i1 in 0..nrows1.value() { - let coeff = self.get_unchecked((i1, j1)).inlined_clone(); + let coeff = self.get_unchecked((i1, j1)).clone(); for i2 in 0..nrows2.value() { *data_res = MaybeUninit::new( - coeff.inlined_clone() * rhs.get_unchecked((i2, j2)).inlined_clone(), + coeff.clone() * rhs.get_unchecked((i2, j2)).clone(), ); data_res = data_res.offset(1); } diff --git a/src/base/properties.rs b/src/base/properties.rs index 091d36ef..7536a4a5 100644 --- a/src/base/properties.rs +++ b/src/base/properties.rs @@ -60,7 +60,7 @@ impl> Matrix { pub fn is_identity(&self, eps: T::Epsilon) -> bool where T: Zero + One + RelativeEq, - T::Epsilon: Copy, + T::Epsilon: Clone, { let (nrows, ncols) = self.shape(); let d; @@ -70,7 +70,7 @@ impl> Matrix { for i in d..nrows { for j in 0..ncols { - if !relative_eq!(self[(i, j)], T::zero(), epsilon = eps) { + if !relative_eq!(self[(i, j)], T::zero(), epsilon = eps.clone()) { return false; } } @@ -81,7 +81,7 @@ impl> Matrix { for i in 0..nrows { for j in d..ncols { - if !relative_eq!(self[(i, j)], T::zero(), epsilon = eps) { + if !relative_eq!(self[(i, j)], T::zero(), epsilon = eps.clone()) { return false; } } @@ -92,8 +92,8 @@ impl> Matrix { for i in 1..d { for j in 0..i { // TODO: use unsafe indexing. - if !relative_eq!(self[(i, j)], T::zero(), epsilon = eps) - || !relative_eq!(self[(j, i)], T::zero(), epsilon = eps) + if !relative_eq!(self[(i, j)], T::zero(), epsilon = eps.clone()) + || !relative_eq!(self[(j, i)], T::zero(), epsilon = eps.clone()) { return false; } @@ -102,7 +102,7 @@ impl> Matrix { // Diagonal elements of the sub-square matrix. for i in 0..d { - if !relative_eq!(self[(i, i)], T::one(), epsilon = eps) { + if !relative_eq!(self[(i, i)], T::one(), epsilon = eps.clone()) { return false; } } @@ -122,7 +122,7 @@ impl> Matrix { where T: Zero + One + ClosedAdd + ClosedMul + RelativeEq, S: Storage, - T::Epsilon: Copy, + T::Epsilon: Clone, DefaultAllocator: Allocator + Allocator, { (self.ad_mul(self)).is_identity(eps) diff --git a/src/base/scalar.rs b/src/base/scalar.rs index baee6e4f..1b9751e2 100644 --- a/src/base/scalar.rs +++ b/src/base/scalar.rs @@ -1,20 +1,8 @@ -use std::any::Any; use std::fmt::Debug; /// The basic scalar type for all structures of `nalgebra`. /// /// This does not make any assumption on the algebraic properties of `Self`. -pub trait Scalar: 'static + Clone + PartialEq + Debug { - #[inline(always)] - /// Performance hack: Clone doesn't get inlined for Copy types in debug mode, so make it inline anyway. - fn inlined_clone(&self) -> Self { - self.clone() - } -} +pub trait Scalar: 'static + Clone + PartialEq + Debug {} -impl Scalar for T { - #[inline(always)] - fn inlined_clone(&self) -> T { - *self - } -} +impl Scalar for T {} diff --git a/src/base/statistics.rs b/src/base/statistics.rs index ebf694a5..1cede1f2 100644 --- a/src/base/statistics.rs +++ b/src/base/statistics.rs @@ -216,11 +216,11 @@ impl> Matrix { T::zero() } else { let val = self.iter().cloned().fold((T::zero(), T::zero()), |a, b| { - (a.0 + b.inlined_clone() * b.inlined_clone(), a.1 + b) + (a.0 + b.clone() * b.clone(), a.1 + b) }); let denom = T::one() / crate::convert::<_, T>(self.len() as f64); - let vd = val.1 * denom.inlined_clone(); - val.0 * denom - vd.inlined_clone() * vd + let vd = val.1 * denom.clone(); + val.0 * denom - vd.clone() * vd } } @@ -289,15 +289,14 @@ impl> Matrix { let (nrows, ncols) = self.shape_generic(); let mut mean = self.column_mean(); - mean.apply(|e| *e = -(e.inlined_clone() * e.inlined_clone())); + mean.apply(|e| *e = -(e.clone() * e.clone())); let denom = T::one() / crate::convert::<_, T>(ncols.value() as f64); self.compress_columns(mean, |out, col| { for i in 0..nrows.value() { unsafe { let val = col.vget_unchecked(i); - *out.vget_unchecked_mut(i) += - denom.inlined_clone() * val.inlined_clone() * val.inlined_clone() + *out.vget_unchecked_mut(i) += denom.clone() * val.clone() * val.clone() } } }) @@ -397,7 +396,7 @@ impl> Matrix { let (nrows, ncols) = self.shape_generic(); let denom = T::one() / crate::convert::<_, T>(ncols.value() as f64); self.compress_columns(OVector::zeros_generic(nrows, Const::<1>), |out, col| { - out.axpy(denom.inlined_clone(), &col, T::one()) + out.axpy(denom.clone(), &col, T::one()) }) } } diff --git a/src/base/swizzle.rs b/src/base/swizzle.rs index 6ed05d81..30332261 100644 --- a/src/base/swizzle.rs +++ b/src/base/swizzle.rs @@ -11,7 +11,7 @@ macro_rules! impl_swizzle { #[must_use] pub fn $name(&self) -> $Result where D::Typenum: Cmp { - $Result::new($(self[$i].inlined_clone()),*) + $Result::new($(self[$i].clone()),*) } )* )* diff --git a/src/base/unit.rs b/src/base/unit.rs index fa869c09..cd32b44b 100644 --- a/src/base/unit.rs +++ b/src/base/unit.rs @@ -170,7 +170,7 @@ impl Unit { #[inline] pub fn new_and_get(mut value: T) -> (Self, T::Norm) { let n = value.norm(); - value.unscale_mut(n); + value.unscale_mut(n.clone()); (Unit { value }, n) } @@ -184,9 +184,9 @@ impl Unit { { let sq_norm = value.norm_squared(); - if sq_norm > min_norm * min_norm { + if sq_norm > min_norm.clone() * min_norm { let n = sq_norm.simd_sqrt(); - value.unscale_mut(n); + value.unscale_mut(n.clone()); Some((Unit { value }, n)) } else { None @@ -201,7 +201,7 @@ impl Unit { #[inline] pub fn renormalize(&mut self) -> T::Norm { let n = self.norm(); - self.value.unscale_mut(n); + self.value.unscale_mut(n.clone()); n } diff --git a/src/geometry/dual_quaternion.rs b/src/geometry/dual_quaternion.rs index 6dd8936d..11ff46d4 100644 --- a/src/geometry/dual_quaternion.rs +++ b/src/geometry/dual_quaternion.rs @@ -87,7 +87,10 @@ where pub fn normalize(&self) -> Self { let real_norm = self.real.norm(); - Self::from_real_and_dual(self.real / real_norm, self.dual / real_norm) + Self::from_real_and_dual( + self.real.clone() / real_norm.clone(), + self.dual.clone() / real_norm, + ) } /// Normalizes this quaternion. @@ -107,8 +110,8 @@ where #[inline] pub fn normalize_mut(&mut self) -> T { let real_norm = self.real.norm(); - self.real /= real_norm; - self.dual /= real_norm; + self.real /= real_norm.clone(); + self.dual /= real_norm.clone(); real_norm } @@ -182,7 +185,7 @@ where where T: RealField, { - let mut res = *self; + let mut res = self.clone(); if res.try_inverse_mut() { Some(res) } else { @@ -216,7 +219,7 @@ where { let inverted = self.real.try_inverse_mut(); if inverted { - self.dual = -self.real * self.dual * self.real; + self.dual = -self.real.clone() * self.dual.clone() * self.real.clone(); true } else { false @@ -246,7 +249,7 @@ where #[inline] #[must_use] pub fn lerp(&self, other: &Self, t: T) -> Self { - self * (T::one() - t) + other * t + self * (T::one() - t.clone()) + other * t } } @@ -293,15 +296,15 @@ where let dq: Dq = Dq::::deserialize(deserializer)?; Ok(Self { - real: Quaternion::new(dq[3], dq[0], dq[1], dq[2]), - dual: Quaternion::new(dq[7], dq[4], dq[5], dq[6]), + real: Quaternion::new(dq[3].clone(), dq[0].clone(), dq[1].clone(), dq[2].clone()), + dual: Quaternion::new(dq[7].clone(), dq[4].clone(), dq[5].clone(), dq[6].clone()), }) } } impl DualQuaternion { fn to_vector(self) -> OVector { - (*self.as_ref()).into() + self.as_ref().clone().into() } } @@ -315,9 +318,9 @@ impl> AbsDiffEq for DualQuaternion { #[inline] fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool { - self.to_vector().abs_diff_eq(&other.to_vector(), epsilon) || + self.clone().to_vector().abs_diff_eq(&other.clone().to_vector(), epsilon.clone()) || // Account for the double-covering of S², i.e. q = -q - self.to_vector().iter().zip(other.to_vector().iter()).all(|(a, b)| a.abs_diff_eq(&-*b, epsilon)) + self.clone().to_vector().iter().zip(other.clone().to_vector().iter()).all(|(a, b)| a.abs_diff_eq(&-b.clone(), epsilon.clone())) } } @@ -334,9 +337,9 @@ impl> RelativeEq for DualQuaternion { epsilon: Self::Epsilon, max_relative: Self::Epsilon, ) -> bool { - self.to_vector().relative_eq(&other.to_vector(), epsilon, max_relative) || + self.clone().to_vector().relative_eq(&other.clone().to_vector(), epsilon.clone(), max_relative.clone()) || // Account for the double-covering of S², i.e. q = -q - self.to_vector().iter().zip(other.to_vector().iter()).all(|(a, b)| a.relative_eq(&-*b, epsilon, max_relative)) + self.clone().to_vector().iter().zip(other.clone().to_vector().iter()).all(|(a, b)| a.relative_eq(&-b.clone(), epsilon.clone(), max_relative.clone())) } } @@ -348,9 +351,9 @@ impl> UlpsEq for DualQuaternion { #[inline] fn ulps_eq(&self, other: &Self, epsilon: Self::Epsilon, max_ulps: u32) -> bool { - self.to_vector().ulps_eq(&other.to_vector(), epsilon, max_ulps) || + self.clone().to_vector().ulps_eq(&other.clone().to_vector(), epsilon.clone(), max_ulps.clone()) || // Account for the double-covering of S², i.e. q = -q. - self.to_vector().iter().zip(other.to_vector().iter()).all(|(a, b)| a.ulps_eq(&-*b, epsilon, max_ulps)) + self.clone().to_vector().iter().zip(other.clone().to_vector().iter()).all(|(a, b)| a.ulps_eq(&-b.clone(), epsilon.clone(), max_ulps.clone())) } } @@ -381,13 +384,13 @@ impl Normed for DualQuaternion { #[inline] fn scale_mut(&mut self, n: Self::Norm) { - self.real.scale_mut(n); + self.real.scale_mut(n.clone()); self.dual.scale_mut(n); } #[inline] fn unscale_mut(&mut self, n: Self::Norm) { - self.real.unscale_mut(n); + self.real.unscale_mut(n.clone()); self.dual.unscale_mut(n); } } @@ -471,10 +474,10 @@ where #[inline] #[must_use = "Did you mean to use inverse_mut()?"] pub fn inverse(&self) -> Self { - let real = Unit::new_unchecked(self.as_ref().real) + let real = Unit::new_unchecked(self.as_ref().real.clone()) .inverse() .into_inner(); - let dual = -real * self.as_ref().dual * real; + let dual = -real.clone() * self.as_ref().dual.clone() * real.clone(); UnitDualQuaternion::new_unchecked(DualQuaternion { real, dual }) } @@ -495,8 +498,10 @@ where #[inline] pub fn inverse_mut(&mut self) { let quat = self.as_mut_unchecked(); - quat.real = Unit::new_unchecked(quat.real).inverse().into_inner(); - quat.dual = -quat.real * quat.dual * quat.real; + quat.real = Unit::new_unchecked(quat.real.clone()) + .inverse() + .into_inner(); + quat.dual = -quat.real.clone() * quat.dual.clone() * quat.real.clone(); } /// The unit dual quaternion needed to make `self` and `other` coincide. @@ -639,16 +644,16 @@ where T: RealField, { let two = T::one() + T::one(); - let half = T::one() / two; + let half = T::one() / two.clone(); // Invert one of the quaternions if we've got a longest-path // interpolation. let other = { let dot_product = self.as_ref().real.coords.dot(&other.as_ref().real.coords); if dot_product < T::zero() { - -*other + -other.clone() } else { - *other + other.clone() } }; @@ -661,21 +666,21 @@ where let inverse_norm_squared = T::one() / norm_squared; let inverse_norm = inverse_norm_squared.sqrt(); - let mut angle = two * difference.real.scalar().acos(); - let mut pitch = -two * difference.dual.scalar() * inverse_norm; - let direction = difference.real.vector() * inverse_norm; + let mut angle = two.clone() * difference.real.scalar().acos(); + let mut pitch = -two * difference.dual.scalar() * inverse_norm.clone(); + let direction = difference.real.vector() * inverse_norm.clone(); let moment = (difference.dual.vector() - - direction * (pitch * difference.real.scalar() * half)) + - direction.clone() * (pitch.clone() * difference.real.scalar() * half.clone())) * inverse_norm; - angle *= t; + angle *= t.clone(); pitch *= t; - let sin = (half * angle).sin(); - let cos = (half * angle).cos(); - let real = Quaternion::from_parts(cos, direction * sin); + let sin = (half.clone() * angle.clone()).sin(); + let cos = (half.clone() * angle).cos(); + let real = Quaternion::from_parts(cos.clone(), direction.clone() * sin.clone()); let dual = Quaternion::from_parts( - -pitch * half * sin, + -pitch.clone() * half.clone() * sin.clone(), moment * sin + direction * (pitch * half * cos), ); @@ -703,7 +708,7 @@ where #[inline] #[must_use] pub fn rotation(&self) -> UnitQuaternion { - Unit::new_unchecked(self.as_ref().real) + Unit::new_unchecked(self.as_ref().real.clone()) } /// Return the translation part of this unit dual quaternion. @@ -725,7 +730,7 @@ where pub fn translation(&self) -> Translation3 { let two = T::one() + T::one(); Translation3::from( - ((self.as_ref().dual * self.as_ref().real.conjugate()) * two) + ((self.as_ref().dual.clone() * self.as_ref().real.clone().conjugate()) * two) .vector() .into_owned(), ) diff --git a/src/geometry/dual_quaternion_construction.rs b/src/geometry/dual_quaternion_construction.rs index ea4c7ee2..94bbc04f 100644 --- a/src/geometry/dual_quaternion_construction.rs +++ b/src/geometry/dual_quaternion_construction.rs @@ -186,7 +186,7 @@ where pub fn from_parts(translation: Translation3, rotation: UnitQuaternion) -> Self { let half: T = crate::convert(0.5f64); UnitDualQuaternion::new_unchecked(DualQuaternion { - real: rotation.into_inner(), + real: rotation.clone().into_inner(), dual: Quaternion::from_parts(T::zero(), translation.vector) * rotation.into_inner() * half, @@ -210,6 +210,8 @@ where /// ``` #[inline] pub fn from_isometry(isometry: &Isometry3) -> Self { + // TODO: take the isometry by-move instead of cloning it. + let isometry = isometry.clone(); UnitDualQuaternion::from_parts(isometry.translation, isometry.rotation) } diff --git a/src/geometry/dual_quaternion_conversion.rs b/src/geometry/dual_quaternion_conversion.rs index 94ef9e97..b8b00f09 100644 --- a/src/geometry/dual_quaternion_conversion.rs +++ b/src/geometry/dual_quaternion_conversion.rs @@ -122,7 +122,7 @@ where { #[inline] fn to_superset(&self) -> Transform { - Transform::from_matrix_unchecked(self.to_homogeneous().to_superset()) + Transform::from_matrix_unchecked(self.clone().to_homogeneous().to_superset()) } #[inline] @@ -141,7 +141,7 @@ impl> SubsetOf> { #[inline] fn to_superset(&self) -> Matrix4 { - self.to_homogeneous().to_superset() + self.clone().to_homogeneous().to_superset() } #[inline] diff --git a/src/geometry/dual_quaternion_ops.rs b/src/geometry/dual_quaternion_ops.rs index 2a1527ec..398fd0bf 100644 --- a/src/geometry/dual_quaternion_ops.rs +++ b/src/geometry/dual_quaternion_ops.rs @@ -417,7 +417,7 @@ dual_quaternion_op_impl!( (U4, U1), (U4, U1); self: &'a UnitDualQuaternion, rhs: &'b UnitQuaternion, Output = UnitDualQuaternion => U1, U4; - self * UnitDualQuaternion::::new_unchecked(DualQuaternion::from_real(rhs.into_inner())); + self * UnitDualQuaternion::::new_unchecked(DualQuaternion::from_real(rhs.clone().into_inner())); 'a, 'b); dual_quaternion_op_impl!( @@ -433,7 +433,7 @@ dual_quaternion_op_impl!( (U4, U1), (U4, U1); self: UnitDualQuaternion, rhs: &'b UnitQuaternion, Output = UnitDualQuaternion => U3, U3; - self * UnitDualQuaternion::::new_unchecked(DualQuaternion::from_real(rhs.into_inner())); + self * UnitDualQuaternion::::new_unchecked(DualQuaternion::from_real(rhs.clone().into_inner())); 'b); dual_quaternion_op_impl!( @@ -449,7 +449,7 @@ dual_quaternion_op_impl!( (U4, U1), (U4, U1); self: &'a UnitQuaternion, rhs: &'b UnitDualQuaternion, Output = UnitDualQuaternion => U1, U4; - UnitDualQuaternion::::new_unchecked(DualQuaternion::from_real(self.into_inner())) * rhs; + UnitDualQuaternion::::new_unchecked(DualQuaternion::from_real(self.clone().into_inner())) * rhs; 'a, 'b); dual_quaternion_op_impl!( @@ -457,7 +457,7 @@ dual_quaternion_op_impl!( (U4, U1), (U4, U1); self: &'a UnitQuaternion, rhs: UnitDualQuaternion, Output = UnitDualQuaternion => U3, U3; - UnitDualQuaternion::::new_unchecked(DualQuaternion::from_real(self.into_inner())) * rhs; + UnitDualQuaternion::::new_unchecked(DualQuaternion::from_real(self.clone().into_inner())) * rhs; 'a); dual_quaternion_op_impl!( @@ -520,7 +520,7 @@ dual_quaternion_op_impl!( #[allow(clippy::suspicious_arithmetic_impl)] { UnitDualQuaternion::::new_unchecked( - DualQuaternion::from_real(self.into_inner()) + DualQuaternion::from_real(self.clone().into_inner()) ) * rhs.inverse() }; 'a, 'b); @@ -532,7 +532,7 @@ dual_quaternion_op_impl!( #[allow(clippy::suspicious_arithmetic_impl)] { UnitDualQuaternion::::new_unchecked( - DualQuaternion::from_real(self.into_inner()) + DualQuaternion::from_real(self.clone().into_inner()) ) * rhs.inverse() }; 'a); @@ -566,7 +566,7 @@ dual_quaternion_op_impl!( (U4, U1), (U3, U1); self: &'a UnitDualQuaternion, rhs: &'b Translation3, Output = UnitDualQuaternion => U3, U1; - self * UnitDualQuaternion::::from_parts(*rhs, UnitQuaternion::identity()); + self * UnitDualQuaternion::::from_parts(rhs.clone(), UnitQuaternion::identity()); 'a, 'b); dual_quaternion_op_impl!( @@ -582,7 +582,7 @@ dual_quaternion_op_impl!( (U4, U1), (U3, U3); self: UnitDualQuaternion, rhs: &'b Translation3, Output = UnitDualQuaternion => U3, U1; - self * UnitDualQuaternion::::from_parts(*rhs, UnitQuaternion::identity()); + self * UnitDualQuaternion::::from_parts(rhs.clone(), UnitQuaternion::identity()); 'b); dual_quaternion_op_impl!( @@ -634,7 +634,7 @@ dual_quaternion_op_impl!( (U3, U1), (U4, U1); self: &'b Translation3, rhs: &'a UnitDualQuaternion, Output = UnitDualQuaternion => U3, U1; - UnitDualQuaternion::::from_parts(*self, UnitQuaternion::identity()) * rhs; + UnitDualQuaternion::::from_parts(self.clone(), UnitQuaternion::identity()) * rhs; 'a, 'b); dual_quaternion_op_impl!( @@ -642,7 +642,7 @@ dual_quaternion_op_impl!( (U3, U1), (U4, U1); self: &'a Translation3, rhs: UnitDualQuaternion, Output = UnitDualQuaternion => U3, U1; - UnitDualQuaternion::::from_parts(*self, UnitQuaternion::identity()) * rhs; + UnitDualQuaternion::::from_parts(self.clone(), UnitQuaternion::identity()) * rhs; 'a); dual_quaternion_op_impl!( @@ -666,7 +666,7 @@ dual_quaternion_op_impl!( (U3, U1), (U4, U1); self: &'b Translation3, rhs: &'a UnitDualQuaternion, Output = UnitDualQuaternion => U3, U1; - UnitDualQuaternion::::from_parts(*self, UnitQuaternion::identity()) / rhs; + UnitDualQuaternion::::from_parts(self.clone(), UnitQuaternion::identity()) / rhs; 'a, 'b); dual_quaternion_op_impl!( @@ -674,7 +674,7 @@ dual_quaternion_op_impl!( (U3, U1), (U4, U1); self: &'a Translation3, rhs: UnitDualQuaternion, Output = UnitDualQuaternion => U3, U1; - UnitDualQuaternion::::from_parts(*self, UnitQuaternion::identity()) / rhs; + UnitDualQuaternion::::from_parts(self.clone(), UnitQuaternion::identity()) / rhs; 'a); dual_quaternion_op_impl!( @@ -828,7 +828,7 @@ dual_quaternion_op_impl!( (U4, U1), (U3, U1) for SB: Storage ; self: &'a UnitDualQuaternion, rhs: &'b Vector, Output = Vector3 => U3, U1; - Unit::new_unchecked(self.as_ref().real) * rhs; + Unit::new_unchecked(self.as_ref().real.clone()) * rhs; 'a, 'b); dual_quaternion_op_impl!( @@ -862,9 +862,9 @@ dual_quaternion_op_impl!( Output = Point3 => U3, U1; { let two: T = crate::convert(2.0f64); - let q_point = Quaternion::from_parts(T::zero(), rhs.coords); + let q_point = Quaternion::from_parts(T::zero(), rhs.coords.clone()); Point::from( - ((self.as_ref().real * q_point + self.as_ref().dual * two) * self.as_ref().real.conjugate()) + ((self.as_ref().real.clone() * q_point + self.as_ref().dual.clone() * two) * self.as_ref().real.clone().conjugate()) .vector() .into_owned(), ) @@ -1117,7 +1117,7 @@ dual_quaternion_op_impl!( MulAssign, mul_assign; (U4, U1), (U4, U1); self: UnitDualQuaternion, rhs: &'b UnitQuaternion; - *self *= *rhs; 'b); + *self *= rhs.clone(); 'b); // UnitDualQuaternion ÷= UnitQuaternion dual_quaternion_op_impl!( @@ -1153,7 +1153,7 @@ dual_quaternion_op_impl!( MulAssign, mul_assign; (U4, U1), (U4, U1); self: UnitDualQuaternion, rhs: &'b Translation3; - *self *= *rhs; 'b); + *self *= rhs.clone(); 'b); // UnitDualQuaternion ÷= Translation3 dual_quaternion_op_impl!( @@ -1219,8 +1219,8 @@ macro_rules! scalar_op_impl( #[inline] fn $op(self, n: T) -> Self::Output { DualQuaternion::from_real_and_dual( - self.real.$op(n), - self.dual.$op(n) + self.real.clone().$op(n.clone()), + self.dual.clone().$op(n) ) } } @@ -1232,8 +1232,8 @@ macro_rules! scalar_op_impl( #[inline] fn $op(self, n: T) -> Self::Output { DualQuaternion::from_real_and_dual( - self.real.$op(n), - self.dual.$op(n) + self.real.clone().$op(n.clone()), + self.dual.clone().$op(n) ) } } @@ -1243,7 +1243,7 @@ macro_rules! scalar_op_impl( #[inline] fn $op_assign(&mut self, n: T) { - self.real.$op_assign(n); + self.real.$op_assign(n.clone()); self.dual.$op_assign(n); } } diff --git a/src/geometry/isometry.rs b/src/geometry/isometry.rs index f8e63d07..4492c6c1 100755 --- a/src/geometry/isometry.rs +++ b/src/geometry/isometry.rs @@ -272,7 +272,7 @@ where #[must_use] pub fn inv_mul(&self, rhs: &Isometry) -> Self { let inv_rot1 = self.rotation.inverse(); - let tr_12 = rhs.translation.vector - self.translation.vector; + let tr_12 = &rhs.translation.vector - &self.translation.vector; Isometry::from_parts( inv_rot1.transform_vector(&tr_12).into(), inv_rot1 * rhs.rotation.clone(), @@ -437,7 +437,7 @@ where #[must_use] pub fn inverse_transform_point(&self, pt: &Point) -> Point { 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 @@ -574,7 +574,7 @@ where impl AbsDiffEq for Isometry where R: AbstractRotation + AbsDiffEq, - T::Epsilon: Copy, + T::Epsilon: Clone, { type Epsilon = T::Epsilon; @@ -585,7 +585,8 @@ where #[inline] fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool { - self.translation.abs_diff_eq(&other.translation, epsilon) + self.translation + .abs_diff_eq(&other.translation, epsilon.clone()) && self.rotation.abs_diff_eq(&other.rotation, epsilon) } } @@ -593,7 +594,7 @@ where impl RelativeEq for Isometry where R: AbstractRotation + RelativeEq, - T::Epsilon: Copy, + T::Epsilon: Clone, { #[inline] fn default_max_relative() -> Self::Epsilon { @@ -608,7 +609,7 @@ where max_relative: Self::Epsilon, ) -> bool { self.translation - .relative_eq(&other.translation, epsilon, max_relative) + .relative_eq(&other.translation, epsilon.clone(), max_relative.clone()) && self .rotation .relative_eq(&other.rotation, epsilon, max_relative) @@ -618,7 +619,7 @@ where impl UlpsEq for Isometry where R: AbstractRotation + UlpsEq, - T::Epsilon: Copy, + T::Epsilon: Clone, { #[inline] fn default_max_ulps() -> u32 { @@ -628,7 +629,7 @@ where #[inline] fn ulps_eq(&self, other: &Self, epsilon: Self::Epsilon, max_ulps: u32) -> bool { self.translation - .ulps_eq(&other.translation, epsilon, max_ulps) + .ulps_eq(&other.translation, epsilon.clone(), max_ulps.clone()) && self.rotation.ulps_eq(&other.rotation, epsilon, max_ulps) } } diff --git a/src/geometry/isometry_interpolation.rs b/src/geometry/isometry_interpolation.rs index 356dbdad..90f2c7ae 100644 --- a/src/geometry/isometry_interpolation.rs +++ b/src/geometry/isometry_interpolation.rs @@ -31,7 +31,10 @@ impl Isometry3 { where T: RealField, { - let tr = self.translation.vector.lerp(&other.translation.vector, t); + let tr = self + .translation + .vector + .lerp(&other.translation.vector, t.clone()); let rot = self.rotation.slerp(&other.rotation, t); Self::from_parts(tr.into(), rot) } @@ -65,7 +68,10 @@ impl Isometry3 { where T: RealField, { - let tr = self.translation.vector.lerp(&other.translation.vector, t); + let tr = self + .translation + .vector + .lerp(&other.translation.vector, t.clone()); let rot = self.rotation.try_slerp(&other.rotation, t, epsilon)?; Some(Self::from_parts(tr.into(), rot)) } @@ -101,7 +107,10 @@ impl IsometryMatrix3 { where T: RealField, { - let tr = self.translation.vector.lerp(&other.translation.vector, t); + let tr = self + .translation + .vector + .lerp(&other.translation.vector, t.clone()); let rot = self.rotation.slerp(&other.rotation, t); Self::from_parts(tr.into(), rot) } @@ -135,7 +144,10 @@ impl IsometryMatrix3 { where T: RealField, { - let tr = self.translation.vector.lerp(&other.translation.vector, t); + let tr = self + .translation + .vector + .lerp(&other.translation.vector, t.clone()); let rot = self.rotation.try_slerp(&other.rotation, t, epsilon)?; Some(Self::from_parts(tr.into(), rot)) } @@ -172,7 +184,10 @@ impl Isometry2 { where T: RealField, { - let tr = self.translation.vector.lerp(&other.translation.vector, t); + let tr = self + .translation + .vector + .lerp(&other.translation.vector, t.clone()); let rot = self.rotation.slerp(&other.rotation, t); Self::from_parts(tr.into(), rot) } @@ -209,7 +224,10 @@ impl IsometryMatrix2 { where T: RealField, { - let tr = self.translation.vector.lerp(&other.translation.vector, t); + let tr = self + .translation + .vector + .lerp(&other.translation.vector, t.clone()); let rot = self.rotation.slerp(&other.rotation, t); Self::from_parts(tr.into(), rot) } diff --git a/src/geometry/isometry_ops.rs b/src/geometry/isometry_ops.rs index 5cf5ec35..074ac025 100644 --- a/src/geometry/isometry_ops.rs +++ b/src/geometry/isometry_ops.rs @@ -201,7 +201,7 @@ md_assign_impl_all!( const D; for; where; self: Isometry, D>, rhs: Rotation; [val] => self.rotation *= rhs; - [ref] => self.rotation *= *rhs; + [ref] => self.rotation *= rhs.clone(); ); md_assign_impl_all!( @@ -220,7 +220,7 @@ md_assign_impl_all!( const; for; where; self: Isometry, 3>, rhs: UnitQuaternion; [val] => self.rotation *= rhs; - [ref] => self.rotation *= *rhs; + [ref] => self.rotation *= rhs.clone(); ); md_assign_impl_all!( @@ -239,7 +239,7 @@ md_assign_impl_all!( const; for; where; self: Isometry, 2>, rhs: UnitComplex; [val] => self.rotation *= rhs; - [ref] => self.rotation *= *rhs; + [ref] => self.rotation *= rhs.clone(); ); md_assign_impl_all!( @@ -368,9 +368,9 @@ isometry_from_composition_impl_all!( D; self: Rotation, right: Translation, Output = Isometry, D>; [val val] => Isometry::from_parts(Translation::from(&self * right.vector), self); - [ref val] => Isometry::from_parts(Translation::from(self * right.vector), *self); + [ref val] => Isometry::from_parts(Translation::from(self * right.vector), self.clone()); [val ref] => Isometry::from_parts(Translation::from(&self * &right.vector), self); - [ref ref] => Isometry::from_parts(Translation::from(self * &right.vector), *self); + [ref ref] => Isometry::from_parts(Translation::from(self * &right.vector), self.clone()); ); // UnitQuaternion × Translation @@ -380,9 +380,9 @@ isometry_from_composition_impl_all!( self: UnitQuaternion, right: Translation, Output = Isometry, 3>; [val val] => Isometry::from_parts(Translation::from(&self * right.vector), self); - [ref val] => Isometry::from_parts(Translation::from( self * right.vector), *self); + [ref val] => Isometry::from_parts(Translation::from( self * right.vector), self.clone()); [val ref] => Isometry::from_parts(Translation::from(&self * &right.vector), self); - [ref ref] => Isometry::from_parts(Translation::from( self * &right.vector), *self); + [ref ref] => Isometry::from_parts(Translation::from( self * &right.vector), self.clone()); ); // Isometry × Rotation @@ -392,9 +392,9 @@ isometry_from_composition_impl_all!( self: Isometry, D>, rhs: Rotation, Output = Isometry, D>; [val val] => Isometry::from_parts(self.translation, self.rotation * rhs); - [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); + [ref val] => Isometry::from_parts(self.translation.clone(), self.rotation.clone() * rhs); + [val ref] => Isometry::from_parts(self.translation, self.rotation * rhs.clone()); + [ref ref] => Isometry::from_parts(self.translation.clone(), self.rotation.clone() * rhs.clone()); ); // Rotation × Isometry @@ -419,9 +419,9 @@ isometry_from_composition_impl_all!( self: Isometry, D>, rhs: Rotation, Output = Isometry, D>; [val val] => Isometry::from_parts(self.translation, self.rotation / rhs); - [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); + [ref val] => Isometry::from_parts(self.translation.clone(), self.rotation.clone() / rhs); + [val ref] => Isometry::from_parts(self.translation, self.rotation / rhs.clone()); + [ref ref] => Isometry::from_parts(self.translation.clone(), self.rotation.clone() / rhs.clone()); ); // Rotation ÷ Isometry @@ -444,9 +444,9 @@ isometry_from_composition_impl_all!( self: Isometry, 3>, rhs: UnitQuaternion, Output = Isometry, 3>; [val val] => Isometry::from_parts(self.translation, self.rotation * rhs); - [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); + [ref val] => Isometry::from_parts(self.translation.clone(), self.rotation.clone() * rhs); + [val ref] => Isometry::from_parts(self.translation, self.rotation * rhs.clone()); + [ref ref] => Isometry::from_parts(self.translation.clone(), self.rotation.clone() * rhs.clone()); ); // UnitQuaternion × Isometry @@ -471,9 +471,9 @@ isometry_from_composition_impl_all!( self: Isometry, 3>, rhs: UnitQuaternion, Output = Isometry, 3>; [val val] => Isometry::from_parts(self.translation, self.rotation / rhs); - [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); + [ref val] => Isometry::from_parts(self.translation.clone(), self.rotation.clone() / rhs); + [val ref] => Isometry::from_parts(self.translation, self.rotation / rhs.clone()); + [ref ref] => Isometry::from_parts(self.translation.clone(), self.rotation.clone() / rhs.clone()); ); // UnitQuaternion ÷ Isometry @@ -495,9 +495,9 @@ isometry_from_composition_impl_all!( D; self: Translation, right: Rotation, Output = Isometry, D>; [val val] => Isometry::from_parts(self, right); - [ref val] => Isometry::from_parts(*self, right); - [val ref] => Isometry::from_parts(self, *right); - [ref ref] => 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()); ); // Translation × UnitQuaternion @@ -506,9 +506,9 @@ isometry_from_composition_impl_all!( ; self: Translation, right: UnitQuaternion, Output = Isometry, 3>; [val val] => Isometry::from_parts(self, right); - [ref val] => Isometry::from_parts(*self, right); - [val ref] => Isometry::from_parts(self, *right); - [ref ref] => 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()); ); // Isometry × UnitComplex @@ -518,9 +518,9 @@ isometry_from_composition_impl_all!( self: Isometry, 2>, rhs: UnitComplex, Output = Isometry, 2>; [val val] => Isometry::from_parts(self.translation, self.rotation * rhs); - [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); + [ref val] => Isometry::from_parts(self.translation.clone(), self.rotation.clone() * rhs); + [val ref] => Isometry::from_parts(self.translation, self.rotation * rhs.clone()); + [ref ref] => Isometry::from_parts(self.translation.clone(), self.rotation.clone() * rhs.clone()); ); // Isometry ÷ UnitComplex @@ -530,7 +530,7 @@ isometry_from_composition_impl_all!( self: Isometry, 2>, rhs: UnitComplex, Output = Isometry, 2>; [val val] => Isometry::from_parts(self.translation, self.rotation / rhs); - [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); + [ref val] => Isometry::from_parts(self.translation.clone(), self.rotation.clone() / rhs); + [val ref] => Isometry::from_parts(self.translation, self.rotation / rhs.clone()); + [ref ref] => Isometry::from_parts(self.translation.clone(), self.rotation.clone() / rhs.clone()); ); diff --git a/src/geometry/orthographic.rs b/src/geometry/orthographic.rs index b349a621..731b46a1 100644 --- a/src/geometry/orthographic.rs +++ b/src/geometry/orthographic.rs @@ -23,12 +23,12 @@ pub struct Orthographic3 { matrix: Matrix4, } -impl Copy for Orthographic3 {} +impl Copy for Orthographic3 {} impl Clone for Orthographic3 { #[inline] fn clone(&self) -> Self { - Self::from_matrix_unchecked(self.matrix) + Self::from_matrix_unchecked(self.matrix.clone()) } } @@ -175,13 +175,13 @@ impl Orthographic3 { ); let half: T = crate::convert(0.5); - let width = zfar * (vfov * half).tan(); - let height = width / aspect; + let width = zfar.clone() * (vfov.clone() * half.clone()).tan(); + let height = width.clone() / aspect; Self::new( - -width * half, - width * half, - -height * half, + -width.clone() * half.clone(), + width * half.clone(), + -height.clone() * half.clone(), height * half, znear, zfar, @@ -208,19 +208,19 @@ impl Orthographic3 { #[inline] #[must_use] pub fn inverse(&self) -> Matrix4 { - let mut res = self.to_homogeneous(); + let mut res = self.clone().to_homogeneous(); - let inv_m11 = T::one() / self.matrix[(0, 0)]; - let inv_m22 = T::one() / self.matrix[(1, 1)]; - let inv_m33 = T::one() / self.matrix[(2, 2)]; + let inv_m11 = T::one() / self.matrix[(0, 0)].clone(); + let inv_m22 = T::one() / self.matrix[(1, 1)].clone(); + let inv_m33 = T::one() / self.matrix[(2, 2)].clone(); - res[(0, 0)] = inv_m11; - res[(1, 1)] = inv_m22; - res[(2, 2)] = inv_m33; + res[(0, 0)] = inv_m11.clone(); + res[(1, 1)] = inv_m22.clone(); + res[(2, 2)] = inv_m33.clone(); - res[(0, 3)] = -self.matrix[(0, 3)] * inv_m11; - res[(1, 3)] = -self.matrix[(1, 3)] * inv_m22; - res[(2, 3)] = -self.matrix[(2, 3)] * inv_m33; + res[(0, 3)] = -self.matrix[(0, 3)].clone() * inv_m11; + res[(1, 3)] = -self.matrix[(1, 3)].clone() * inv_m22; + res[(2, 3)] = -self.matrix[(2, 3)].clone() * inv_m33; res } @@ -335,7 +335,7 @@ impl Orthographic3 { #[inline] #[must_use] pub fn left(&self) -> T { - (-T::one() - self.matrix[(0, 3)]) / self.matrix[(0, 0)] + (-T::one() - self.matrix[(0, 3)].clone()) / self.matrix[(0, 0)].clone() } /// The right offset of the view cuboid. @@ -352,7 +352,7 @@ impl Orthographic3 { #[inline] #[must_use] pub fn right(&self) -> T { - (T::one() - self.matrix[(0, 3)]) / self.matrix[(0, 0)] + (T::one() - self.matrix[(0, 3)].clone()) / self.matrix[(0, 0)].clone() } /// The bottom offset of the view cuboid. @@ -369,7 +369,7 @@ impl Orthographic3 { #[inline] #[must_use] pub fn bottom(&self) -> T { - (-T::one() - self.matrix[(1, 3)]) / self.matrix[(1, 1)] + (-T::one() - self.matrix[(1, 3)].clone()) / self.matrix[(1, 1)].clone() } /// The top offset of the view cuboid. @@ -386,7 +386,7 @@ impl Orthographic3 { #[inline] #[must_use] pub fn top(&self) -> T { - (T::one() - self.matrix[(1, 3)]) / self.matrix[(1, 1)] + (T::one() - self.matrix[(1, 3)].clone()) / self.matrix[(1, 1)].clone() } /// The near plane offset of the view cuboid. @@ -403,7 +403,7 @@ impl Orthographic3 { #[inline] #[must_use] pub fn znear(&self) -> T { - (T::one() + self.matrix[(2, 3)]) / self.matrix[(2, 2)] + (T::one() + self.matrix[(2, 3)].clone()) / self.matrix[(2, 2)].clone() } /// The far plane offset of the view cuboid. @@ -420,7 +420,7 @@ impl Orthographic3 { #[inline] #[must_use] pub fn zfar(&self) -> T { - (-T::one() + self.matrix[(2, 3)]) / self.matrix[(2, 2)] + (-T::one() + self.matrix[(2, 3)].clone()) / self.matrix[(2, 2)].clone() } // TODO: when we get specialization, specialize the Mul impl instead. @@ -454,9 +454,9 @@ impl Orthographic3 { #[must_use] pub fn project_point(&self, p: &Point3) -> Point3 { Point3::new( - self.matrix[(0, 0)] * p[0] + self.matrix[(0, 3)], - self.matrix[(1, 1)] * p[1] + self.matrix[(1, 3)], - self.matrix[(2, 2)] * p[2] + self.matrix[(2, 3)], + self.matrix[(0, 0)].clone() * p[0].clone() + self.matrix[(0, 3)].clone(), + self.matrix[(1, 1)].clone() * p[1].clone() + self.matrix[(1, 3)].clone(), + self.matrix[(2, 2)].clone() * p[2].clone() + self.matrix[(2, 3)].clone(), ) } @@ -490,9 +490,9 @@ impl Orthographic3 { #[must_use] pub fn unproject_point(&self, p: &Point3) -> Point3 { Point3::new( - (p[0] - self.matrix[(0, 3)]) / self.matrix[(0, 0)], - (p[1] - self.matrix[(1, 3)]) / self.matrix[(1, 1)], - (p[2] - self.matrix[(2, 3)]) / self.matrix[(2, 2)], + (p[0].clone() - self.matrix[(0, 3)].clone()) / self.matrix[(0, 0)].clone(), + (p[1].clone() - self.matrix[(1, 3)].clone()) / self.matrix[(1, 1)].clone(), + (p[2].clone() - self.matrix[(2, 3)].clone()) / self.matrix[(2, 2)].clone(), ) } @@ -522,9 +522,9 @@ impl Orthographic3 { SB: Storage, { Vector3::new( - self.matrix[(0, 0)] * p[0], - self.matrix[(1, 1)] * p[1], - self.matrix[(2, 2)] * p[2], + self.matrix[(0, 0)].clone() * p[0].clone(), + self.matrix[(1, 1)].clone() * p[1].clone(), + self.matrix[(2, 2)].clone() * p[2].clone(), ) } @@ -663,8 +663,8 @@ impl Orthographic3 { left != right, "The left corner must not be equal to the right corner." ); - self.matrix[(0, 0)] = crate::convert::<_, T>(2.0) / (right - left); - self.matrix[(0, 3)] = -(right + left) / (right - left); + self.matrix[(0, 0)] = crate::convert::<_, T>(2.0) / (right.clone() - left.clone()); + self.matrix[(0, 3)] = -(right.clone() + left.clone()) / (right - left); } /// Sets the view cuboid offsets along the `y` axis. @@ -684,12 +684,12 @@ impl Orthographic3 { /// ``` #[inline] pub fn set_bottom_and_top(&mut self, bottom: T, top: T) { - assert!( - bottom != top, + assert_ne!( + bottom, top, "The top corner must not be equal to the bottom corner." ); - self.matrix[(1, 1)] = crate::convert::<_, T>(2.0) / (top - bottom); - self.matrix[(1, 3)] = -(top + bottom) / (top - bottom); + self.matrix[(1, 1)] = crate::convert::<_, T>(2.0) / (top.clone() - bottom.clone()); + self.matrix[(1, 3)] = -(top.clone() + bottom.clone()) / (top - bottom); } /// Sets the near and far plane offsets of the view cuboid. @@ -713,8 +713,8 @@ impl Orthographic3 { zfar != znear, "The near-plane and far-plane must not be superimposed." ); - self.matrix[(2, 2)] = -crate::convert::<_, T>(2.0) / (zfar - znear); - self.matrix[(2, 3)] = -(zfar + znear) / (zfar - znear); + self.matrix[(2, 2)] = -crate::convert::<_, T>(2.0) / (zfar.clone() - znear.clone()); + self.matrix[(2, 3)] = -(zfar.clone() + znear.clone()) / (zfar - znear); } } diff --git a/src/geometry/perspective.rs b/src/geometry/perspective.rs index d5a6fe42..34af6f0b 100644 --- a/src/geometry/perspective.rs +++ b/src/geometry/perspective.rs @@ -24,12 +24,12 @@ pub struct Perspective3 { matrix: Matrix4, } -impl Copy for Perspective3 {} +impl Copy for Perspective3 {} impl Clone for Perspective3 { #[inline] fn clone(&self) -> Self { - Self::from_matrix_unchecked(self.matrix) + Self::from_matrix_unchecked(self.matrix.clone()) } } @@ -99,7 +99,7 @@ impl Perspective3 { /// Creates a new perspective matrix from the aspect ratio, y field of view, and near/far planes. pub fn new(aspect: T, fovy: T, znear: T, zfar: T) -> Self { assert!( - !relative_eq!(zfar - znear, T::zero()), + relative_ne!(zfar, znear), "The near-plane and far-plane must not be superimposed." ); assert!( @@ -124,18 +124,18 @@ impl Perspective3 { #[inline] #[must_use] pub fn inverse(&self) -> Matrix4 { - let mut res = self.to_homogeneous(); + let mut res = self.clone().to_homogeneous(); - res[(0, 0)] = T::one() / self.matrix[(0, 0)]; - res[(1, 1)] = T::one() / self.matrix[(1, 1)]; + res[(0, 0)] = T::one() / self.matrix[(0, 0)].clone(); + res[(1, 1)] = T::one() / self.matrix[(1, 1)].clone(); res[(2, 2)] = T::zero(); - let m23 = self.matrix[(2, 3)]; - let m32 = self.matrix[(3, 2)]; + let m23 = self.matrix[(2, 3)].clone(); + let m32 = self.matrix[(3, 2)].clone(); - res[(2, 3)] = T::one() / m32; - res[(3, 2)] = T::one() / m23; - res[(3, 3)] = -self.matrix[(2, 2)] / (m23 * m32); + res[(2, 3)] = T::one() / m32.clone(); + res[(3, 2)] = T::one() / m23.clone(); + res[(3, 3)] = -self.matrix[(2, 2)].clone() / (m23 * m32); res } @@ -186,33 +186,35 @@ impl Perspective3 { #[inline] #[must_use] pub fn aspect(&self) -> T { - self.matrix[(1, 1)] / self.matrix[(0, 0)] + self.matrix[(1, 1)].clone() / self.matrix[(0, 0)].clone() } /// Gets the y field of view of the view frustum. #[inline] #[must_use] pub fn fovy(&self) -> T { - (T::one() / self.matrix[(1, 1)]).atan() * crate::convert(2.0) + (T::one() / self.matrix[(1, 1)].clone()).atan() * crate::convert(2.0) } /// Gets the near plane offset of the view frustum. #[inline] #[must_use] pub fn znear(&self) -> T { - let ratio = (-self.matrix[(2, 2)] + T::one()) / (-self.matrix[(2, 2)] - T::one()); + let ratio = + (-self.matrix[(2, 2)].clone() + T::one()) / (-self.matrix[(2, 2)].clone() - T::one()); - self.matrix[(2, 3)] / (ratio * crate::convert(2.0)) - - self.matrix[(2, 3)] / crate::convert(2.0) + self.matrix[(2, 3)].clone() / (ratio * crate::convert(2.0)) + - self.matrix[(2, 3)].clone() / crate::convert(2.0) } /// Gets the far plane offset of the view frustum. #[inline] #[must_use] pub fn zfar(&self) -> T { - let ratio = (-self.matrix[(2, 2)] + T::one()) / (-self.matrix[(2, 2)] - T::one()); + let ratio = + (-self.matrix[(2, 2)].clone() + T::one()) / (-self.matrix[(2, 2)].clone() - T::one()); - (self.matrix[(2, 3)] - ratio * self.matrix[(2, 3)]) / crate::convert(2.0) + (self.matrix[(2, 3)].clone() - ratio * self.matrix[(2, 3)].clone()) / crate::convert(2.0) } // TODO: add a method to retrieve znear and zfar simultaneously? @@ -222,11 +224,12 @@ impl Perspective3 { #[inline] #[must_use] pub fn project_point(&self, p: &Point3) -> Point3 { - let inverse_denom = -T::one() / p[2]; + let inverse_denom = -T::one() / p[2].clone(); Point3::new( - self.matrix[(0, 0)] * p[0] * inverse_denom, - self.matrix[(1, 1)] * p[1] * inverse_denom, - (self.matrix[(2, 2)] * p[2] + self.matrix[(2, 3)]) * inverse_denom, + self.matrix[(0, 0)].clone() * p[0].clone() * inverse_denom.clone(), + self.matrix[(1, 1)].clone() * p[1].clone() * inverse_denom.clone(), + (self.matrix[(2, 2)].clone() * p[2].clone() + self.matrix[(2, 3)].clone()) + * inverse_denom, ) } @@ -234,11 +237,12 @@ impl Perspective3 { #[inline] #[must_use] pub fn unproject_point(&self, p: &Point3) -> Point3 { - let inverse_denom = self.matrix[(2, 3)] / (p[2] + self.matrix[(2, 2)]); + let inverse_denom = + self.matrix[(2, 3)].clone() / (p[2].clone() + self.matrix[(2, 2)].clone()); Point3::new( - p[0] * inverse_denom / self.matrix[(0, 0)], - p[1] * inverse_denom / self.matrix[(1, 1)], + p[0].clone() * inverse_denom.clone() / self.matrix[(0, 0)].clone(), + p[1].clone() * inverse_denom.clone() / self.matrix[(1, 1)].clone(), -inverse_denom, ) } @@ -251,11 +255,11 @@ impl Perspective3 { where SB: Storage, { - let inverse_denom = -T::one() / p[2]; + let inverse_denom = -T::one() / p[2].clone(); Vector3::new( - self.matrix[(0, 0)] * p[0] * inverse_denom, - self.matrix[(1, 1)] * p[1] * inverse_denom, - self.matrix[(2, 2)], + self.matrix[(0, 0)].clone() * p[0].clone() * inverse_denom.clone(), + self.matrix[(1, 1)].clone() * p[1].clone() * inverse_denom, + self.matrix[(2, 2)].clone(), ) } @@ -267,15 +271,15 @@ impl Perspective3 { !relative_eq!(aspect, T::zero()), "The aspect ratio must not be zero." ); - self.matrix[(0, 0)] = self.matrix[(1, 1)] / aspect; + self.matrix[(0, 0)] = self.matrix[(1, 1)].clone() / aspect; } /// Updates this perspective with a new y field of view of the view frustum. #[inline] pub fn set_fovy(&mut self, fovy: T) { - let old_m22 = self.matrix[(1, 1)]; + let old_m22 = self.matrix[(1, 1)].clone(); let new_m22 = T::one() / (fovy / crate::convert(2.0)).tan(); - self.matrix[(1, 1)] = new_m22; + self.matrix[(1, 1)] = new_m22.clone(); self.matrix[(0, 0)] *= new_m22 / old_m22; } @@ -296,8 +300,8 @@ impl Perspective3 { /// Updates this perspective matrix with new near and far plane offsets of the view frustum. #[inline] pub fn set_znear_and_zfar(&mut self, znear: T, zfar: T) { - self.matrix[(2, 2)] = (zfar + znear) / (znear - zfar); - self.matrix[(2, 3)] = zfar * znear * crate::convert(2.0) / (znear - zfar); + self.matrix[(2, 2)] = (zfar.clone() + znear.clone()) / (znear.clone() - zfar.clone()); + self.matrix[(2, 3)] = zfar.clone() * znear.clone() * crate::convert(2.0) / (znear - zfar); } } @@ -310,8 +314,8 @@ where fn sample(&self, r: &mut R) -> Perspective3 { use crate::base::helper; let znear = r.gen(); - let zfar = helper::reject_rand(r, |&x: &T| !(x - znear).is_zero()); - let aspect = helper::reject_rand(r, |&x: &T| !x.is_zero()); + let zfar = helper::reject_rand(r, |x: &T| !(x.clone() - znear.clone()).is_zero()); + let aspect = helper::reject_rand(r, |x: &T| !x.is_zero()); Perspective3::new(aspect, r.gen(), znear, zfar) } @@ -321,9 +325,9 @@ where impl Arbitrary for Perspective3 { fn arbitrary(g: &mut Gen) -> Self { use crate::base::helper; - let znear = Arbitrary::arbitrary(g); - let zfar = helper::reject(g, |&x: &T| !(x - znear).is_zero()); - let aspect = helper::reject(g, |&x: &T| !x.is_zero()); + let znear: T = Arbitrary::arbitrary(g); + let zfar = helper::reject(g, |x: &T| !(x.clone() - znear.clone()).is_zero()); + let aspect = helper::reject(g, |x: &T| !x.is_zero()); Self::new(aspect, Arbitrary::arbitrary(g), znear, zfar) } diff --git a/src/geometry/point.rs b/src/geometry/point.rs index 098b5c2a..69022671 100644 --- a/src/geometry/point.rs +++ b/src/geometry/point.rs @@ -323,7 +323,7 @@ where impl AbsDiffEq for OPoint where - T::Epsilon: Copy, + T::Epsilon: Clone, DefaultAllocator: Allocator, { type Epsilon = T::Epsilon; @@ -341,7 +341,7 @@ where impl RelativeEq for OPoint where - T::Epsilon: Copy, + T::Epsilon: Clone, DefaultAllocator: Allocator, { #[inline] @@ -363,7 +363,7 @@ where impl UlpsEq for OPoint where - T::Epsilon: Copy, + T::Epsilon: Clone, DefaultAllocator: Allocator, { #[inline] diff --git a/src/geometry/point_construction.rs b/src/geometry/point_construction.rs index d2393146..e4e729aa 100644 --- a/src/geometry/point_construction.rs +++ b/src/geometry/point_construction.rs @@ -104,8 +104,7 @@ where DefaultAllocator: Allocator>, { if !v[D::dim()].is_zero() { - let coords = - v.generic_slice((0, 0), (D::name(), Const::<1>)) / v[D::dim()].inlined_clone(); + let coords = v.generic_slice((0, 0), (D::name(), Const::<1>)) / v[D::dim()].clone(); Some(Self::from(coords)) } else { None diff --git a/src/geometry/point_conversion.rs b/src/geometry/point_conversion.rs index f35a9fc6..ce1bd930 100644 --- a/src/geometry/point_conversion.rs +++ b/src/geometry/point_conversion.rs @@ -66,7 +66,7 @@ where #[inline] fn from_superset_unchecked(v: &OVector>) -> Self { - let coords = v.generic_slice((0, 0), (D::name(), Const::<1>)) / v[D::dim()].inlined_clone(); + let coords = v.generic_slice((0, 0), (D::name(), Const::<1>)) / v[D::dim()].clone(); Self { coords: crate::convert_unchecked(coords), } diff --git a/src/geometry/quaternion.rs b/src/geometry/quaternion.rs index cd248c94..0c2c01c7 100755 --- a/src/geometry/quaternion.rs +++ b/src/geometry/quaternion.rs @@ -208,7 +208,7 @@ where #[inline] #[must_use = "Did you mean to use conjugate_mut()?"] pub fn conjugate(&self) -> Self { - Self::from_parts(self.w, -self.imag()) + Self::from_parts(self.w.clone(), -self.imag()) } /// Linear interpolation between two quaternion. @@ -226,7 +226,7 @@ where #[inline] #[must_use] pub fn lerp(&self, other: &Self, t: T) -> Self { - self * (T::one() - t) + other * t + self * (T::one() - t.clone()) + other * t } /// The vector part `(i, j, k)` of this quaternion. @@ -256,7 +256,7 @@ where #[inline] #[must_use] pub fn scalar(&self) -> T { - self.coords[3] + self.coords[3].clone() } /// Reinterprets this quaternion as a 4D vector. @@ -385,7 +385,7 @@ where where T: RealField, { - let mut res = *self; + let mut res = self.clone(); if res.try_inverse_mut() { Some(res) @@ -401,7 +401,7 @@ where #[must_use = "Did you mean to use try_inverse_mut()?"] pub fn simd_try_inverse(&self) -> SimdOption { let norm_squared = self.norm_squared(); - let ge = norm_squared.simd_ge(T::simd_default_epsilon()); + let ge = norm_squared.clone().simd_ge(T::simd_default_epsilon()); SimdOption::new(self.conjugate() / norm_squared, ge) } @@ -511,7 +511,7 @@ where where T: RealField, { - if let Some((q, n)) = Unit::try_new_and_get(*self, T::zero()) { + if let Some((q, n)) = Unit::try_new_and_get(self.clone(), T::zero()) { if let Some(axis) = Unit::try_new(self.vector().clone_owned(), T::zero()) { let angle = q.angle() / crate::convert(2.0f64); @@ -540,7 +540,7 @@ where let v = self.vector(); let s = self.scalar(); - Self::from_parts(n.simd_ln(), v.normalize() * (s / n).simd_acos()) + Self::from_parts(n.clone().simd_ln(), v.normalize() * (s / n).simd_acos()) } /// Compute the exponential of a quaternion. @@ -577,11 +577,11 @@ where pub fn exp_eps(&self, eps: T) -> Self { let v = self.vector(); let nn = v.norm_squared(); - let le = nn.simd_le(eps * eps); + let le = nn.clone().simd_le(eps.clone() * eps); le.if_else(Self::identity, || { let w_exp = self.scalar().simd_exp(); let n = nn.simd_sqrt(); - let nv = v * (w_exp * n.simd_sin() / n); + let nv = v * (w_exp.clone() * n.clone().simd_sin() / n.clone()); Self::from_parts(w_exp * n.simd_cos(), nv) }) @@ -648,9 +648,9 @@ where /// ``` #[inline] pub fn conjugate_mut(&mut self) { - self.coords[0] = -self.coords[0]; - self.coords[1] = -self.coords[1]; - self.coords[2] = -self.coords[2]; + self.coords[0] = -self.coords[0].clone(); + self.coords[1] = -self.coords[1].clone(); + self.coords[2] = -self.coords[2].clone(); } /// Inverts this quaternion in-place if it is not zero. @@ -671,8 +671,8 @@ where #[inline] pub fn try_inverse_mut(&mut self) -> T::SimdBool { let norm_squared = self.norm_squared(); - let ge = norm_squared.simd_ge(T::simd_default_epsilon()); - *self = ge.if_else(|| self.conjugate() / norm_squared, || *self); + let ge = norm_squared.clone().simd_ge(T::simd_default_epsilon()); + *self = ge.if_else(|| self.conjugate() / norm_squared, || self.clone()); ge } @@ -778,8 +778,8 @@ where #[must_use] pub fn cos(&self) -> Self { let z = self.imag().magnitude(); - let w = -self.w.simd_sin() * z.simd_sinhc(); - Self::from_parts(self.w.simd_cos() * z.simd_cosh(), self.imag() * w) + let w = -self.w.clone().simd_sin() * z.clone().simd_sinhc(); + Self::from_parts(self.w.clone().simd_cos() * z.simd_cosh(), self.imag() * w) } /// Calculates the quaternionic arccosinus. @@ -818,8 +818,8 @@ where #[must_use] pub fn sin(&self) -> Self { let z = self.imag().magnitude(); - let w = self.w.simd_cos() * z.simd_sinhc(); - Self::from_parts(self.w.simd_sin() * z.simd_cosh(), self.imag() * w) + let w = self.w.clone().simd_cos() * z.clone().simd_sinhc(); + Self::from_parts(self.w.clone().simd_sin() * z.simd_cosh(), self.imag() * w) } /// Calculates the quaternionic arcsinus. @@ -838,7 +838,7 @@ where let u = Self::from_imag(self.imag().normalize()); let identity = Self::identity(); - let z = ((u * self) + (identity - self.squared()).sqrt()).ln(); + let z = ((u.clone() * self) + (identity - self.squared()).sqrt()).ln(); -(u * z) } @@ -880,8 +880,8 @@ where T: RealField, { let u = Self::from_imag(self.imag().normalize()); - let num = u + self; - let den = u - self; + let num = u.clone() + self; + let den = u.clone() - self; let fr = num.right_div(&den).unwrap(); let ln = fr.ln(); (u.half()) * ln @@ -954,7 +954,7 @@ where #[must_use] pub fn acosh(&self) -> Self { let identity = Self::identity(); - (self + (self + identity).sqrt() * (self - identity).sqrt()).ln() + (self + (self + identity.clone()).sqrt() * (self - identity).sqrt()).ln() } /// Calculates the hyperbolic quaternionic tangent. @@ -992,7 +992,7 @@ where #[must_use] pub fn atanh(&self) -> Self { let identity = Self::identity(); - ((identity + self).ln() - (identity - self).ln()).half() + ((identity.clone() + self).ln() - (identity - self).ln()).half() } } @@ -1006,9 +1006,9 @@ impl> AbsDiffEq for Quaternion { #[inline] fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool { - self.as_vector().abs_diff_eq(other.as_vector(), epsilon) || + self.as_vector().abs_diff_eq(other.as_vector(), epsilon.clone()) || // Account for the double-covering of S², i.e. q = -q - self.as_vector().iter().zip(other.as_vector().iter()).all(|(a, b)| a.abs_diff_eq(&-*b, epsilon)) + self.as_vector().iter().zip(other.as_vector().iter()).all(|(a, b)| a.abs_diff_eq(&-b.clone(), epsilon.clone())) } } @@ -1025,9 +1025,9 @@ impl> RelativeEq for Quaternion { epsilon: Self::Epsilon, max_relative: Self::Epsilon, ) -> bool { - self.as_vector().relative_eq(other.as_vector(), epsilon, max_relative) || + self.as_vector().relative_eq(other.as_vector(), epsilon.clone(), max_relative.clone()) || // Account for the double-covering of S², i.e. q = -q - self.as_vector().iter().zip(other.as_vector().iter()).all(|(a, b)| a.relative_eq(&-*b, epsilon, max_relative)) + self.as_vector().iter().zip(other.as_vector().iter()).all(|(a, b)| a.relative_eq(&-b.clone(), epsilon.clone(), max_relative.clone())) } } @@ -1039,9 +1039,9 @@ impl> UlpsEq for Quaternion { #[inline] fn ulps_eq(&self, other: &Self, epsilon: Self::Epsilon, max_ulps: u32) -> bool { - self.as_vector().ulps_eq(other.as_vector(), epsilon, max_ulps) || + self.as_vector().ulps_eq(other.as_vector(), epsilon.clone(), max_ulps.clone()) || // Account for the double-covering of S², i.e. q = -q. - self.as_vector().iter().zip(other.as_vector().iter()).all(|(a, b)| a.ulps_eq(&-*b, epsilon, max_ulps)) + self.as_vector().iter().zip(other.as_vector().iter()).all(|(a, b)| a.ulps_eq(&-b.clone(), epsilon.clone(), max_ulps.clone())) } } @@ -1063,7 +1063,7 @@ impl PartialEq for UnitQuaternion { fn eq(&self, rhs: &Self) -> bool { self.coords == rhs.coords || // Account for the double-covering of S², i.e. q = -q - self.coords.iter().zip(rhs.coords.iter()).all(|(a, b)| *a == -b.inlined_clone()) + self.coords.iter().zip(rhs.coords.iter()).all(|(a, b)| *a == -b.clone()) } } @@ -1279,14 +1279,14 @@ where T: RealField, { let coords = if self.coords.dot(&other.coords) < T::zero() { - Unit::new_unchecked(self.coords).try_slerp( - &Unit::new_unchecked(-other.coords), + Unit::new_unchecked(self.coords.clone()).try_slerp( + &Unit::new_unchecked(-other.coords.clone()), t, epsilon, ) } else { - Unit::new_unchecked(self.coords).try_slerp( - &Unit::new_unchecked(other.coords), + Unit::new_unchecked(self.coords.clone()).try_slerp( + &Unit::new_unchecked(other.coords.clone()), t, epsilon, ) @@ -1479,31 +1479,31 @@ where #[inline] #[must_use] pub fn to_rotation_matrix(self) -> Rotation { - let i = self.as_ref()[0]; - let j = self.as_ref()[1]; - let k = self.as_ref()[2]; - let w = self.as_ref()[3]; + let i = self.as_ref()[0].clone(); + let j = self.as_ref()[1].clone(); + let k = self.as_ref()[2].clone(); + let w = self.as_ref()[3].clone(); - let ww = w * w; - let ii = i * i; - let jj = j * j; - let kk = k * k; - let ij = i * j * crate::convert(2.0f64); - let wk = w * k * crate::convert(2.0f64); - let wj = w * j * crate::convert(2.0f64); - let ik = i * k * crate::convert(2.0f64); - let jk = j * k * crate::convert(2.0f64); - let wi = w * i * crate::convert(2.0f64); + let ww = w.clone() * w.clone(); + let ii = i.clone() * i.clone(); + let jj = j.clone() * j.clone(); + let kk = k.clone() * k.clone(); + let ij = i.clone() * j.clone() * crate::convert(2.0f64); + let wk = w.clone() * k.clone() * crate::convert(2.0f64); + let wj = w.clone() * j.clone() * crate::convert(2.0f64); + let ik = i.clone() * k.clone() * crate::convert(2.0f64); + let jk = j.clone() * k.clone() * crate::convert(2.0f64); + let wi = w.clone() * i.clone() * crate::convert(2.0f64); Rotation::from_matrix_unchecked(Matrix3::new( - ww + ii - jj - kk, - ij - wk, - wj + ik, - wk + ij, - ww - ii + jj - kk, - jk - wi, - ik - wj, - wi + jk, + ww.clone() + ii.clone() - jj.clone() - kk.clone(), + ij.clone() - wk.clone(), + wj.clone() + ik.clone(), + wk.clone() + ij.clone(), + ww.clone() - ii.clone() + jj.clone() - kk.clone(), + jk.clone() - wi.clone(), + ik.clone() - wj.clone(), + wi.clone() + jk.clone(), ww - ii - jj + kk, )) } @@ -1540,7 +1540,7 @@ where where T: RealField, { - self.to_rotation_matrix().euler_angles() + self.clone().to_rotation_matrix().euler_angles() } /// Converts this unit quaternion into its equivalent homogeneous transformation matrix. @@ -1679,9 +1679,9 @@ where #[must_use] pub fn append_axisangle_linearized(&self, axisangle: &Vector3) -> Self { let half: T = crate::convert(0.5); - let q1 = self.into_inner(); + let q1 = self.clone().into_inner(); let q2 = Quaternion::from_imag(axisangle * half); - Unit::new_normalize(q1 + q2 * q1) + Unit::new_normalize(&q1 + q2 * &q1) } } diff --git a/src/geometry/quaternion_construction.rs b/src/geometry/quaternion_construction.rs index 61b1fe3e..6de21bd5 100644 --- a/src/geometry/quaternion_construction.rs +++ b/src/geometry/quaternion_construction.rs @@ -95,7 +95,12 @@ impl Quaternion { where SB: Storage, { - Self::new(scalar, vector[0], vector[1], vector[2]) + Self::new( + scalar, + vector[0].clone(), + vector[1].clone(), + vector[2].clone(), + ) } /// Constructs a real quaternion. @@ -296,9 +301,9 @@ where let (sy, cy) = (yaw * crate::convert(0.5f64)).simd_sin_cos(); let q = Quaternion::new( - cr * cp * cy + sr * sp * sy, - sr * cp * cy - cr * sp * sy, - cr * sp * cy + sr * cp * sy, + cr.clone() * cp.clone() * cy.clone() + sr.clone() * sp.clone() * sy.clone(), + sr.clone() * cp.clone() * cy.clone() - cr.clone() * sp.clone() * sy.clone(), + cr.clone() * sp.clone() * cy.clone() + sr.clone() * cp.clone() * sy.clone(), cr * cp * sy - sr * sp * cy, ); @@ -334,56 +339,65 @@ where pub fn from_rotation_matrix(rotmat: &Rotation3) -> Self { // Robust matrix to quaternion transformation. // See https://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion - let tr = rotmat[(0, 0)] + rotmat[(1, 1)] + rotmat[(2, 2)]; + let tr = rotmat[(0, 0)].clone() + rotmat[(1, 1)].clone() + rotmat[(2, 2)].clone(); let quarter: T = crate::convert(0.25); - let res = tr.simd_gt(T::zero()).if_else3( + let res = tr.clone().simd_gt(T::zero()).if_else3( || { - let denom = (tr + T::one()).simd_sqrt() * crate::convert(2.0); + let denom = (tr.clone() + T::one()).simd_sqrt() * crate::convert(2.0); Quaternion::new( - quarter * denom, - (rotmat[(2, 1)] - rotmat[(1, 2)]) / denom, - (rotmat[(0, 2)] - rotmat[(2, 0)]) / denom, - (rotmat[(1, 0)] - rotmat[(0, 1)]) / denom, + quarter.clone() * denom.clone(), + (rotmat[(2, 1)].clone() - rotmat[(1, 2)].clone()) / denom.clone(), + (rotmat[(0, 2)].clone() - rotmat[(2, 0)].clone()) / denom.clone(), + (rotmat[(1, 0)].clone() - rotmat[(0, 1)].clone()) / denom, ) }, ( - || rotmat[(0, 0)].simd_gt(rotmat[(1, 1)]) & rotmat[(0, 0)].simd_gt(rotmat[(2, 2)]), || { - let denom = (T::one() + rotmat[(0, 0)] - rotmat[(1, 1)] - rotmat[(2, 2)]) - .simd_sqrt() + rotmat[(0, 0)].clone().simd_gt(rotmat[(1, 1)].clone()) + & rotmat[(0, 0)].clone().simd_gt(rotmat[(2, 2)].clone()) + }, + || { + let denom = (T::one() + rotmat[(0, 0)].clone() + - rotmat[(1, 1)].clone() + - rotmat[(2, 2)].clone()) + .simd_sqrt() * crate::convert(2.0); Quaternion::new( - (rotmat[(2, 1)] - rotmat[(1, 2)]) / denom, - quarter * denom, - (rotmat[(0, 1)] + rotmat[(1, 0)]) / denom, - (rotmat[(0, 2)] + rotmat[(2, 0)]) / denom, + (rotmat[(2, 1)].clone() - rotmat[(1, 2)].clone()) / denom.clone(), + quarter.clone() * denom.clone(), + (rotmat[(0, 1)].clone() + rotmat[(1, 0)].clone()) / denom.clone(), + (rotmat[(0, 2)].clone() + rotmat[(2, 0)].clone()) / denom, ) }, ), ( - || rotmat[(1, 1)].simd_gt(rotmat[(2, 2)]), + || rotmat[(1, 1)].clone().simd_gt(rotmat[(2, 2)].clone()), || { - let denom = (T::one() + rotmat[(1, 1)] - rotmat[(0, 0)] - rotmat[(2, 2)]) - .simd_sqrt() + let denom = (T::one() + rotmat[(1, 1)].clone() + - rotmat[(0, 0)].clone() + - rotmat[(2, 2)].clone()) + .simd_sqrt() * crate::convert(2.0); Quaternion::new( - (rotmat[(0, 2)] - rotmat[(2, 0)]) / denom, - (rotmat[(0, 1)] + rotmat[(1, 0)]) / denom, - quarter * denom, - (rotmat[(1, 2)] + rotmat[(2, 1)]) / denom, + (rotmat[(0, 2)].clone() - rotmat[(2, 0)].clone()) / denom.clone(), + (rotmat[(0, 1)].clone() + rotmat[(1, 0)].clone()) / denom.clone(), + quarter.clone() * denom.clone(), + (rotmat[(1, 2)].clone() + rotmat[(2, 1)].clone()) / denom, ) }, ), || { - let denom = (T::one() + rotmat[(2, 2)] - rotmat[(0, 0)] - rotmat[(1, 1)]) - .simd_sqrt() + let denom = (T::one() + rotmat[(2, 2)].clone() + - rotmat[(0, 0)].clone() + - rotmat[(1, 1)].clone()) + .simd_sqrt() * crate::convert(2.0); Quaternion::new( - (rotmat[(1, 0)] - rotmat[(0, 1)]) / denom, - (rotmat[(0, 2)] + rotmat[(2, 0)]) / denom, - (rotmat[(1, 2)] + rotmat[(2, 1)]) / denom, - quarter * denom, + (rotmat[(1, 0)].clone() - rotmat[(0, 1)].clone()) / denom.clone(), + (rotmat[(0, 2)].clone() + rotmat[(2, 0)].clone()) / denom.clone(), + (rotmat[(1, 2)].clone() + rotmat[(2, 1)].clone()) / denom.clone(), + quarter.clone() * denom, ) }, ); @@ -833,10 +847,10 @@ where let max_eigenvector = eigen_matrix.eigenvectors.column(max_eigenvalue_index); UnitQuaternion::from_quaternion(Quaternion::new( - max_eigenvector[0], - max_eigenvector[1], - max_eigenvector[2], - max_eigenvector[3], + max_eigenvector[0].clone(), + max_eigenvector[1].clone(), + max_eigenvector[2].clone(), + max_eigenvector[3].clone(), )) } } @@ -868,13 +882,18 @@ where let twopi = Uniform::new(T::zero(), T::simd_two_pi()); let theta1 = rng.sample(&twopi); let theta2 = rng.sample(&twopi); - let s1 = theta1.simd_sin(); + let s1 = theta1.clone().simd_sin(); let c1 = theta1.simd_cos(); - let s2 = theta2.simd_sin(); + let s2 = theta2.clone().simd_sin(); let c2 = theta2.simd_cos(); - let r1 = (T::one() - x0).simd_sqrt(); + let r1 = (T::one() - x0.clone()).simd_sqrt(); let r2 = x0.simd_sqrt(); - Unit::new_unchecked(Quaternion::new(s1 * r1, c1 * r1, s2 * r2, c2 * r2)) + Unit::new_unchecked(Quaternion::new( + s1 * r1.clone(), + c1 * r1, + s2 * r2.clone(), + c2 * r2, + )) } } diff --git a/src/geometry/quaternion_conversion.rs b/src/geometry/quaternion_conversion.rs index 6dfbfbc6..d2fe274b 100644 --- a/src/geometry/quaternion_conversion.rs +++ b/src/geometry/quaternion_conversion.rs @@ -167,7 +167,7 @@ where { #[inline] fn to_superset(&self) -> Transform { - Transform::from_matrix_unchecked(self.to_homogeneous().to_superset()) + Transform::from_matrix_unchecked(self.clone().to_homogeneous().to_superset()) } #[inline] @@ -184,7 +184,7 @@ where impl> SubsetOf> for UnitQuaternion { #[inline] fn to_superset(&self) -> Matrix4 { - self.to_homogeneous().to_superset() + self.clone().to_homogeneous().to_superset() } #[inline] diff --git a/src/geometry/quaternion_ops.rs b/src/geometry/quaternion_ops.rs index eb7a15cd..032e8919 100644 --- a/src/geometry/quaternion_ops.rs +++ b/src/geometry/quaternion_ops.rs @@ -159,10 +159,10 @@ quaternion_op_impl!( ; self: &'a Quaternion, rhs: &'b Quaternion, Output = Quaternion; Quaternion::new( - self[3] * rhs[3] - self[0] * rhs[0] - self[1] * rhs[1] - self[2] * rhs[2], - self[3] * rhs[0] + self[0] * rhs[3] + self[1] * rhs[2] - self[2] * rhs[1], - self[3] * rhs[1] - self[0] * rhs[2] + self[1] * rhs[3] + self[2] * rhs[0], - self[3] * rhs[2] + self[0] * rhs[1] - self[1] * rhs[0] + self[2] * rhs[3]); + self[3].clone() * rhs[3].clone() - self[0].clone() * rhs[0].clone() - self[1].clone() * rhs[1].clone() - self[2].clone() * rhs[2].clone(), + self[3].clone() * rhs[0].clone() + self[0].clone() * rhs[3].clone() + self[1].clone() * rhs[2].clone() - self[2].clone() * rhs[1].clone(), + self[3].clone() * rhs[1].clone() - self[0].clone() * rhs[2].clone() + self[1].clone() * rhs[3].clone() + self[2].clone() * rhs[0].clone(), + self[3].clone() * rhs[2].clone() + self[0].clone() * rhs[1].clone() - self[1].clone() * rhs[0].clone() + self[2].clone() * rhs[3].clone()); 'a, 'b); quaternion_op_impl!( diff --git a/src/geometry/reflection.rs b/src/geometry/reflection.rs index a48b8024..0b178c76 100644 --- a/src/geometry/reflection.rs +++ b/src/geometry/reflection.rs @@ -45,7 +45,7 @@ impl> Reflection { /// represents a plane that passes through the origin. #[must_use] pub fn bias(&self) -> T { - self.bias + self.bias.clone() } // TODO: naming convention: reflect_to, reflect_assign ? @@ -60,7 +60,7 @@ impl> Reflection { // dot product, and then mutably. Somehow, this allows significantly // better optimizations of the dot product from the compiler. let m_two: T = crate::convert(-2.0f64); - let factor = (self.axis.dotc(&rhs.column(i)) - self.bias) * m_two; + let factor = (self.axis.dotc(&rhs.column(i)) - self.bias.clone()) * m_two; rhs.column_mut(i).axpy(factor, &self.axis, T::one()); } } @@ -76,9 +76,9 @@ impl> Reflection { // NOTE: we borrow the column twice here. First it is borrowed immutably for the // dot product, and then mutably. Somehow, this allows significantly // better optimizations of the dot product from the compiler. - let m_two = sign.scale(crate::convert(-2.0f64)); - let factor = (self.axis.dotc(&rhs.column(i)) - self.bias) * m_two; - rhs.column_mut(i).axpy(factor, &self.axis, sign); + let m_two = sign.clone().scale(crate::convert(-2.0f64)); + let factor = (self.axis.dotc(&rhs.column(i)) - self.bias.clone()) * m_two; + rhs.column_mut(i).axpy(factor, &self.axis, sign.clone()); } } @@ -95,7 +95,7 @@ impl> Reflection { lhs.mul_to(&self.axis, work); if !self.bias.is_zero() { - work.add_scalar_mut(-self.bias); + work.add_scalar_mut(-self.bias.clone()); } let m_two: T = crate::convert(-2.0f64); @@ -116,10 +116,10 @@ impl> Reflection { lhs.mul_to(&self.axis, work); if !self.bias.is_zero() { - work.add_scalar_mut(-self.bias); + work.add_scalar_mut(-self.bias.clone()); } - let m_two = sign.scale(crate::convert(-2.0f64)); + let m_two = sign.clone().scale(crate::convert(-2.0f64)); lhs.gerc(m_two, work, &self.axis, sign); } } diff --git a/src/geometry/rotation.rs b/src/geometry/rotation.rs index 33e42dda..3ac3ca57 100755 --- a/src/geometry/rotation.rs +++ b/src/geometry/rotation.rs @@ -514,7 +514,7 @@ impl PartialEq for Rotation { impl AbsDiffEq for Rotation where T: Scalar + AbsDiffEq, - T::Epsilon: Copy, + T::Epsilon: Clone, { type Epsilon = T::Epsilon; @@ -532,7 +532,7 @@ where impl RelativeEq for Rotation where T: Scalar + RelativeEq, - T::Epsilon: Copy, + T::Epsilon: Clone, { #[inline] fn default_max_relative() -> Self::Epsilon { @@ -554,7 +554,7 @@ where impl UlpsEq for Rotation where T: Scalar + UlpsEq, - T::Epsilon: Copy, + T::Epsilon: Clone, { #[inline] fn default_max_ulps() -> u32 { diff --git a/src/geometry/rotation_interpolation.rs b/src/geometry/rotation_interpolation.rs index dc029d20..477d5e03 100644 --- a/src/geometry/rotation_interpolation.rs +++ b/src/geometry/rotation_interpolation.rs @@ -23,8 +23,8 @@ impl Rotation2 { where T::Element: SimdRealField, { - let c1 = UnitComplex::from(*self); - let c2 = UnitComplex::from(*other); + let c1 = UnitComplex::from(self.clone()); + let c2 = UnitComplex::from(other.clone()); c1.slerp(&c2, t).into() } } @@ -53,8 +53,8 @@ impl Rotation3 { where T: RealField, { - let q1 = UnitQuaternion::from(*self); - let q2 = UnitQuaternion::from(*other); + let q1 = UnitQuaternion::from(self.clone()); + let q2 = UnitQuaternion::from(other.clone()); q1.slerp(&q2, t).into() } @@ -74,8 +74,8 @@ impl Rotation3 { where T: RealField, { - let q1 = UnitQuaternion::from(*self); - let q2 = UnitQuaternion::from(*other); + let q1 = UnitQuaternion::from(self.clone()); + let q2 = UnitQuaternion::from(other.clone()); q1.try_slerp(&q2, t, epsilon).map(|q| q.into()) } } diff --git a/src/geometry/rotation_specialization.rs b/src/geometry/rotation_specialization.rs index 5cd44119..c24514ba 100644 --- a/src/geometry/rotation_specialization.rs +++ b/src/geometry/rotation_specialization.rs @@ -42,7 +42,7 @@ impl Rotation2 { /// ``` pub fn new(angle: T) -> Self { let (sia, coa) = angle.simd_sin_cos(); - Self::from_matrix_unchecked(Matrix2::new(coa, -sia, sia, coa)) + Self::from_matrix_unchecked(Matrix2::new(coa.clone(), -sia.clone(), sia, coa)) } /// Builds a 2 dimensional rotation matrix from an angle in radian wrapped in a 1-dimensional vector. @@ -52,7 +52,7 @@ impl Rotation2 { /// the `::new(angle)` method instead is more common. #[inline] pub fn from_scaled_axis>(axisangle: Vector) -> Self { - Self::new(axisangle[0]) + Self::new(axisangle[0].clone()) } } @@ -108,7 +108,7 @@ impl Rotation2 { let denom = rot.column(0).dot(&m.column(0)) + rot.column(1).dot(&m.column(1)); let angle = axis / (denom.abs() + T::default_epsilon()); - if angle.abs() > eps { + if angle.clone().abs() > eps { rot = Self::new(angle) * rot; } else { break; @@ -198,7 +198,7 @@ impl Rotation2 { where T: RealField, { - let mut c = UnitComplex::from(*self); + let mut c = UnitComplex::from(self.clone()); let _ = c.renormalize(); *self = Self::from_matrix_eps(self.matrix(), T::default_epsilon(), 0, c.into()) @@ -236,7 +236,9 @@ impl Rotation2 { #[inline] #[must_use] pub fn angle(&self) -> T { - self.matrix()[(1, 0)].simd_atan2(self.matrix()[(0, 0)]) + self.matrix()[(1, 0)] + .clone() + .simd_atan2(self.matrix()[(0, 0)].clone()) } /// The rotation angle needed to make `self` and `other` coincide. @@ -382,27 +384,27 @@ where where SB: Storage, { - angle.simd_ne(T::zero()).if_else( + angle.clone().simd_ne(T::zero()).if_else( || { - let ux = axis.as_ref()[0]; - let uy = axis.as_ref()[1]; - let uz = axis.as_ref()[2]; - let sqx = ux * ux; - let sqy = uy * uy; - let sqz = uz * uz; + let ux = axis.as_ref()[0].clone(); + let uy = axis.as_ref()[1].clone(); + let uz = axis.as_ref()[2].clone(); + let sqx = ux.clone() * ux.clone(); + let sqy = uy.clone() * uy.clone(); + let sqz = uz.clone() * uz.clone(); let (sin, cos) = angle.simd_sin_cos(); - let one_m_cos = T::one() - cos; + let one_m_cos = T::one() - cos.clone(); Self::from_matrix_unchecked(SMatrix::::new( - sqx + (T::one() - sqx) * cos, - ux * uy * one_m_cos - uz * sin, - ux * uz * one_m_cos + uy * sin, - ux * uy * one_m_cos + uz * sin, - sqy + (T::one() - sqy) * cos, - uy * uz * one_m_cos - ux * sin, - ux * uz * one_m_cos - uy * sin, + sqx.clone() + (T::one() - sqx) * cos.clone(), + ux.clone() * uy.clone() * one_m_cos.clone() - uz.clone() * sin.clone(), + ux.clone() * uz.clone() * one_m_cos.clone() + uy.clone() * sin.clone(), + ux.clone() * uy.clone() * one_m_cos.clone() + uz.clone() * sin.clone(), + sqy.clone() + (T::one() - sqy) * cos.clone(), + uy.clone() * uz.clone() * one_m_cos.clone() - ux.clone() * sin.clone(), + ux.clone() * uz.clone() * one_m_cos.clone() - uy.clone() * sin.clone(), uy * uz * one_m_cos + ux * sin, - sqz + (T::one() - sqz) * cos, + sqz.clone() + (T::one() - sqz) * cos, )) }, Self::identity, @@ -429,14 +431,14 @@ where let (sy, cy) = yaw.simd_sin_cos(); Self::from_matrix_unchecked(SMatrix::::new( - cy * cp, - cy * sp * sr - sy * cr, - cy * sp * cr + sy * sr, - sy * cp, - sy * sp * sr + cy * cr, - sy * sp * cr - cy * sr, + cy.clone() * cp.clone(), + cy.clone() * sp.clone() * sr.clone() - sy.clone() * cr.clone(), + cy.clone() * sp.clone() * cr.clone() + sy.clone() * sr.clone(), + sy.clone() * cp.clone(), + sy.clone() * sp.clone() * sr.clone() + cy.clone() * cr.clone(), + sy * sp.clone() * cr.clone() - cy * sr.clone(), -sp, - cp * sr, + cp.clone() * sr, cp * cr, )) } @@ -479,7 +481,15 @@ where let yaxis = zaxis.cross(&xaxis).normalize(); Self::from_matrix_unchecked(SMatrix::::new( - xaxis.x, yaxis.x, zaxis.x, xaxis.y, yaxis.y, zaxis.y, xaxis.z, yaxis.z, zaxis.z, + xaxis.x.clone(), + yaxis.x.clone(), + zaxis.x.clone(), + xaxis.y.clone(), + yaxis.y.clone(), + zaxis.y.clone(), + xaxis.z.clone(), + yaxis.z.clone(), + zaxis.z.clone(), )) } @@ -735,7 +745,7 @@ where let axisangle = axis / (denom.abs() + T::default_epsilon()); - if let Some((axis, angle)) = Unit::try_new_and_get(axisangle, eps) { + if let Some((axis, angle)) = Unit::try_new_and_get(axisangle, eps.clone()) { rot = Rotation3::from_axis_angle(&axis, angle) * rot; } else { break; @@ -752,7 +762,7 @@ where where T: RealField, { - let mut c = UnitQuaternion::from(*self); + let mut c = UnitQuaternion::from(self.clone()); let _ = c.renormalize(); *self = Self::from_matrix_eps(self.matrix(), T::default_epsilon(), 0, c.into()) @@ -774,7 +784,10 @@ impl Rotation3 { #[inline] #[must_use] pub fn angle(&self) -> T { - ((self.matrix()[(0, 0)] + self.matrix()[(1, 1)] + self.matrix()[(2, 2)] - T::one()) + ((self.matrix()[(0, 0)].clone() + + self.matrix()[(1, 1)].clone() + + self.matrix()[(2, 2)].clone() + - T::one()) / crate::convert(2.0)) .simd_acos() } @@ -800,10 +813,11 @@ impl Rotation3 { where T: RealField, { + let rotmat = self.matrix(); let axis = SVector::::new( - self.matrix()[(2, 1)] - self.matrix()[(1, 2)], - self.matrix()[(0, 2)] - self.matrix()[(2, 0)], - self.matrix()[(1, 0)] - self.matrix()[(0, 1)], + rotmat[(2, 1)].clone() - rotmat[(1, 2)].clone(), + rotmat[(0, 2)].clone() - rotmat[(2, 0)].clone(), + rotmat[(1, 0)].clone() - rotmat[(0, 1)].clone(), ); Unit::try_new(axis, T::default_epsilon()) @@ -911,16 +925,22 @@ impl Rotation3 { { // Implementation informed by "Computing Euler angles from a rotation matrix", by Gregory G. Slabaugh // https://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.371.6578 - if self[(2, 0)].abs() < T::one() { - let yaw = -self[(2, 0)].asin(); - let roll = (self[(2, 1)] / yaw.cos()).atan2(self[(2, 2)] / yaw.cos()); - let pitch = (self[(1, 0)] / yaw.cos()).atan2(self[(0, 0)] / yaw.cos()); + if self[(2, 0)].clone().abs() < T::one() { + let yaw = -self[(2, 0)].clone().asin(); + let roll = (self[(2, 1)].clone() / yaw.clone().cos()) + .atan2(self[(2, 2)].clone() / yaw.clone().cos()); + let pitch = (self[(1, 0)].clone() / yaw.clone().cos()) + .atan2(self[(0, 0)].clone() / yaw.clone().cos()); (roll, yaw, pitch) - } else if self[(2, 0)] <= -T::one() { - (self[(0, 1)].atan2(self[(0, 2)]), T::frac_pi_2(), T::zero()) + } else if self[(2, 0)].clone() <= -T::one() { + ( + self[(0, 1)].clone().atan2(self[(0, 2)].clone()), + T::frac_pi_2(), + T::zero(), + ) } else { ( - -self[(0, 1)].atan2(-self[(0, 2)]), + -self[(0, 1)].clone().atan2(-self[(0, 2)].clone()), -T::frac_pi_2(), T::zero(), ) @@ -947,8 +967,8 @@ where let theta = rng.sample(&twopi); let (ts, tc) = theta.simd_sin_cos(); let a = SMatrix::::new( - tc, - ts, + tc.clone(), + ts.clone(), T::zero(), -ts, tc, @@ -962,10 +982,10 @@ where let phi = rng.sample(&twopi); let z = rng.sample(OpenClosed01); let (ps, pc) = phi.simd_sin_cos(); - let sqrt_z = z.simd_sqrt(); - let v = Vector3::new(pc * sqrt_z, ps * sqrt_z, (T::one() - z).simd_sqrt()); - let mut b = v * v.transpose(); - b += b; + let sqrt_z = z.clone().simd_sqrt(); + let v = Vector3::new(pc * sqrt_z.clone(), ps * sqrt_z, (T::one() - z).simd_sqrt()); + let mut b = v.clone() * v.transpose(); + b += b.clone(); b -= SMatrix::::identity(); Rotation3::from_matrix_unchecked(b * a) diff --git a/src/geometry/similarity.rs b/src/geometry/similarity.rs index 32a19772..4cff61ce 100755 --- a/src/geometry/similarity.rs +++ b/src/geometry/similarity.rs @@ -124,7 +124,7 @@ impl Similarity { #[inline] #[must_use] pub fn scaling(&self) -> T { - self.scaling.inlined_clone() + self.scaling.clone() } } @@ -151,9 +151,9 @@ where /// Inverts `self` in-place. #[inline] pub fn inverse_mut(&mut self) { - self.scaling = T::one() / self.scaling; + self.scaling = T::one() / self.scaling.clone(); self.isometry.inverse_mut(); - self.isometry.translation.vector *= self.scaling; + self.isometry.translation.vector *= self.scaling.clone(); } /// The similarity transformation that applies a scaling factor `scaling` before `self`. @@ -165,7 +165,7 @@ where "The similarity scaling factor must not be zero." ); - Self::from_isometry(self.isometry.clone(), self.scaling * scaling) + Self::from_isometry(self.isometry.clone(), self.scaling.clone() * scaling) } /// The similarity transformation that applies a scaling factor `scaling` after `self`. @@ -178,9 +178,9 @@ where ); Self::from_parts( - Translation::from(self.isometry.translation.vector * scaling), + Translation::from(&self.isometry.translation.vector * scaling.clone()), self.isometry.rotation.clone(), - self.scaling * scaling, + self.scaling.clone() * scaling, ) } @@ -203,7 +203,7 @@ where "The similarity scaling factor must not be zero." ); - self.isometry.translation.vector *= scaling; + self.isometry.translation.vector *= scaling.clone(); self.scaling *= scaling; } @@ -336,7 +336,7 @@ impl Similarity { let mut res = self.isometry.to_homogeneous(); for e in res.fixed_slice_mut::(0, 0).iter_mut() { - *e *= self.scaling + *e *= self.scaling.clone() } res @@ -361,7 +361,7 @@ where impl AbsDiffEq for Similarity where R: AbstractRotation + AbsDiffEq, - T::Epsilon: Copy, + T::Epsilon: Clone, { type Epsilon = T::Epsilon; @@ -372,7 +372,7 @@ where #[inline] fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool { - self.isometry.abs_diff_eq(&other.isometry, epsilon) + self.isometry.abs_diff_eq(&other.isometry, epsilon.clone()) && self.scaling.abs_diff_eq(&other.scaling, epsilon) } } @@ -380,7 +380,7 @@ where impl RelativeEq for Similarity where R: AbstractRotation + RelativeEq, - T::Epsilon: Copy, + T::Epsilon: Clone, { #[inline] fn default_max_relative() -> Self::Epsilon { @@ -395,7 +395,7 @@ where max_relative: Self::Epsilon, ) -> bool { self.isometry - .relative_eq(&other.isometry, epsilon, max_relative) + .relative_eq(&other.isometry, epsilon.clone(), max_relative.clone()) && self .scaling .relative_eq(&other.scaling, epsilon, max_relative) @@ -405,7 +405,7 @@ where impl UlpsEq for Similarity where R: AbstractRotation + UlpsEq, - T::Epsilon: Copy, + T::Epsilon: Clone, { #[inline] fn default_max_ulps() -> u32 { @@ -414,7 +414,8 @@ where #[inline] fn ulps_eq(&self, other: &Self, epsilon: Self::Epsilon, max_ulps: u32) -> bool { - self.isometry.ulps_eq(&other.isometry, epsilon, max_ulps) + self.isometry + .ulps_eq(&other.isometry, epsilon.clone(), max_ulps.clone()) && self.scaling.ulps_eq(&other.scaling, epsilon, max_ulps) } } diff --git a/src/geometry/similarity_ops.rs b/src/geometry/similarity_ops.rs index b88f9442..0c8535b5 100644 --- a/src/geometry/similarity_ops.rs +++ b/src/geometry/similarity_ops.rs @@ -222,7 +222,7 @@ md_assign_impl_all!( const D; for; where; self: Similarity, D>, rhs: Rotation; [val] => self.isometry.rotation *= rhs; - [ref] => self.isometry.rotation *= *rhs; + [ref] => self.isometry.rotation *= rhs.clone(); ); md_assign_impl_all!( @@ -241,7 +241,7 @@ md_assign_impl_all!( const; for; where; self: Similarity, 3>, rhs: UnitQuaternion; [val] => self.isometry.rotation *= rhs; - [ref] => self.isometry.rotation *= *rhs; + [ref] => self.isometry.rotation *= rhs.clone(); ); md_assign_impl_all!( @@ -260,7 +260,7 @@ md_assign_impl_all!( const; for; where; self: Similarity, 2>, rhs: UnitComplex; [val] => self.isometry.rotation *= rhs; - [ref] => self.isometry.rotation *= *rhs; + [ref] => self.isometry.rotation *= rhs.clone(); ); md_assign_impl_all!( diff --git a/src/geometry/swizzle.rs b/src/geometry/swizzle.rs index 0ad51f00..f8f9f6d5 100644 --- a/src/geometry/swizzle.rs +++ b/src/geometry/swizzle.rs @@ -11,7 +11,7 @@ macro_rules! impl_swizzle { #[must_use] pub fn $name(&self) -> $Result where as ToTypenum>::Typenum: Cmp { - $Result::new($(self[$i].inlined_clone()),*) + $Result::new($(self[$i].clone()),*) } )* )* diff --git a/src/geometry/transform.rs b/src/geometry/transform.rs index 71544b59..f9dbeb51 100755 --- a/src/geometry/transform.rs +++ b/src/geometry/transform.rs @@ -31,7 +31,7 @@ pub trait TCategory: Any + Debug + Copy + PartialEq + Send { /// category `Self`. fn check_homogeneous_invariants(mat: &OMatrix) -> bool where - T::Epsilon: Copy, + T::Epsilon: Clone, DefaultAllocator: Allocator; } @@ -74,7 +74,7 @@ impl TCategory for TGeneral { #[inline] fn check_homogeneous_invariants(_: &OMatrix) -> bool where - T::Epsilon: Copy, + T::Epsilon: Clone, DefaultAllocator: Allocator, { true @@ -85,7 +85,7 @@ impl TCategory for TProjective { #[inline] fn check_homogeneous_invariants(mat: &OMatrix) -> bool where - T::Epsilon: Copy, + T::Epsilon: Clone, DefaultAllocator: Allocator, { mat.is_invertible() @@ -101,7 +101,7 @@ impl TCategory for TAffine { #[inline] fn check_homogeneous_invariants(mat: &OMatrix) -> bool where - T::Epsilon: Copy, + T::Epsilon: Clone, DefaultAllocator: Allocator, { let last = D::dim() - 1; @@ -178,7 +178,7 @@ where } } -impl Copy for Transform +impl Copy for Transform where Const: DimNameAdd, DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, @@ -583,7 +583,7 @@ where impl AbsDiffEq for Transform where Const: DimNameAdd, - T::Epsilon: Copy, + T::Epsilon: Clone, DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, { type Epsilon = T::Epsilon; @@ -602,7 +602,7 @@ where impl RelativeEq for Transform where Const: DimNameAdd, - T::Epsilon: Copy, + T::Epsilon: Clone, DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, { #[inline] @@ -625,7 +625,7 @@ where impl UlpsEq for Transform where Const: DimNameAdd, - T::Epsilon: Copy, + T::Epsilon: Clone, DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, { #[inline] diff --git a/src/geometry/transform_ops.rs b/src/geometry/transform_ops.rs index 94ef4ab3..8a500676 100644 --- a/src/geometry/transform_ops.rs +++ b/src/geometry/transform_ops.rs @@ -154,7 +154,7 @@ md_impl_all!( if C::has_normalizer() { let normalizer = self.matrix().fixed_slice::<1, D>(D, 0); #[allow(clippy::suspicious_arithmetic_impl)] - let n = normalizer.tr_dot(&rhs.coords) + unsafe { *self.matrix().get_unchecked((D, D)) }; + let n = normalizer.tr_dot(&rhs.coords) + unsafe { self.matrix().get_unchecked((D, D)).clone() }; if !n.is_zero() { return (transform * rhs + translation) / n; @@ -221,8 +221,8 @@ md_impl_all!( self: Transform, rhs: UnitQuaternion, Output = Transform; [val val] => Self::Output::from_matrix_unchecked(self.into_inner() * rhs.to_homogeneous()); [ref val] => Self::Output::from_matrix_unchecked(self.matrix() * rhs.to_homogeneous()); - [val ref] => Self::Output::from_matrix_unchecked(self.into_inner() * rhs.to_homogeneous()); - [ref ref] => Self::Output::from_matrix_unchecked(self.matrix() * rhs.to_homogeneous()); + [val ref] => Self::Output::from_matrix_unchecked(self.into_inner() * rhs.clone().to_homogeneous()); + [ref ref] => Self::Output::from_matrix_unchecked(self.matrix() * rhs.clone().to_homogeneous()); ); // Transform × UnitComplex @@ -235,8 +235,8 @@ md_impl_all!( self: Transform, rhs: UnitComplex, Output = Transform; [val val] => Self::Output::from_matrix_unchecked(self.into_inner() * rhs.to_homogeneous()); [ref val] => Self::Output::from_matrix_unchecked(self.matrix() * rhs.to_homogeneous()); - [val ref] => Self::Output::from_matrix_unchecked(self.into_inner() * rhs.to_homogeneous()); - [ref ref] => Self::Output::from_matrix_unchecked(self.matrix() * rhs.to_homogeneous()); + [val ref] => Self::Output::from_matrix_unchecked(self.into_inner() * rhs.clone().to_homogeneous()); + [ref ref] => Self::Output::from_matrix_unchecked(self.matrix() * rhs.clone().to_homogeneous()); ); // UnitQuaternion × Transform @@ -248,9 +248,9 @@ md_impl_all!( where C: TCategoryMul; self: UnitQuaternion, rhs: Transform, Output = Transform; [val val] => Self::Output::from_matrix_unchecked(self.to_homogeneous() * rhs.into_inner()); - [ref val] => Self::Output::from_matrix_unchecked(self.to_homogeneous() * rhs.into_inner()); + [ref val] => Self::Output::from_matrix_unchecked(self.clone().to_homogeneous() * rhs.into_inner()); [val ref] => Self::Output::from_matrix_unchecked(self.to_homogeneous() * rhs.matrix()); - [ref ref] => Self::Output::from_matrix_unchecked(self.to_homogeneous() * rhs.matrix()); + [ref ref] => Self::Output::from_matrix_unchecked(self.clone().to_homogeneous() * rhs.matrix()); ); // UnitComplex × Transform @@ -262,9 +262,9 @@ md_impl_all!( where C: TCategoryMul; self: UnitComplex, rhs: Transform, Output = Transform; [val val] => Self::Output::from_matrix_unchecked(self.to_homogeneous() * rhs.into_inner()); - [ref val] => Self::Output::from_matrix_unchecked(self.to_homogeneous() * rhs.into_inner()); + [ref val] => Self::Output::from_matrix_unchecked(self.clone().to_homogeneous() * rhs.into_inner()); [val ref] => Self::Output::from_matrix_unchecked(self.to_homogeneous() * rhs.matrix()); - [ref ref] => Self::Output::from_matrix_unchecked(self.to_homogeneous() * rhs.matrix()); + [ref ref] => Self::Output::from_matrix_unchecked(self.clone().to_homogeneous() * rhs.matrix()); ); // Transform × Isometry @@ -604,7 +604,7 @@ md_assign_impl_all!( where C: TCategory; self: Transform, rhs: UnitQuaternion; [val] => *self.matrix_mut_unchecked() *= rhs.to_homogeneous(); - [ref] => *self.matrix_mut_unchecked() *= rhs.to_homogeneous(); + [ref] => *self.matrix_mut_unchecked() *= rhs.clone().to_homogeneous(); ); // Transform ×= UnitComplex @@ -616,7 +616,7 @@ md_assign_impl_all!( where C: TCategory; self: Transform, rhs: UnitComplex; [val] => *self.matrix_mut_unchecked() *= rhs.to_homogeneous(); - [ref] => *self.matrix_mut_unchecked() *= rhs.to_homogeneous(); + [ref] => *self.matrix_mut_unchecked() *= rhs.clone().to_homogeneous(); ); // Transform ÷= Transform diff --git a/src/geometry/translation.rs b/src/geometry/translation.rs index 1dd6f6d5..8a64b97a 100755 --- a/src/geometry/translation.rs +++ b/src/geometry/translation.rs @@ -291,7 +291,7 @@ impl PartialEq for Translation { impl AbsDiffEq for Translation where - T::Epsilon: Copy, + T::Epsilon: Clone, { type Epsilon = T::Epsilon; @@ -308,7 +308,7 @@ where impl RelativeEq for Translation where - T::Epsilon: Copy, + T::Epsilon: Clone, { #[inline] fn default_max_relative() -> Self::Epsilon { @@ -329,7 +329,7 @@ where impl UlpsEq for Translation where - T::Epsilon: Copy, + T::Epsilon: Clone, { #[inline] fn default_max_ulps() -> u32 { diff --git a/src/geometry/translation_conversion.rs b/src/geometry/translation_conversion.rs index d443a2f4..70000efb 100644 --- a/src/geometry/translation_conversion.rs +++ b/src/geometry/translation_conversion.rs @@ -77,7 +77,7 @@ where { #[inline] fn to_superset(&self) -> UnitDualQuaternion { - let dq = UnitDualQuaternion::::from_parts(*self, UnitQuaternion::identity()); + let dq = UnitDualQuaternion::::from_parts(self.clone(), UnitQuaternion::identity()); dq.to_superset() } diff --git a/src/geometry/unit_complex.rs b/src/geometry/unit_complex.rs index d6f3d0dc..87af3200 100755 --- a/src/geometry/unit_complex.rs +++ b/src/geometry/unit_complex.rs @@ -47,25 +47,25 @@ impl Normed for Complex { fn norm(&self) -> T::SimdRealField { // We don't use `.norm_sqr()` because it requires // some very strong Num trait requirements. - (self.re * self.re + self.im * self.im).simd_sqrt() + (self.re.clone() * self.re.clone() + self.im.clone() * self.im.clone()).simd_sqrt() } #[inline] fn norm_squared(&self) -> T::SimdRealField { // We don't use `.norm_sqr()` because it requires // some very strong Num trait requirements. - self.re * self.re + self.im * self.im + self.re.clone() * self.re.clone() + self.im.clone() * self.im.clone() } #[inline] fn scale_mut(&mut self, n: Self::Norm) { - self.re *= n; + self.re *= n.clone(); self.im *= n; } #[inline] fn unscale_mut(&mut self, n: Self::Norm) { - self.re /= n; + self.re /= n.clone(); self.im /= n; } } @@ -86,7 +86,7 @@ where #[inline] #[must_use] pub fn angle(&self) -> T { - self.im.simd_atan2(self.re) + self.im.clone().simd_atan2(self.re.clone()) } /// The sine of the rotation angle. @@ -101,7 +101,7 @@ where #[inline] #[must_use] pub fn sin_angle(&self) -> T { - self.im + self.im.clone() } /// The cosine of the rotation angle. @@ -116,7 +116,7 @@ where #[inline] #[must_use] pub fn cos_angle(&self) -> T { - self.re + self.re.clone() } /// The rotation angle returned as a 1-dimensional vector. @@ -145,7 +145,7 @@ where if ang.is_zero() { None } else if ang.is_sign_negative() { - Some((Unit::new_unchecked(Vector1::x()), -ang)) + Some((Unit::new_unchecked(Vector1::x()), -ang.clone())) } else { Some((Unit::new_unchecked(-Vector1::::x()), ang)) } @@ -223,7 +223,7 @@ where #[inline] pub fn conjugate_mut(&mut self) { let me = self.as_mut_unchecked(); - me.im = -me.im; + me.im = -me.im.clone(); } /// Inverts in-place this unit complex number. @@ -262,10 +262,10 @@ where #[inline] #[must_use] pub fn to_rotation_matrix(self) -> Rotation2 { - let r = self.re; - let i = self.im; + let r = self.re.clone(); + let i = self.im.clone(); - Rotation2::from_matrix_unchecked(Matrix2::new(r, -i, i, r)) + Rotation2::from_matrix_unchecked(Matrix2::new(r.clone(), -i.clone(), i, r)) } /// Converts this unit complex number into its equivalent homogeneous transformation matrix. @@ -407,7 +407,7 @@ where #[inline] #[must_use] pub fn slerp(&self, other: &Self, t: T) -> Self { - Self::new(self.angle() * (T::one() - t) + other.angle() * t) + Self::new(self.angle() * (T::one() - t.clone()) + other.angle() * t) } } @@ -427,7 +427,7 @@ impl AbsDiffEq for UnitComplex { #[inline] fn abs_diff_eq(&self, other: &Self, epsilon: Self::Epsilon) -> bool { - self.re.abs_diff_eq(&other.re, epsilon) && self.im.abs_diff_eq(&other.im, epsilon) + self.re.abs_diff_eq(&other.re, epsilon.clone()) && self.im.abs_diff_eq(&other.im, epsilon) } } @@ -444,7 +444,8 @@ impl RelativeEq for UnitComplex { epsilon: Self::Epsilon, max_relative: Self::Epsilon, ) -> bool { - self.re.relative_eq(&other.re, epsilon, max_relative) + self.re + .relative_eq(&other.re, epsilon.clone(), max_relative.clone()) && self.im.relative_eq(&other.im, epsilon, max_relative) } } @@ -457,7 +458,8 @@ impl UlpsEq for UnitComplex { #[inline] fn ulps_eq(&self, other: &Self, epsilon: Self::Epsilon, max_ulps: u32) -> bool { - self.re.ulps_eq(&other.re, epsilon, max_ulps) + self.re + .ulps_eq(&other.re, epsilon.clone(), max_ulps.clone()) && self.im.ulps_eq(&other.im, epsilon, max_ulps) } } diff --git a/src/geometry/unit_complex_construction.rs b/src/geometry/unit_complex_construction.rs index a86b2277..0bf0188c 100644 --- a/src/geometry/unit_complex_construction.rs +++ b/src/geometry/unit_complex_construction.rs @@ -109,7 +109,7 @@ where /// the `::new(angle)` method instead is more common. #[inline] pub fn from_scaled_axis>(axisangle: Vector) -> Self { - Self::from_angle(axisangle[0]) + Self::from_angle(axisangle[0].clone()) } } @@ -166,8 +166,8 @@ where /// The input complex number will be normalized. Returns the norm of the complex number as well. #[inline] pub fn from_complex_and_get(q: Complex) -> (Self, T) { - let norm = (q.im * q.im + q.re * q.re).simd_sqrt(); - (Self::new_unchecked(q / norm), norm) + let norm = (q.im.clone() * q.im.clone() + q.re.clone() * q.re.clone()).simd_sqrt(); + (Self::new_unchecked(q / norm.clone()), norm) } /// Builds the unit complex number from the corresponding 2D rotation matrix. @@ -182,7 +182,7 @@ where // TODO: add UnitComplex::from(...) instead? #[inline] pub fn from_rotation_matrix(rotmat: &Rotation2) -> Self { - Self::new_unchecked(Complex::new(rotmat[(0, 0)], rotmat[(1, 0)])) + Self::new_unchecked(Complex::new(rotmat[(0, 0)].clone(), rotmat[(1, 0)].clone())) } /// Builds a rotation from a basis assumed to be orthonormal. @@ -410,7 +410,7 @@ where #[inline] fn sample<'a, R: Rng + ?Sized>(&self, rng: &mut R) -> UnitComplex { let x = rng.sample(rand_distr::UnitCircle); - UnitComplex::new_unchecked(Complex::new(x[0], x[1])) + UnitComplex::new_unchecked(Complex::new(x[0].clone(), x[1].clone())) } } diff --git a/src/geometry/unit_complex_conversion.rs b/src/geometry/unit_complex_conversion.rs index 04fb41ac..c98c9fb5 100644 --- a/src/geometry/unit_complex_conversion.rs +++ b/src/geometry/unit_complex_conversion.rs @@ -121,7 +121,7 @@ where { #[inline] fn to_superset(&self) -> Transform { - Transform::from_matrix_unchecked(self.to_homogeneous().to_superset()) + Transform::from_matrix_unchecked(self.clone().to_homogeneous().to_superset()) } #[inline] @@ -138,7 +138,7 @@ where impl> SubsetOf> for UnitComplex { #[inline] fn to_superset(&self) -> Matrix3 { - self.to_homogeneous().to_superset() + self.clone().to_homogeneous().to_superset() } #[inline] diff --git a/src/geometry/unit_complex_ops.rs b/src/geometry/unit_complex_ops.rs index efa91a95..a2d9f0da 100644 --- a/src/geometry/unit_complex_ops.rs +++ b/src/geometry/unit_complex_ops.rs @@ -255,9 +255,9 @@ complex_op_impl_all!( [ref val] => self * &rhs; [val ref] => &self * rhs; [ref ref] => { - let i = self.as_ref().im; - let r = self.as_ref().re; - Vector2::new(r * rhs[0] - i * rhs[1], i * rhs[0] + r * rhs[1]) + let i = self.as_ref().im.clone(); + let r = self.as_ref().re.clone(); + Vector2::new(r.clone() * rhs[0].clone() - i.clone() * rhs[1].clone(), i * rhs[0].clone() + r * rhs[1].clone()) }; ); @@ -306,9 +306,9 @@ complex_op_impl_all!( self: UnitComplex, rhs: Translation, Output = Isometry, 2>; [val val] => Isometry::from_parts(Translation::from(&self * rhs.vector), self); - [ref val] => Isometry::from_parts(Translation::from( self * rhs.vector), *self); + [ref val] => Isometry::from_parts(Translation::from( self * rhs.vector), self.clone()); [val ref] => Isometry::from_parts(Translation::from(&self * &rhs.vector), self); - [ref ref] => Isometry::from_parts(Translation::from( self * &rhs.vector), *self); + [ref ref] => Isometry::from_parts(Translation::from( self * &rhs.vector), self.clone()); ); // Translation × UnitComplex @@ -318,9 +318,9 @@ complex_op_impl_all!( self: Translation, right: UnitComplex, Output = Isometry, 2>; [val val] => Isometry::from_parts(self, right); - [ref val] => Isometry::from_parts(*self, right); - [val ref] => Isometry::from_parts(self, *right); - [ref ref] => 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()); ); // UnitComplex ×= UnitComplex @@ -330,7 +330,7 @@ where { #[inline] fn mul_assign(&mut self, rhs: UnitComplex) { - *self = *self * rhs + *self = self.clone() * rhs } } @@ -340,7 +340,7 @@ where { #[inline] fn mul_assign(&mut self, rhs: &'b UnitComplex) { - *self = *self * rhs + *self = self.clone() * rhs } } @@ -351,7 +351,7 @@ where { #[inline] fn div_assign(&mut self, rhs: UnitComplex) { - *self = *self / rhs + *self = self.clone() / rhs } } @@ -361,7 +361,7 @@ where { #[inline] fn div_assign(&mut self, rhs: &'b UnitComplex) { - *self = *self / rhs + *self = self.clone() / rhs } } @@ -372,7 +372,7 @@ where { #[inline] fn mul_assign(&mut self, rhs: Rotation) { - *self = *self * rhs + *self = self.clone() * rhs } } @@ -382,7 +382,7 @@ where { #[inline] fn mul_assign(&mut self, rhs: &'b Rotation) { - *self = *self * rhs + *self = self.clone() * rhs } } @@ -393,7 +393,7 @@ where { #[inline] fn div_assign(&mut self, rhs: Rotation) { - *self = *self / rhs + *self = self.clone() / rhs } } @@ -403,7 +403,7 @@ where { #[inline] fn div_assign(&mut self, rhs: &'b Rotation) { - *self = *self / rhs + *self = self.clone() / rhs } } @@ -424,7 +424,7 @@ where { #[inline] fn mul_assign(&mut self, rhs: &'b UnitComplex) { - self.mul_assign(rhs.to_rotation_matrix()) + self.mul_assign(rhs.clone().to_rotation_matrix()) } } @@ -445,6 +445,6 @@ where { #[inline] fn div_assign(&mut self, rhs: &'b UnitComplex) { - self.div_assign(rhs.to_rotation_matrix()) + self.div_assign(rhs.clone().to_rotation_matrix()) } } diff --git a/src/lib.rs b/src/lib.rs index 5fc38070..5ce5cb18 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -390,7 +390,7 @@ pub fn center( p1: &Point, p2: &Point, ) -> Point { - ((p1.coords + p2.coords) * convert::<_, T>(0.5)).into() + ((&p1.coords + &p2.coords) * convert::<_, T>(0.5)).into() } /// The distance between two points. @@ -404,7 +404,7 @@ pub fn distance( p1: &Point, p2: &Point, ) -> T::SimdRealField { - (p2.coords - p1.coords).norm() + (&p2.coords - &p1.coords).norm() } /// The squared distance between two points. @@ -418,7 +418,7 @@ pub fn distance_squared( p1: &Point, p2: &Point, ) -> T::SimdRealField { - (p2.coords - p1.coords).norm_squared() + (&p2.coords - &p1.coords).norm_squared() } /* diff --git a/src/linalg/balancing.rs b/src/linalg/balancing.rs index 15679e2b..4be9ba9f 100644 --- a/src/linalg/balancing.rs +++ b/src/linalg/balancing.rs @@ -31,33 +31,33 @@ where let mut n_row = matrix.row(i).norm_squared(); let mut f = T::one(); - let s = n_col + n_row; + let s = n_col.clone() + n_row.clone(); n_col = n_col.sqrt(); n_row = n_row.sqrt(); - if n_col.is_zero() || n_row.is_zero() { + if n_col.clone().is_zero() || n_row.clone().is_zero() { continue; } - while n_col < n_row / radix { - n_col *= radix; - n_row /= radix; - f *= radix; + while n_col.clone() < n_row.clone() / radix.clone() { + n_col *= radix.clone(); + n_row /= radix.clone(); + f *= radix.clone(); } - while n_col >= n_row * radix { - n_col /= radix; - n_row *= radix; - f /= radix; + while n_col.clone() >= n_row.clone() * radix.clone() { + n_col /= radix.clone(); + n_row *= radix.clone(); + f /= radix.clone(); } let eps: T = crate::convert(0.95); #[allow(clippy::suspicious_operation_groupings)] - if n_col * n_col + n_row * n_row < eps * s { + if n_col.clone() * n_col + n_row.clone() * n_row < eps * s { converged = false; - d[i] *= f; - matrix.column_mut(i).mul_assign(f); - matrix.row_mut(i).div_assign(f); + d[i] *= f.clone(); + matrix.column_mut(i).mul_assign(f.clone()); + matrix.row_mut(i).div_assign(f.clone()); } } } @@ -75,10 +75,10 @@ where for j in 0..d.len() { let mut col = m.column_mut(j); - let denom = T::one() / d[j]; + let denom = T::one() / d[j].clone(); for i in 0..d.len() { - col[i] *= d[i] * denom; + col[i] *= d[i].clone() * denom.clone(); } } } diff --git a/src/linalg/bidiagonal.rs b/src/linalg/bidiagonal.rs index e269b4a0..c6b02975 100644 --- a/src/linalg/bidiagonal.rs +++ b/src/linalg/bidiagonal.rs @@ -195,11 +195,19 @@ where let d = nrows.min(ncols); let mut res = OMatrix::identity_generic(d, d); - res.set_partial_diagonal(self.diagonal.iter().map(|e| T::from_real(e.modulus()))); + res.set_partial_diagonal( + self.diagonal + .iter() + .map(|e| T::from_real(e.clone().modulus())), + ); let start = self.axis_shift(); res.slice_mut(start, (d.value() - 1, d.value() - 1)) - .set_partial_diagonal(self.off_diagonal.iter().map(|e| T::from_real(e.modulus()))); + .set_partial_diagonal( + self.off_diagonal + .iter() + .map(|e| T::from_real(e.clone().modulus())), + ); res } @@ -225,9 +233,9 @@ where let mut res_rows = res.slice_range_mut(i + shift.., i..); let sign = if self.upper_diagonal { - self.diagonal[i].signum() + self.diagonal[i].clone().signum() } else { - self.off_diagonal[i].signum() + self.off_diagonal[i].clone().signum() }; refl.reflect_with_sign(&mut res_rows, sign); @@ -261,9 +269,9 @@ where let mut res_rows = res.slice_range_mut(i.., i + shift..); let sign = if self.upper_diagonal { - self.off_diagonal[i].signum() + self.off_diagonal[i].clone().signum() } else { - self.diagonal[i].signum() + self.diagonal[i].clone().signum() }; refl.reflect_rows_with_sign(&mut res_rows, &mut work.rows_range_mut(i..), sign); diff --git a/src/linalg/cholesky.rs b/src/linalg/cholesky.rs index 47939311..51da364f 100644 --- a/src/linalg/cholesky.rs +++ b/src/linalg/cholesky.rs @@ -52,7 +52,7 @@ where for j in 0..n { for k in 0..j { - let factor = unsafe { -*matrix.get_unchecked((j, k)) }; + let factor = unsafe { -matrix.get_unchecked((j, k)).clone() }; let (mut col_j, col_k) = matrix.columns_range_pair_mut(j, k); let mut col_j = col_j.rows_range_mut(j..); @@ -60,11 +60,11 @@ where col_j.axpy(factor.simd_conjugate(), &col_k, T::one()); } - let diag = unsafe { *matrix.get_unchecked((j, j)) }; + let diag = unsafe { matrix.get_unchecked((j, j)).clone() }; let denom = diag.simd_sqrt(); unsafe { - *matrix.get_unchecked_mut((j, j)) = denom; + *matrix.get_unchecked_mut((j, j)) = denom.clone(); } let mut col = matrix.slice_range_mut(j + 1.., j); @@ -149,7 +149,7 @@ where let dim = self.chol.nrows(); let mut prod_diag = T::one(); for i in 0..dim { - prod_diag *= unsafe { *self.chol.get_unchecked((i, i)) }; + prod_diag *= unsafe { self.chol.get_unchecked((i, i)).clone() }; } prod_diag.simd_modulus_squared() } @@ -170,7 +170,7 @@ where for j in 0..n { for k in 0..j { - let factor = unsafe { -*matrix.get_unchecked((j, k)) }; + let factor = unsafe { -matrix.get_unchecked((j, k)).clone() }; let (mut col_j, col_k) = matrix.columns_range_pair_mut(j, k); let mut col_j = col_j.rows_range_mut(j..); @@ -179,11 +179,11 @@ where col_j.axpy(factor.conjugate(), &col_k, T::one()); } - let diag = unsafe { *matrix.get_unchecked((j, j)) }; + let diag = unsafe { matrix.get_unchecked((j, j)).clone() }; if !diag.is_zero() { if let Some(denom) = diag.try_sqrt() { unsafe { - *matrix.get_unchecked_mut((j, j)) = denom; + *matrix.get_unchecked_mut((j, j)) = denom.clone(); } let mut col = matrix.slice_range_mut(j + 1.., j); @@ -254,7 +254,7 @@ where // update the jth row let top_left_corner = self.chol.slice_range(..j, ..j); - let col_j = col[j]; + let col_j = col[j].clone(); let (mut new_rowj_adjoint, mut new_colj) = col.rows_range_pair_mut(..j, j + 1..); assert!( top_left_corner.solve_lower_triangular_mut(&mut new_rowj_adjoint), @@ -265,13 +265,13 @@ where // update the center element let center_element = T::sqrt(col_j - T::from_real(new_rowj_adjoint.norm_squared())); - chol[(j, j)] = center_element; + chol[(j, j)] = center_element.clone(); // update the jth column let bottom_left_corner = self.chol.slice_range(j.., ..j); // new_colj = (col_jplus - bottom_left_corner * new_rowj.adjoint()) / center_element; new_colj.gemm( - -T::one() / center_element, + -T::one() / center_element.clone(), &bottom_left_corner, &new_rowj_adjoint, T::one() / center_element, @@ -353,23 +353,23 @@ where for j in 0..n { // updates the diagonal - let diag = T::real(unsafe { *chol.get_unchecked((j, j)) }); - let diag2 = diag * diag; - let xj = unsafe { *x.get_unchecked(j) }; - let sigma_xj2 = sigma * T::modulus_squared(xj); - let gamma = diag2 * beta + sigma_xj2; - let new_diag = (diag2 + sigma_xj2 / beta).sqrt(); - unsafe { *chol.get_unchecked_mut((j, j)) = T::from_real(new_diag) }; + let diag = T::real(unsafe { chol.get_unchecked((j, j)).clone() }); + let diag2 = diag.clone() * diag.clone(); + let xj = unsafe { x.get_unchecked(j).clone() }; + let sigma_xj2 = sigma.clone() * T::modulus_squared(xj.clone()); + let gamma = diag2.clone() * beta.clone() + sigma_xj2.clone(); + let new_diag = (diag2.clone() + sigma_xj2.clone() / beta.clone()).sqrt(); + unsafe { *chol.get_unchecked_mut((j, j)) = T::from_real(new_diag.clone()) }; beta += sigma_xj2 / diag2; // updates the terms of L let mut xjplus = x.rows_range_mut(j + 1..); let mut col_j = chol.slice_range_mut(j + 1.., j); // temp_jplus -= (wj / T::from_real(diag)) * col_j; - xjplus.axpy(-xj / T::from_real(diag), &col_j, T::one()); + xjplus.axpy(-xj.clone() / T::from_real(diag.clone()), &col_j, T::one()); if gamma != crate::zero::() { // col_j = T::from_real(nljj / diag) * col_j + (T::from_real(nljj * sigma / gamma) * T::conjugate(wj)) * temp_jplus; col_j.axpy( - T::from_real(new_diag * sigma / gamma) * T::conjugate(xj), + T::from_real(new_diag.clone() * sigma.clone() / gamma) * T::conjugate(xj), &xjplus, T::from_real(new_diag / diag), ); diff --git a/src/linalg/col_piv_qr.rs b/src/linalg/col_piv_qr.rs index f5c61336..822448e3 100644 --- a/src/linalg/col_piv_qr.rs +++ b/src/linalg/col_piv_qr.rs @@ -109,7 +109,7 @@ where .col_piv_qr .rows_generic(0, nrows.min(ncols)) .upper_triangle(); - res.set_partial_diagonal(self.diag.iter().map(|e| T::from_real(e.modulus()))); + res.set_partial_diagonal(self.diag.iter().map(|e| T::from_real(e.clone().modulus()))); res } @@ -126,7 +126,7 @@ where .col_piv_qr .resize_generic(nrows.min(ncols), ncols, T::zero()); res.fill_lower_triangle(T::zero(), 1); - res.set_partial_diagonal(self.diag.iter().map(|e| T::from_real(e.modulus()))); + res.set_partial_diagonal(self.diag.iter().map(|e| T::from_real(e.clone().modulus()))); res } @@ -149,7 +149,7 @@ where let refl = Reflection::new(Unit::new_unchecked(axis), T::zero()); let mut res_rows = res.slice_range_mut(i.., i..); - refl.reflect_with_sign(&mut res_rows, self.diag[i].signum()); + refl.reflect_with_sign(&mut res_rows, self.diag[i].clone().signum()); } res @@ -195,7 +195,7 @@ where let refl = Reflection::new(Unit::new_unchecked(axis), T::zero()); let mut rhs_rows = rhs.rows_range_mut(i..); - refl.reflect_with_sign(&mut rhs_rows, self.diag[i].signum().conjugate()); + refl.reflect_with_sign(&mut rhs_rows, self.diag[i].clone().signum().conjugate()); } } } @@ -270,14 +270,14 @@ where let coeff; unsafe { - let diag = self.diag.vget_unchecked(i).modulus(); + let diag = self.diag.vget_unchecked(i).clone().modulus(); if diag.is_zero() { return false; } - coeff = b.vget_unchecked(i).unscale(diag); - *b.vget_unchecked_mut(i) = coeff; + coeff = b.vget_unchecked(i).clone().unscale(diag); + *b.vget_unchecked_mut(i) = coeff.clone(); } b.rows_range_mut(..i) @@ -337,7 +337,7 @@ where let mut res = T::one(); for i in 0..dim { - res *= unsafe { *self.diag.vget_unchecked(i) }; + res *= unsafe { self.diag.vget_unchecked(i).clone() }; } res * self.p.determinant() diff --git a/src/linalg/convolution.rs b/src/linalg/convolution.rs index 21a32dbc..2402bb3d 100644 --- a/src/linalg/convolution.rs +++ b/src/linalg/convolution.rs @@ -47,11 +47,11 @@ impl> Vector { let u_f = cmp::min(i, vec - 1); if u_i == u_f { - conv[i] += self[u_i] * kernel[(i - u_i)]; + conv[i] += self[u_i].clone() * kernel[(i - u_i)].clone(); } else { for u in u_i..(u_f + 1) { if i - u < ker { - conv[i] += self[u] * kernel[(i - u)]; + conv[i] += self[u].clone() * kernel[(i - u)].clone(); } } } @@ -97,7 +97,7 @@ impl> Vector { for i in 0..(vec - ker + 1) { for j in 0..ker { - conv[i] += self[i + j] * kernel[ker - j - 1]; + conv[i] += self[i + j].clone() * kernel[ker - j - 1].clone(); } } conv @@ -133,9 +133,9 @@ impl> Vector { let val = if i + j < 1 || i + j >= vec + 1 { zero::() } else { - self[i + j - 1] + self[i + j - 1].clone() }; - conv[i] += val * kernel[ker - j - 1]; + conv[i] += val * kernel[ker - j - 1].clone(); } } diff --git a/src/linalg/determinant.rs b/src/linalg/determinant.rs index 22b681f5..7b5d6b2c 100644 --- a/src/linalg/determinant.rs +++ b/src/linalg/determinant.rs @@ -26,30 +26,30 @@ impl, S: Storage> SquareMatri unsafe { match dim { 0 => T::one(), - 1 => *self.get_unchecked((0, 0)), + 1 => self.get_unchecked((0, 0)).clone(), 2 => { - let m11 = *self.get_unchecked((0, 0)); - let m12 = *self.get_unchecked((0, 1)); - let m21 = *self.get_unchecked((1, 0)); - let m22 = *self.get_unchecked((1, 1)); + let m11 = self.get_unchecked((0, 0)).clone(); + let m12 = self.get_unchecked((0, 1)).clone(); + let m21 = self.get_unchecked((1, 0)).clone(); + let m22 = self.get_unchecked((1, 1)).clone(); m11 * m22 - m21 * m12 } 3 => { - let m11 = *self.get_unchecked((0, 0)); - let m12 = *self.get_unchecked((0, 1)); - let m13 = *self.get_unchecked((0, 2)); + let m11 = self.get_unchecked((0, 0)).clone(); + let m12 = self.get_unchecked((0, 1)).clone(); + let m13 = self.get_unchecked((0, 2)).clone(); - let m21 = *self.get_unchecked((1, 0)); - let m22 = *self.get_unchecked((1, 1)); - let m23 = *self.get_unchecked((1, 2)); + let m21 = self.get_unchecked((1, 0)).clone(); + let m22 = self.get_unchecked((1, 1)).clone(); + let m23 = self.get_unchecked((1, 2)).clone(); - let m31 = *self.get_unchecked((2, 0)); - let m32 = *self.get_unchecked((2, 1)); - let m33 = *self.get_unchecked((2, 2)); + let m31 = self.get_unchecked((2, 0)).clone(); + let m32 = self.get_unchecked((2, 1)).clone(); + let m33 = self.get_unchecked((2, 2)).clone(); - let minor_m12_m23 = m22 * m33 - m32 * m23; - let minor_m11_m23 = m21 * m33 - m31 * m23; + let minor_m12_m23 = m22.clone() * m33.clone() - m32.clone() * m23.clone(); + let minor_m11_m23 = m21.clone() * m33.clone() - m31.clone() * m23.clone(); let minor_m11_m22 = m21 * m32 - m31 * m22; m11 * minor_m12_m23 - m12 * minor_m11_m23 + m13 * minor_m11_m22 diff --git a/src/linalg/exp.rs b/src/linalg/exp.rs index e7751af2..835730da 100644 --- a/src/linalg/exp.rs +++ b/src/linalg/exp.rs @@ -116,7 +116,7 @@ where self.calc_a4(); self.d4_exact = Some(one_norm(self.a4.as_ref().unwrap()).powf(convert(0.25))); } - self.d4_exact.unwrap() + self.d4_exact.clone().unwrap() } fn d6_tight(&mut self) -> T::RealField { @@ -124,7 +124,7 @@ where self.calc_a6(); self.d6_exact = Some(one_norm(self.a6.as_ref().unwrap()).powf(convert(1.0 / 6.0))); } - self.d6_exact.unwrap() + self.d6_exact.clone().unwrap() } fn d8_tight(&mut self) -> T::RealField { @@ -132,7 +132,7 @@ where self.calc_a8(); self.d8_exact = Some(one_norm(self.a8.as_ref().unwrap()).powf(convert(1.0 / 8.0))); } - self.d8_exact.unwrap() + self.d8_exact.clone().unwrap() } fn d10_tight(&mut self) -> T::RealField { @@ -140,7 +140,7 @@ where self.calc_a10(); self.d10_exact = Some(one_norm(self.a10.as_ref().unwrap()).powf(convert(1.0 / 10.0))); } - self.d10_exact.unwrap() + self.d10_exact.clone().unwrap() } fn d4_loose(&mut self) -> T::RealField { @@ -149,7 +149,7 @@ where } if self.d4_exact.is_some() { - return self.d4_exact.unwrap(); + return self.d4_exact.clone().unwrap(); } if self.d4_approx.is_none() { @@ -157,7 +157,7 @@ where self.d4_approx = Some(one_norm(self.a4.as_ref().unwrap()).powf(convert(0.25))); } - self.d4_approx.unwrap() + self.d4_approx.clone().unwrap() } fn d6_loose(&mut self) -> T::RealField { @@ -166,7 +166,7 @@ where } if self.d6_exact.is_some() { - return self.d6_exact.unwrap(); + return self.d6_exact.clone().unwrap(); } if self.d6_approx.is_none() { @@ -174,7 +174,7 @@ where self.d6_approx = Some(one_norm(self.a6.as_ref().unwrap()).powf(convert(1.0 / 6.0))); } - self.d6_approx.unwrap() + self.d6_approx.clone().unwrap() } fn d8_loose(&mut self) -> T::RealField { @@ -183,7 +183,7 @@ where } if self.d8_exact.is_some() { - return self.d8_exact.unwrap(); + return self.d8_exact.clone().unwrap(); } if self.d8_approx.is_none() { @@ -191,7 +191,7 @@ where self.d8_approx = Some(one_norm(self.a8.as_ref().unwrap()).powf(convert(1.0 / 8.0))); } - self.d8_approx.unwrap() + self.d8_approx.clone().unwrap() } fn d10_loose(&mut self) -> T::RealField { @@ -200,7 +200,7 @@ where } if self.d10_exact.is_some() { - return self.d10_exact.unwrap(); + return self.d10_exact.clone().unwrap(); } if self.d10_approx.is_none() { @@ -208,15 +208,15 @@ where self.d10_approx = Some(one_norm(self.a10.as_ref().unwrap()).powf(convert(1.0 / 10.0))); } - self.d10_approx.unwrap() + self.d10_approx.clone().unwrap() } fn pade3(&mut self) -> (OMatrix, OMatrix) { let b: [T; 4] = [convert(120.0), convert(60.0), convert(12.0), convert(1.0)]; self.calc_a2(); let a2 = self.a2.as_ref().unwrap(); - let u = &self.a * (a2 * b[3] + &self.ident * b[1]); - let v = a2 * b[2] + &self.ident * b[0]; + let u = &self.a * (a2 * b[3].clone() + &self.ident * b[1].clone()); + let v = a2 * b[2].clone() + &self.ident * b[0].clone(); (u, v) } @@ -232,12 +232,12 @@ where self.calc_a2(); self.calc_a6(); let u = &self.a - * (self.a4.as_ref().unwrap() * b[5] - + self.a2.as_ref().unwrap() * b[3] - + &self.ident * b[1]); - let v = self.a4.as_ref().unwrap() * b[4] - + self.a2.as_ref().unwrap() * b[2] - + &self.ident * b[0]; + * (self.a4.as_ref().unwrap() * b[5].clone() + + self.a2.as_ref().unwrap() * b[3].clone() + + &self.ident * b[1].clone()); + let v = self.a4.as_ref().unwrap() * b[4].clone() + + self.a2.as_ref().unwrap() * b[2].clone() + + &self.ident * b[0].clone(); (u, v) } @@ -256,14 +256,14 @@ where self.calc_a4(); self.calc_a6(); let u = &self.a - * (self.a6.as_ref().unwrap() * b[7] - + self.a4.as_ref().unwrap() * b[5] - + self.a2.as_ref().unwrap() * b[3] - + &self.ident * b[1]); - let v = self.a6.as_ref().unwrap() * b[6] - + self.a4.as_ref().unwrap() * b[4] - + self.a2.as_ref().unwrap() * b[2] - + &self.ident * b[0]; + * (self.a6.as_ref().unwrap() * b[7].clone() + + self.a4.as_ref().unwrap() * b[5].clone() + + self.a2.as_ref().unwrap() * b[3].clone() + + &self.ident * b[1].clone()); + let v = self.a6.as_ref().unwrap() * b[6].clone() + + self.a4.as_ref().unwrap() * b[4].clone() + + self.a2.as_ref().unwrap() * b[2].clone() + + &self.ident * b[0].clone(); (u, v) } @@ -285,16 +285,16 @@ where self.calc_a6(); self.calc_a8(); let u = &self.a - * (self.a8.as_ref().unwrap() * b[9] - + self.a6.as_ref().unwrap() * b[7] - + self.a4.as_ref().unwrap() * b[5] - + self.a2.as_ref().unwrap() * b[3] - + &self.ident * b[1]); - let v = self.a8.as_ref().unwrap() * b[8] - + self.a6.as_ref().unwrap() * b[6] - + self.a4.as_ref().unwrap() * b[4] - + self.a2.as_ref().unwrap() * b[2] - + &self.ident * b[0]; + * (self.a8.as_ref().unwrap() * b[9].clone() + + self.a6.as_ref().unwrap() * b[7].clone() + + self.a4.as_ref().unwrap() * b[5].clone() + + self.a2.as_ref().unwrap() * b[3].clone() + + &self.ident * b[1].clone()); + let v = self.a8.as_ref().unwrap() * b[8].clone() + + self.a6.as_ref().unwrap() * b[6].clone() + + self.a4.as_ref().unwrap() * b[4].clone() + + self.a2.as_ref().unwrap() * b[2].clone() + + &self.ident * b[0].clone(); (u, v) } @@ -321,14 +321,23 @@ where self.calc_a2(); self.calc_a4(); self.calc_a6(); - let mb2 = self.a2.as_ref().unwrap() * convert::(2.0_f64.powf(-2.0 * s)); - let mb4 = self.a4.as_ref().unwrap() * convert::(2.0.powf(-4.0 * s)); + let mb2 = self.a2.as_ref().unwrap() * convert::(2.0_f64.powf(-2.0 * s.clone())); + let mb4 = self.a4.as_ref().unwrap() * convert::(2.0.powf(-4.0 * s.clone())); let mb6 = self.a6.as_ref().unwrap() * convert::(2.0.powf(-6.0 * s)); - let u2 = &mb6 * (&mb6 * b[13] + &mb4 * b[11] + &mb2 * b[9]); - let u = &mb * (&u2 + &mb6 * b[7] + &mb4 * b[5] + &mb2 * b[3] + &self.ident * b[1]); - let v2 = &mb6 * (&mb6 * b[12] + &mb4 * b[10] + &mb2 * b[8]); - let v = v2 + &mb6 * b[6] + &mb4 * b[4] + &mb2 * b[2] + &self.ident * b[0]; + let u2 = &mb6 * (&mb6 * b[13].clone() + &mb4 * b[11].clone() + &mb2 * b[9].clone()); + let u = &mb + * (&u2 + + &mb6 * b[7].clone() + + &mb4 * b[5].clone() + + &mb2 * b[3].clone() + + &self.ident * b[1].clone()); + let v2 = &mb6 * (&mb6 * b[12].clone() + &mb4 * b[10].clone() + &mb2 * b[8].clone()); + let v = v2 + + &mb6 * b[6].clone() + + &mb4 * b[4].clone() + + &mb2 * b[2].clone() + + &self.ident * b[0].clone(); (u, v) } } @@ -417,7 +426,9 @@ where let col = m.column(i); max = max.max( col.iter() - .fold(::RealField::zero(), |a, b| a + b.abs()), + .fold(::RealField::zero(), |a, b| { + a + b.clone().abs() + }), ); } diff --git a/src/linalg/full_piv_lu.rs b/src/linalg/full_piv_lu.rs index 20033c3c..b11bf4d6 100644 --- a/src/linalg/full_piv_lu.rs +++ b/src/linalg/full_piv_lu.rs @@ -67,7 +67,7 @@ where let piv = matrix.slice_range(i.., i..).icamax_full(); let row_piv = piv.0 + i; let col_piv = piv.1 + i; - let diag = matrix[(row_piv, col_piv)]; + let diag = matrix[(row_piv, col_piv)].clone(); if diag.is_zero() { // The remaining of the matrix is zero. @@ -253,10 +253,10 @@ where ); let dim = self.lu.nrows(); - let mut res = self.lu[(dim - 1, dim - 1)]; + let mut res = self.lu[(dim - 1, dim - 1)].clone(); if !res.is_zero() { for i in 0..dim - 1 { - res *= unsafe { *self.lu.get_unchecked((i, i)) }; + res *= unsafe { self.lu.get_unchecked((i, i)).clone() }; } res * self.p.determinant() * self.q.determinant() diff --git a/src/linalg/givens.rs b/src/linalg/givens.rs index 8be91fe1..c719deb6 100644 --- a/src/linalg/givens.rs +++ b/src/linalg/givens.rs @@ -42,12 +42,12 @@ impl GivensRotation { /// Initializes a Givens rotation form its non-normalized cosine an sine components. pub fn try_new(c: T, s: T, eps: T::RealField) -> Option<(Self, T)> { let (mod0, sign0) = c.to_exp(); - let denom = (mod0 * mod0 + s.modulus_squared()).sqrt(); + let denom = (mod0.clone() * mod0.clone() + s.clone().modulus_squared()).sqrt(); if denom > eps { - let norm = sign0.scale(denom); + let norm = sign0.scale(denom.clone()); let c = mod0 / denom; - let s = s / norm; + let s = s.clone() / norm.clone(); Some((Self { c, s }, norm)) } else { None @@ -60,10 +60,10 @@ impl GivensRotation { /// of `v` and the rotation `r` such that `R * v = [ |v|, 0.0 ]^t` where `|v|` is the norm of `v`. pub fn cancel_y>(v: &Vector) -> Option<(Self, T)> { if !v[1].is_zero() { - let (mod0, sign0) = v[0].to_exp(); - let denom = (mod0 * mod0 + v[1].modulus_squared()).sqrt(); - let c = mod0 / denom; - let s = -v[1] / sign0.scale(denom); + let (mod0, sign0) = v[0].clone().to_exp(); + let denom = (mod0.clone() * mod0.clone() + v[1].clone().modulus_squared()).sqrt(); + let c = mod0 / denom.clone(); + let s = -v[1].clone() / sign0.clone().scale(denom.clone()); let r = sign0.scale(denom); Some((Self { c, s }, r)) } else { @@ -77,10 +77,10 @@ impl GivensRotation { /// of `v` and the rotation `r` such that `R * v = [ 0.0, |v| ]^t` where `|v|` is the norm of `v`. pub fn cancel_x>(v: &Vector) -> Option<(Self, T)> { if !v[0].is_zero() { - let (mod1, sign1) = v[1].to_exp(); - let denom = (mod1 * mod1 + v[0].modulus_squared()).sqrt(); - let c = mod1 / denom; - let s = (v[0].conjugate() * sign1).unscale(denom); + let (mod1, sign1) = v[1].clone().to_exp(); + let denom = (mod1.clone() * mod1.clone() + v[0].clone().modulus_squared()).sqrt(); + let c = mod1 / denom.clone(); + let s = (v[0].clone().conjugate() * sign1.clone()).unscale(denom.clone()); let r = sign1.scale(denom); Some((Self { c, s }, r)) } else { @@ -91,21 +91,21 @@ impl GivensRotation { /// The cos part of this roration. #[must_use] pub fn c(&self) -> T::RealField { - self.c + self.c.clone() } /// The sin part of this roration. #[must_use] pub fn s(&self) -> T { - self.s + self.s.clone() } /// The inverse of this givens rotation. #[must_use = "This function does not mutate self."] pub fn inverse(&self) -> Self { Self { - c: self.c, - s: -self.s, + c: self.c.clone(), + s: -self.s.clone(), } } @@ -121,16 +121,17 @@ impl GivensRotation { 2, "Unit complex rotation: the input matrix must have exactly two rows." ); - let s = self.s; - let c = self.c; + let s = self.s.clone(); + let c = self.c.clone(); for j in 0..rhs.ncols() { unsafe { - let a = *rhs.get_unchecked((0, j)); - let b = *rhs.get_unchecked((1, j)); + let a = rhs.get_unchecked((0, j)).clone(); + let b = rhs.get_unchecked((1, j)).clone(); - *rhs.get_unchecked_mut((0, j)) = a.scale(c) - s.conjugate() * b; - *rhs.get_unchecked_mut((1, j)) = s * a + b.scale(c); + *rhs.get_unchecked_mut((0, j)) = + a.clone().scale(c.clone()) - s.clone().conjugate() * b.clone(); + *rhs.get_unchecked_mut((1, j)) = s.clone() * a + b.scale(c.clone()); } } } @@ -147,17 +148,17 @@ impl GivensRotation { 2, "Unit complex rotation: the input matrix must have exactly two columns." ); - let s = self.s; - let c = self.c; + let s = self.s.clone(); + let c = self.c.clone(); // TODO: can we optimize that to iterate on one column at a time ? for j in 0..lhs.nrows() { unsafe { - let a = *lhs.get_unchecked((j, 0)); - let b = *lhs.get_unchecked((j, 1)); + let a = lhs.get_unchecked((j, 0)).clone(); + let b = lhs.get_unchecked((j, 1)).clone(); - *lhs.get_unchecked_mut((j, 0)) = a.scale(c) + s * b; - *lhs.get_unchecked_mut((j, 1)) = -s.conjugate() * a + b.scale(c); + *lhs.get_unchecked_mut((j, 0)) = a.clone().scale(c.clone()) + s.clone() * b.clone(); + *lhs.get_unchecked_mut((j, 1)) = -s.clone().conjugate() * a + b.scale(c.clone()); } } } diff --git a/src/linalg/hessenberg.rs b/src/linalg/hessenberg.rs index 1e266b16..2f85d462 100644 --- a/src/linalg/hessenberg.rs +++ b/src/linalg/hessenberg.rs @@ -114,7 +114,11 @@ where self.hess.fill_lower_triangle(T::zero(), 2); self.hess .slice_mut((1, 0), (dim - 1, dim - 1)) - .set_partial_diagonal(self.subdiag.iter().map(|e| T::from_real(e.modulus()))); + .set_partial_diagonal( + self.subdiag + .iter() + .map(|e| T::from_real(e.clone().modulus())), + ); self.hess } @@ -129,7 +133,11 @@ where let mut res = self.hess.clone(); res.fill_lower_triangle(T::zero(), 2); res.slice_mut((1, 0), (dim - 1, dim - 1)) - .set_partial_diagonal(self.subdiag.iter().map(|e| T::from_real(e.modulus()))); + .set_partial_diagonal( + self.subdiag + .iter() + .map(|e| T::from_real(e.clone().modulus())), + ); res } diff --git a/src/linalg/householder.rs b/src/linalg/householder.rs index 6d20205d..688930a3 100644 --- a/src/linalg/householder.rs +++ b/src/linalg/householder.rs @@ -20,16 +20,16 @@ pub fn reflection_axis_mut>( column: &mut Vector, ) -> (T, bool) { let reflection_sq_norm = column.norm_squared(); - let reflection_norm = reflection_sq_norm.sqrt(); + let reflection_norm = reflection_sq_norm.clone().sqrt(); let factor; let signed_norm; unsafe { - let (modulus, sign) = column.vget_unchecked(0).to_exp(); - signed_norm = sign.scale(reflection_norm); + let (modulus, sign) = column.vget_unchecked(0).clone().to_exp(); + signed_norm = sign.scale(reflection_norm.clone()); factor = (reflection_sq_norm + modulus * reflection_norm) * crate::convert(2.0); - *column.vget_unchecked_mut(0) += signed_norm; + *column.vget_unchecked_mut(0) += signed_norm.clone(); }; if !factor.is_zero() { @@ -63,9 +63,9 @@ where if not_zero { let refl = Reflection::new(Unit::new_unchecked(axis), T::zero()); - let sign = reflection_norm.signum(); + let sign = reflection_norm.clone().signum(); if let Some(mut work) = bilateral { - refl.reflect_rows_with_sign(&mut right, &mut work, sign); + refl.reflect_rows_with_sign(&mut right, &mut work, sign.clone()); } refl.reflect_with_sign(&mut right.rows_range_mut(icol + shift..), sign.conjugate()); } @@ -101,7 +101,7 @@ where refl.reflect_rows_with_sign( &mut bottom.columns_range_mut(irow + shift..), &mut work.rows_range_mut(irow + 1..), - reflection_norm.signum().conjugate(), + reflection_norm.clone().signum().conjugate(), ); top.columns_range_mut(irow + shift..) .tr_copy_from(refl.axis()); @@ -132,7 +132,7 @@ where let refl = Reflection::new(Unit::new_unchecked(axis), T::zero()); let mut res_rows = res.slice_range_mut(i + 1.., i..); - refl.reflect_with_sign(&mut res_rows, signs[i].signum()); + refl.reflect_with_sign(&mut res_rows, signs[i].clone().signum()); } res diff --git a/src/linalg/inverse.rs b/src/linalg/inverse.rs index 28b148a1..f07be14a 100644 --- a/src/linalg/inverse.rs +++ b/src/linalg/inverse.rs @@ -40,7 +40,7 @@ impl> SquareMatrix { match dim { 0 => true, 1 => { - let determinant = *self.get_unchecked((0, 0)); + let determinant = self.get_unchecked((0, 0)).clone(); if determinant.is_zero() { false } else { @@ -49,58 +49,66 @@ impl> SquareMatrix { } } 2 => { - let m11 = *self.get_unchecked((0, 0)); - let m12 = *self.get_unchecked((0, 1)); - let m21 = *self.get_unchecked((1, 0)); - let m22 = *self.get_unchecked((1, 1)); + let m11 = self.get_unchecked((0, 0)).clone(); + let m12 = self.get_unchecked((0, 1)).clone(); + let m21 = self.get_unchecked((1, 0)).clone(); + let m22 = self.get_unchecked((1, 1)).clone(); - let determinant = m11 * m22 - m21 * m12; + let determinant = m11.clone() * m22.clone() - m21.clone() * m12.clone(); if determinant.is_zero() { false } else { - *self.get_unchecked_mut((0, 0)) = m22 / determinant; - *self.get_unchecked_mut((0, 1)) = -m12 / determinant; + *self.get_unchecked_mut((0, 0)) = m22 / determinant.clone(); + *self.get_unchecked_mut((0, 1)) = -m12 / determinant.clone(); - *self.get_unchecked_mut((1, 0)) = -m21 / determinant; + *self.get_unchecked_mut((1, 0)) = -m21 / determinant.clone(); *self.get_unchecked_mut((1, 1)) = m11 / determinant; true } } 3 => { - let m11 = *self.get_unchecked((0, 0)); - let m12 = *self.get_unchecked((0, 1)); - let m13 = *self.get_unchecked((0, 2)); + let m11 = self.get_unchecked((0, 0)).clone(); + let m12 = self.get_unchecked((0, 1)).clone(); + let m13 = self.get_unchecked((0, 2)).clone(); - let m21 = *self.get_unchecked((1, 0)); - let m22 = *self.get_unchecked((1, 1)); - let m23 = *self.get_unchecked((1, 2)); + let m21 = self.get_unchecked((1, 0)).clone(); + let m22 = self.get_unchecked((1, 1)).clone(); + let m23 = self.get_unchecked((1, 2)).clone(); - let m31 = *self.get_unchecked((2, 0)); - let m32 = *self.get_unchecked((2, 1)); - let m33 = *self.get_unchecked((2, 2)); + let m31 = self.get_unchecked((2, 0)).clone(); + let m32 = self.get_unchecked((2, 1)).clone(); + let m33 = self.get_unchecked((2, 2)).clone(); - let minor_m12_m23 = m22 * m33 - m32 * m23; - let minor_m11_m23 = m21 * m33 - m31 * m23; - let minor_m11_m22 = m21 * m32 - m31 * m22; + let minor_m12_m23 = m22.clone() * m33.clone() - m32.clone() * m23.clone(); + let minor_m11_m23 = m21.clone() * m33.clone() - m31.clone() * m23.clone(); + let minor_m11_m22 = m21.clone() * m32.clone() - m31.clone() * m22.clone(); - let determinant = - m11 * minor_m12_m23 - m12 * minor_m11_m23 + m13 * minor_m11_m22; + let determinant = m11.clone() * minor_m12_m23.clone() + - m12.clone() * minor_m11_m23.clone() + + m13.clone() * minor_m11_m22.clone(); if determinant.is_zero() { false } else { - *self.get_unchecked_mut((0, 0)) = minor_m12_m23 / determinant; - *self.get_unchecked_mut((0, 1)) = (m13 * m32 - m33 * m12) / determinant; - *self.get_unchecked_mut((0, 2)) = (m12 * m23 - m22 * m13) / determinant; + *self.get_unchecked_mut((0, 0)) = minor_m12_m23 / determinant.clone(); + *self.get_unchecked_mut((0, 1)) = (m13.clone() * m32.clone() + - m33.clone() * m12.clone()) + / determinant.clone(); + *self.get_unchecked_mut((0, 2)) = (m12.clone() * m23.clone() + - m22.clone() * m13.clone()) + / determinant.clone(); - *self.get_unchecked_mut((1, 0)) = -minor_m11_m23 / determinant; - *self.get_unchecked_mut((1, 1)) = (m11 * m33 - m31 * m13) / determinant; - *self.get_unchecked_mut((1, 2)) = (m13 * m21 - m23 * m11) / determinant; + *self.get_unchecked_mut((1, 0)) = -minor_m11_m23 / determinant.clone(); + *self.get_unchecked_mut((1, 1)) = + (m11.clone() * m33 - m31.clone() * m13.clone()) / determinant.clone(); + *self.get_unchecked_mut((1, 2)) = + (m13 * m21.clone() - m23 * m11.clone()) / determinant.clone(); - *self.get_unchecked_mut((2, 0)) = minor_m11_m22 / determinant; - *self.get_unchecked_mut((2, 1)) = (m12 * m31 - m32 * m11) / determinant; + *self.get_unchecked_mut((2, 0)) = minor_m11_m22 / determinant.clone(); + *self.get_unchecked_mut((2, 1)) = + (m12.clone() * m31 - m32 * m11.clone()) / determinant.clone(); *self.get_unchecked_mut((2, 2)) = (m11 * m22 - m21 * m12) / determinant; true @@ -129,94 +137,129 @@ where { let m = m.as_slice(); - out[(0, 0)] = m[5] * m[10] * m[15] - m[5] * m[11] * m[14] - m[9] * m[6] * m[15] - + m[9] * m[7] * m[14] - + m[13] * m[6] * m[11] - - m[13] * m[7] * m[10]; + out[(0, 0)] = m[5].clone() * m[10].clone() * m[15].clone() + - m[5].clone() * m[11].clone() * m[14].clone() + - m[9].clone() * m[6].clone() * m[15].clone() + + m[9].clone() * m[7].clone() * m[14].clone() + + m[13].clone() * m[6].clone() * m[11].clone() + - m[13].clone() * m[7].clone() * m[10].clone(); - out[(1, 0)] = -m[1] * m[10] * m[15] + m[1] * m[11] * m[14] + m[9] * m[2] * m[15] - - m[9] * m[3] * m[14] - - m[13] * m[2] * m[11] - + m[13] * m[3] * m[10]; + out[(1, 0)] = -m[1].clone() * m[10].clone() * m[15].clone() + + m[1].clone() * m[11].clone() * m[14].clone() + + m[9].clone() * m[2].clone() * m[15].clone() + - m[9].clone() * m[3].clone() * m[14].clone() + - m[13].clone() * m[2].clone() * m[11].clone() + + m[13].clone() * m[3].clone() * m[10].clone(); - out[(2, 0)] = m[1] * m[6] * m[15] - m[1] * m[7] * m[14] - m[5] * m[2] * m[15] - + m[5] * m[3] * m[14] - + m[13] * m[2] * m[7] - - m[13] * m[3] * m[6]; + out[(2, 0)] = m[1].clone() * m[6].clone() * m[15].clone() + - m[1].clone() * m[7].clone() * m[14].clone() + - m[5].clone() * m[2].clone() * m[15].clone() + + m[5].clone() * m[3].clone() * m[14].clone() + + m[13].clone() * m[2].clone() * m[7].clone() + - m[13].clone() * m[3].clone() * m[6].clone(); - out[(3, 0)] = -m[1] * m[6] * m[11] + m[1] * m[7] * m[10] + m[5] * m[2] * m[11] - - m[5] * m[3] * m[10] - - m[9] * m[2] * m[7] - + m[9] * m[3] * m[6]; + out[(3, 0)] = -m[1].clone() * m[6].clone() * m[11].clone() + + m[1].clone() * m[7].clone() * m[10].clone() + + m[5].clone() * m[2].clone() * m[11].clone() + - m[5].clone() * m[3].clone() * m[10].clone() + - m[9].clone() * m[2].clone() * m[7].clone() + + m[9].clone() * m[3].clone() * m[6].clone(); - out[(0, 1)] = -m[4] * m[10] * m[15] + m[4] * m[11] * m[14] + m[8] * m[6] * m[15] - - m[8] * m[7] * m[14] - - m[12] * m[6] * m[11] - + m[12] * m[7] * m[10]; + out[(0, 1)] = -m[4].clone() * m[10].clone() * m[15].clone() + + m[4].clone() * m[11].clone() * m[14].clone() + + m[8].clone() * m[6].clone() * m[15].clone() + - m[8].clone() * m[7].clone() * m[14].clone() + - m[12].clone() * m[6].clone() * m[11].clone() + + m[12].clone() * m[7].clone() * m[10].clone(); - out[(1, 1)] = m[0] * m[10] * m[15] - m[0] * m[11] * m[14] - m[8] * m[2] * m[15] - + m[8] * m[3] * m[14] - + m[12] * m[2] * m[11] - - m[12] * m[3] * m[10]; + out[(1, 1)] = m[0].clone() * m[10].clone() * m[15].clone() + - m[0].clone() * m[11].clone() * m[14].clone() + - m[8].clone() * m[2].clone() * m[15].clone() + + m[8].clone() * m[3].clone() * m[14].clone() + + m[12].clone() * m[2].clone() * m[11].clone() + - m[12].clone() * m[3].clone() * m[10].clone(); - out[(2, 1)] = -m[0] * m[6] * m[15] + m[0] * m[7] * m[14] + m[4] * m[2] * m[15] - - m[4] * m[3] * m[14] - - m[12] * m[2] * m[7] - + m[12] * m[3] * m[6]; + out[(2, 1)] = -m[0].clone() * m[6].clone() * m[15].clone() + + m[0].clone() * m[7].clone() * m[14].clone() + + m[4].clone() * m[2].clone() * m[15].clone() + - m[4].clone() * m[3].clone() * m[14].clone() + - m[12].clone() * m[2].clone() * m[7].clone() + + m[12].clone() * m[3].clone() * m[6].clone(); - out[(3, 1)] = m[0] * m[6] * m[11] - m[0] * m[7] * m[10] - m[4] * m[2] * m[11] - + m[4] * m[3] * m[10] - + m[8] * m[2] * m[7] - - m[8] * m[3] * m[6]; + out[(3, 1)] = m[0].clone() * m[6].clone() * m[11].clone() + - m[0].clone() * m[7].clone() * m[10].clone() + - m[4].clone() * m[2].clone() * m[11].clone() + + m[4].clone() * m[3].clone() * m[10].clone() + + m[8].clone() * m[2].clone() * m[7].clone() + - m[8].clone() * m[3].clone() * m[6].clone(); - out[(0, 2)] = m[4] * m[9] * m[15] - m[4] * m[11] * m[13] - m[8] * m[5] * m[15] - + m[8] * m[7] * m[13] - + m[12] * m[5] * m[11] - - m[12] * m[7] * m[9]; + out[(0, 2)] = m[4].clone() * m[9].clone() * m[15].clone() + - m[4].clone() * m[11].clone() * m[13].clone() + - m[8].clone() * m[5].clone() * m[15].clone() + + m[8].clone() * m[7].clone() * m[13].clone() + + m[12].clone() * m[5].clone() * m[11].clone() + - m[12].clone() * m[7].clone() * m[9].clone(); - out[(1, 2)] = -m[0] * m[9] * m[15] + m[0] * m[11] * m[13] + m[8] * m[1] * m[15] - - m[8] * m[3] * m[13] - - m[12] * m[1] * m[11] - + m[12] * m[3] * m[9]; + out[(1, 2)] = -m[0].clone() * m[9].clone() * m[15].clone() + + m[0].clone() * m[11].clone() * m[13].clone() + + m[8].clone() * m[1].clone() * m[15].clone() + - m[8].clone() * m[3].clone() * m[13].clone() + - m[12].clone() * m[1].clone() * m[11].clone() + + m[12].clone() * m[3].clone() * m[9].clone(); - out[(2, 2)] = m[0] * m[5] * m[15] - m[0] * m[7] * m[13] - m[4] * m[1] * m[15] - + m[4] * m[3] * m[13] - + m[12] * m[1] * m[7] - - m[12] * m[3] * m[5]; + out[(2, 2)] = m[0].clone() * m[5].clone() * m[15].clone() + - m[0].clone() * m[7].clone() * m[13].clone() + - m[4].clone() * m[1].clone() * m[15].clone() + + m[4].clone() * m[3].clone() * m[13].clone() + + m[12].clone() * m[1].clone() * m[7].clone() + - m[12].clone() * m[3].clone() * m[5].clone(); - out[(0, 3)] = -m[4] * m[9] * m[14] + m[4] * m[10] * m[13] + m[8] * m[5] * m[14] - - m[8] * m[6] * m[13] - - m[12] * m[5] * m[10] - + m[12] * m[6] * m[9]; + out[(0, 3)] = -m[4].clone() * m[9].clone() * m[14].clone() + + m[4].clone() * m[10].clone() * m[13].clone() + + m[8].clone() * m[5].clone() * m[14].clone() + - m[8].clone() * m[6].clone() * m[13].clone() + - m[12].clone() * m[5].clone() * m[10].clone() + + m[12].clone() * m[6].clone() * m[9].clone(); - out[(3, 2)] = -m[0] * m[5] * m[11] + m[0] * m[7] * m[9] + m[4] * m[1] * m[11] - - m[4] * m[3] * m[9] - - m[8] * m[1] * m[7] - + m[8] * m[3] * m[5]; + out[(3, 2)] = -m[0].clone() * m[5].clone() * m[11].clone() + + m[0].clone() * m[7].clone() * m[9].clone() + + m[4].clone() * m[1].clone() * m[11].clone() + - m[4].clone() * m[3].clone() * m[9].clone() + - m[8].clone() * m[1].clone() * m[7].clone() + + m[8].clone() * m[3].clone() * m[5].clone(); - out[(1, 3)] = m[0] * m[9] * m[14] - m[0] * m[10] * m[13] - m[8] * m[1] * m[14] - + m[8] * m[2] * m[13] - + m[12] * m[1] * m[10] - - m[12] * m[2] * m[9]; + out[(1, 3)] = m[0].clone() * m[9].clone() * m[14].clone() + - m[0].clone() * m[10].clone() * m[13].clone() + - m[8].clone() * m[1].clone() * m[14].clone() + + m[8].clone() * m[2].clone() * m[13].clone() + + m[12].clone() * m[1].clone() * m[10].clone() + - m[12].clone() * m[2].clone() * m[9].clone(); - out[(2, 3)] = -m[0] * m[5] * m[14] + m[0] * m[6] * m[13] + m[4] * m[1] * m[14] - - m[4] * m[2] * m[13] - - m[12] * m[1] * m[6] - + m[12] * m[2] * m[5]; + out[(2, 3)] = -m[0].clone() * m[5].clone() * m[14].clone() + + m[0].clone() * m[6].clone() * m[13].clone() + + m[4].clone() * m[1].clone() * m[14].clone() + - m[4].clone() * m[2].clone() * m[13].clone() + - m[12].clone() * m[1].clone() * m[6].clone() + + m[12].clone() * m[2].clone() * m[5].clone(); - out[(3, 3)] = m[0] * m[5] * m[10] - m[0] * m[6] * m[9] - m[4] * m[1] * m[10] - + m[4] * m[2] * m[9] - + m[8] * m[1] * m[6] - - m[8] * m[2] * m[5]; + out[(3, 3)] = m[0].clone() * m[5].clone() * m[10].clone() + - m[0].clone() * m[6].clone() * m[9].clone() + - m[4].clone() * m[1].clone() * m[10].clone() + + m[4].clone() * m[2].clone() * m[9].clone() + + m[8].clone() * m[1].clone() * m[6].clone() + - m[8].clone() * m[2].clone() * m[5].clone(); - let det = m[0] * out[(0, 0)] + m[1] * out[(0, 1)] + m[2] * out[(0, 2)] + m[3] * out[(0, 3)]; + let det = m[0].clone() * out[(0, 0)].clone() + + m[1].clone() * out[(0, 1)].clone() + + m[2].clone() * out[(0, 2)].clone() + + m[3].clone() * out[(0, 3)].clone(); if !det.is_zero() { let inv_det = T::one() / det; for j in 0..4 { for i in 0..4 { - out[(i, j)] *= inv_det; + out[(i, j)] *= inv_det.clone(); } } true diff --git a/src/linalg/lu.rs b/src/linalg/lu.rs index 0e3be559..b0fa065d 100644 --- a/src/linalg/lu.rs +++ b/src/linalg/lu.rs @@ -65,7 +65,7 @@ where for i in 0..dim { let piv = matrix.slice_range(i.., i).icamax() + i; - let diag = matrix[(piv, i)]; + let diag = matrix[(piv, i)].clone(); if diag.is_zero() { return false; @@ -101,7 +101,7 @@ where for i in 0..min_nrows_ncols.value() { let piv = matrix.slice_range(i.., i).icamax() + i; - let diag = matrix[(piv, i)]; + let diag = matrix[(piv, i)].clone(); if diag.is_zero() { // No non-zero entries on this column. @@ -306,7 +306,7 @@ where let mut res = T::one(); for i in 0..dim { - res *= unsafe { *self.lu.get_unchecked((i, i)) }; + res *= unsafe { self.lu.get_unchecked((i, i)).clone() }; } res * self.p.determinant() @@ -351,7 +351,7 @@ where for k in 0..pivot_row.ncols() { down.column_mut(k) - .axpy(-pivot_row[k].inlined_clone(), &coeffs, T::one()); + .axpy(-pivot_row[k].clone(), &coeffs, T::one()); } } @@ -383,6 +383,6 @@ pub fn gauss_step_swap( for k in 0..pivot_row.ncols() { mem::swap(&mut pivot_row[k], &mut down[(piv - 1, k)]); down.column_mut(k) - .axpy(-pivot_row[k].inlined_clone(), &coeffs, T::one()); + .axpy(-pivot_row[k].clone(), &coeffs, T::one()); } } diff --git a/src/linalg/qr.rs b/src/linalg/qr.rs index e2f8e0c3..5839f270 100644 --- a/src/linalg/qr.rs +++ b/src/linalg/qr.rs @@ -83,7 +83,7 @@ where { let (nrows, ncols) = self.qr.shape_generic(); let mut res = self.qr.rows_generic(0, nrows.min(ncols)).upper_triangle(); - res.set_partial_diagonal(self.diag.iter().map(|e| T::from_real(e.modulus()))); + res.set_partial_diagonal(self.diag.iter().map(|e| T::from_real(e.clone().modulus()))); res } @@ -98,7 +98,7 @@ where let (nrows, ncols) = self.qr.shape_generic(); let mut res = self.qr.resize_generic(nrows.min(ncols), ncols, T::zero()); res.fill_lower_triangle(T::zero(), 1); - res.set_partial_diagonal(self.diag.iter().map(|e| T::from_real(e.modulus()))); + res.set_partial_diagonal(self.diag.iter().map(|e| T::from_real(e.clone().modulus()))); res } @@ -121,7 +121,7 @@ where let refl = Reflection::new(Unit::new_unchecked(axis), T::zero()); let mut res_rows = res.slice_range_mut(i.., i..); - refl.reflect_with_sign(&mut res_rows, self.diag[i].signum()); + refl.reflect_with_sign(&mut res_rows, self.diag[i].clone().signum()); } res @@ -160,7 +160,7 @@ where let refl = Reflection::new(Unit::new_unchecked(axis), T::zero()); let mut rhs_rows = rhs.rows_range_mut(i..); - refl.reflect_with_sign(&mut rhs_rows, self.diag[i].signum().conjugate()); + refl.reflect_with_sign(&mut rhs_rows, self.diag[i].clone().signum().conjugate()); } } } @@ -231,14 +231,14 @@ where let coeff; unsafe { - let diag = self.diag.vget_unchecked(i).modulus(); + let diag = self.diag.vget_unchecked(i).clone().modulus(); if diag.is_zero() { return false; } - coeff = b.vget_unchecked(i).unscale(diag); - *b.vget_unchecked_mut(i) = coeff; + coeff = b.vget_unchecked(i).clone().unscale(diag); + *b.vget_unchecked_mut(i) = coeff.clone(); } b.rows_range_mut(..i) diff --git a/src/linalg/schur.rs b/src/linalg/schur.rs index 953e9953..c7753cee 100644 --- a/src/linalg/schur.rs +++ b/src/linalg/schur.rs @@ -111,7 +111,7 @@ where } let amax_m = m.camax(); - m.unscale_mut(amax_m); + m.unscale_mut(amax_m.clone()); let hess = Hessenberg::new_with_workspace(m, work); let mut q; @@ -130,7 +130,7 @@ where // Implicit double-shift QR method. let mut niter = 0; - let (mut start, mut end) = Self::delimit_subproblem(&mut t, eps, dim.value() - 1); + let (mut start, mut end) = Self::delimit_subproblem(&mut t, eps.clone(), dim.value() - 1); while end != start { let subdim = end - start + 1; @@ -139,23 +139,23 @@ where let m = end - 1; let n = end; - let h11 = t[(start, start)]; - let h12 = t[(start, start + 1)]; - let h21 = t[(start + 1, start)]; - let h22 = t[(start + 1, start + 1)]; - let h32 = t[(start + 2, start + 1)]; + let h11 = t[(start, start)].clone(); + let h12 = t[(start, start + 1)].clone(); + let h21 = t[(start + 1, start)].clone(); + let h22 = t[(start + 1, start + 1)].clone(); + let h32 = t[(start + 2, start + 1)].clone(); - let hnn = t[(n, n)]; - let hmm = t[(m, m)]; - let hnm = t[(n, m)]; - let hmn = t[(m, n)]; + let hnn = t[(n, n)].clone(); + let hmm = t[(m, m)].clone(); + let hnm = t[(n, m)].clone(); + let hmn = t[(m, n)].clone(); - let tra = hnn + hmm; + let tra = hnn.clone() + hmm.clone(); let det = hnn * hmm - hnm * hmn; let mut axis = Vector3::new( - h11 * h11 + h12 * h21 - tra * h11 + det, - h21 * (h11 + h22 - tra), + h11.clone() * h11.clone() + h12 * h21.clone() - tra.clone() * h11.clone() + det, + h21.clone() * (h11 + h22 - tra), h21 * h32, ); @@ -169,7 +169,7 @@ where t[(k + 2, k - 1)] = T::zero(); } - let refl = Reflection::new(Unit::new_unchecked(axis), T::zero()); + let refl = Reflection::new(Unit::new_unchecked(axis.clone()), T::zero()); { let krows = cmp::min(k + 4, end + 1); @@ -192,15 +192,15 @@ where } } - axis.x = t[(k + 1, k)]; - axis.y = t[(k + 2, k)]; + axis.x = t[(k + 1, k)].clone(); + axis.y = t[(k + 2, k)].clone(); if k < n - 2 { - axis.z = t[(k + 3, k)]; + axis.z = t[(k + 3, k)].clone(); } } - let mut axis = Vector2::new(axis.x, axis.y); + let mut axis = Vector2::new(axis.x.clone(), axis.y.clone()); let (norm, not_zero) = householder::reflection_axis_mut(&mut axis); if not_zero { @@ -254,7 +254,7 @@ where } } - let sub = Self::delimit_subproblem(&mut t, eps, end); + let sub = Self::delimit_subproblem(&mut t, eps.clone(), end); start = sub.0; end = sub.1; @@ -279,7 +279,7 @@ where let n = m + 1; if t[(n, m)].is_zero() { - out[m] = t[(m, m)]; + out[m] = t[(m, m)].clone(); m += 1; } else { // Complex eigenvalue. @@ -288,7 +288,7 @@ where } if m == dim - 1 { - out[m] = t[(m, m)]; + out[m] = t[(m, m)].clone(); } true @@ -307,33 +307,36 @@ where let n = m + 1; if t[(n, m)].is_zero() { - out[m] = MaybeUninit::new(NumComplex::new(t[(m, m)], T::zero())); + out[m] = MaybeUninit::new(NumComplex::new(t[(m, m)].clone(), T::zero())); m += 1; } else { // Solve the 2x2 eigenvalue subproblem. - let hmm = t[(m, m)]; - let hnm = t[(n, m)]; - let hmn = t[(m, n)]; - let hnn = t[(n, n)]; + let hmm = t[(m, m)].clone(); + let hnm = t[(n, m)].clone(); + let hmn = t[(m, n)].clone(); + let hnn = t[(n, n)].clone(); // NOTE: use the same algorithm as in compute_2x2_eigvals. - let val = (hmm - hnn) * crate::convert(0.5); - let discr = hnm * hmn + val * val; + let val = (hmm.clone() - hnn.clone()) * crate::convert(0.5); + let discr = hnm * hmn + val.clone() * val; // All 2x2 blocks have negative discriminant because we already decoupled those // with positive eigenvalues. let sqrt_discr = NumComplex::new(T::zero(), (-discr).sqrt()); let half_tra = (hnn + hmm) * crate::convert(0.5); - out[m] = MaybeUninit::new(NumComplex::new(half_tra, T::zero()) + sqrt_discr); - out[m + 1] = MaybeUninit::new(NumComplex::new(half_tra, T::zero()) - sqrt_discr); + out[m] = MaybeUninit::new( + NumComplex::new(half_tra.clone(), T::zero()) + sqrt_discr.clone(), + ); + out[m + 1] = + MaybeUninit::new(NumComplex::new(half_tra, T::zero()) - sqrt_discr.clone()); m += 2; } } if m == dim - 1 { - out[m] = MaybeUninit::new(NumComplex::new(t[(m, m)], T::zero())); + out[m] = MaybeUninit::new(NumComplex::new(t[(m, m)].clone(), T::zero())); } } @@ -347,7 +350,9 @@ where while n > 0 { let m = n - 1; - if t[(n, m)].norm1() <= eps * (t[(n, n)].norm1() + t[(m, m)].norm1()) { + if t[(n, m)].clone().norm1() + <= eps.clone() * (t[(n, n)].clone().norm1() + t[(m, m)].clone().norm1()) + { t[(n, m)] = T::zero(); } else { break; @@ -364,9 +369,11 @@ where while new_start > 0 { let m = new_start - 1; - let off_diag = t[(new_start, m)]; + let off_diag = t[(new_start, m)].clone(); if off_diag.is_zero() - || off_diag.norm1() <= eps * (t[(new_start, new_start)].norm1() + t[(m, m)].norm1()) + || off_diag.norm1() + <= eps.clone() + * (t[(new_start, new_start)].clone().norm1() + t[(m, m)].clone().norm1()) { t[(new_start, m)] = T::zero(); break; @@ -435,7 +442,7 @@ where q = Some(OMatrix::from_column_slice_generic( dim, dim, - &[c, rot.s(), -rot.s().conjugate(), c], + &[c.clone(), rot.s(), -rot.s().conjugate(), c], )); } } @@ -453,20 +460,20 @@ fn compute_2x2_eigvals>( m: &SquareMatrix, ) -> Option<(T, T)> { // Solve the 2x2 eigenvalue subproblem. - let h00 = m[(0, 0)]; - let h10 = m[(1, 0)]; - let h01 = m[(0, 1)]; - let h11 = m[(1, 1)]; + let h00 = m[(0, 0)].clone(); + let h10 = m[(1, 0)].clone(); + let h01 = m[(0, 1)].clone(); + let h11 = m[(1, 1)].clone(); // NOTE: this discriminant computation is more stable than the // one based on the trace and determinant: 0.25 * tra * tra - det // because it ensures positiveness for symmetric matrices. - let val = (h00 - h11) * crate::convert(0.5); - let discr = h10 * h01 + val * val; + let val = (h00.clone() - h11.clone()) * crate::convert(0.5); + let discr = h10 * h01 + val.clone() * val; discr.try_sqrt().map(|sqrt_discr| { let half_tra = (h00 + h11) * crate::convert(0.5); - (half_tra + sqrt_discr, half_tra - sqrt_discr) + (half_tra.clone() + sqrt_discr.clone(), half_tra - sqrt_discr) }) } @@ -478,20 +485,20 @@ fn compute_2x2_eigvals>( fn compute_2x2_basis>( m: &SquareMatrix, ) -> Option> { - let h10 = m[(1, 0)]; + let h10 = m[(1, 0)].clone(); if h10.is_zero() { return None; } if let Some((eigval1, eigval2)) = compute_2x2_eigvals(m) { - let x1 = eigval1 - m[(1, 1)]; - let x2 = eigval2 - m[(1, 1)]; + let x1 = eigval1 - m[(1, 1)].clone(); + let x2 = eigval2 - m[(1, 1)].clone(); // NOTE: Choose the one that yields a larger x component. // This is necessary for numerical stability of the normalization of the complex // number. - if x1.norm1() > x2.norm1() { + if x1.clone().norm1() > x2.clone().norm1() { Some(GivensRotation::new(x1, h10).0) } else { Some(GivensRotation::new(x2, h10).0) diff --git a/src/linalg/solve.rs b/src/linalg/solve.rs index 32221fec..7409e7fb 100644 --- a/src/linalg/solve.rs +++ b/src/linalg/solve.rs @@ -82,14 +82,14 @@ impl> SquareMatrix { let coeff; unsafe { - let diag = *self.get_unchecked((i, i)); + let diag = self.get_unchecked((i, i)).clone(); if diag.is_zero() { return false; } - coeff = *b.vget_unchecked(i) / diag; - *b.vget_unchecked_mut(i) = coeff; + coeff = b.vget_unchecked(i).clone() / diag; + *b.vget_unchecked_mut(i) = coeff.clone(); } b.rows_range_mut(i + 1..) @@ -123,7 +123,7 @@ impl> SquareMatrix { let mut bcol = b.column_mut(k); for i in 0..dim - 1 { - let coeff = unsafe { *bcol.vget_unchecked(i) } / diag; + let coeff = unsafe { bcol.vget_unchecked(i).clone() } / diag.clone(); bcol.rows_range_mut(i + 1..) .axpy(-coeff, &self.slice_range(i + 1.., i), T::one()); } @@ -164,14 +164,14 @@ impl> SquareMatrix { let coeff; unsafe { - let diag = *self.get_unchecked((i, i)); + let diag = self.get_unchecked((i, i)).clone(); if diag.is_zero() { return false; } - coeff = *b.vget_unchecked(i) / diag; - *b.vget_unchecked_mut(i) = coeff; + coeff = b.vget_unchecked(i).clone() / diag; + *b.vget_unchecked_mut(i) = coeff.clone(); } b.rows_range_mut(..i) @@ -392,13 +392,13 @@ impl> SquareMatrix { unsafe { let b_i = b.vget_unchecked_mut(i); - let diag = conjugate(*self.get_unchecked((i, i))); + let diag = conjugate(self.get_unchecked((i, i)).clone()); if diag.is_zero() { return false; } - *b_i = (*b_i - dot) / diag; + *b_i = (b_i.clone() - dot) / diag; } } @@ -426,13 +426,13 @@ impl> SquareMatrix { unsafe { let b_i = b.vget_unchecked_mut(i); - let diag = conjugate(*self.get_unchecked((i, i))); + let diag = conjugate(self.get_unchecked((i, i)).clone()); if diag.is_zero() { return false; } - *b_i = (*b_i - dot) / diag; + *b_i = (b_i.clone() - dot) / diag; } } @@ -508,13 +508,13 @@ impl> SquareMatrix { let coeff; unsafe { - let diag = *self.get_unchecked((i, i)); - coeff = *b.vget_unchecked(i) / diag; - *b.vget_unchecked_mut(i) = coeff; + let diag = self.get_unchecked((i, i)).clone(); + coeff = b.vget_unchecked(i).clone() / diag; + *b.vget_unchecked_mut(i) = coeff.clone(); } b.rows_range_mut(i + 1..) - .axpy(-coeff, &self.slice_range(i + 1.., i), T::one()); + .axpy(-coeff.clone(), &self.slice_range(i + 1.., i), T::one()); } } @@ -537,7 +537,7 @@ impl> SquareMatrix { let mut bcol = b.column_mut(k); for i in 0..dim - 1 { - let coeff = unsafe { *bcol.vget_unchecked(i) } / diag; + let coeff = unsafe { bcol.vget_unchecked(i).clone() } / diag.clone(); bcol.rows_range_mut(i + 1..) .axpy(-coeff, &self.slice_range(i + 1.., i), T::one()); } @@ -569,9 +569,9 @@ impl> SquareMatrix { let coeff; unsafe { - let diag = *self.get_unchecked((i, i)); - coeff = *b.vget_unchecked(i) / diag; - *b.vget_unchecked_mut(i) = coeff; + let diag = self.get_unchecked((i, i)).clone(); + coeff = b.vget_unchecked(i).clone() / diag; + *b.vget_unchecked_mut(i) = coeff.clone(); } b.rows_range_mut(..i) @@ -748,8 +748,8 @@ impl> SquareMatrix { unsafe { let b_i = b.vget_unchecked_mut(i); - let diag = conjugate(*self.get_unchecked((i, i))); - *b_i = (*b_i - dot) / diag; + let diag = conjugate(self.get_unchecked((i, i)).clone()); + *b_i = (b_i.clone() - dot) / diag; } } } @@ -772,8 +772,8 @@ impl> SquareMatrix { unsafe { let b_i = b.vget_unchecked_mut(i); - let diag = conjugate(*self.get_unchecked((i, i))); - *b_i = (*b_i - dot) / diag; + let diag = conjugate(self.get_unchecked((i, i)).clone()); + *b_i = (b_i.clone() - dot) / diag; } } } diff --git a/src/linalg/svd.rs b/src/linalg/svd.rs index 0b50fc9b..5f1b0112 100644 --- a/src/linalg/svd.rs +++ b/src/linalg/svd.rs @@ -118,7 +118,7 @@ where let m_amax = matrix.camax(); if !m_amax.is_zero() { - matrix.unscale_mut(m_amax); + matrix.unscale_mut(m_amax.clone()); } let bi_matrix = Bidiagonal::new(matrix); @@ -139,7 +139,7 @@ where &mut v_t, bi_matrix.is_upper_diagonal(), dim - 1, - eps, + eps.clone(), ); while end != start { @@ -153,19 +153,20 @@ where let mut vec; { - let dm = diagonal[m]; - let dn = diagonal[n]; - let fm = off_diagonal[m]; + let dm = diagonal[m].clone(); + let dn = diagonal[n].clone(); + let fm = off_diagonal[m].clone(); - let tmm = dm * dm + off_diagonal[m - 1] * off_diagonal[m - 1]; - let tmn = dm * fm; - let tnn = dn * dn + fm * fm; + let tmm = dm.clone() * dm.clone() + + off_diagonal[m - 1].clone() * off_diagonal[m - 1].clone(); + let tmn = dm * fm.clone(); + let tnn = dn.clone() * dn + fm.clone() * fm; let shift = symmetric_eigen::wilkinson_shift(tmm, tnn, tmn); vec = Vector2::new( - diagonal[start] * diagonal[start] - shift, - diagonal[start] * off_diagonal[start], + diagonal[start].clone() * diagonal[start].clone() - shift, + diagonal[start].clone() * off_diagonal[start].clone(), ); } @@ -173,15 +174,15 @@ where let m12 = if k == n - 1 { T::RealField::zero() } else { - off_diagonal[k + 1] + off_diagonal[k + 1].clone() }; let mut subm = Matrix2x3::new( - diagonal[k], - off_diagonal[k], + diagonal[k].clone(), + off_diagonal[k].clone(), T::RealField::zero(), T::RealField::zero(), - diagonal[k + 1], + diagonal[k + 1].clone(), m12, ); @@ -195,10 +196,10 @@ where off_diagonal[k - 1] = norm1; } - let v = Vector2::new(subm[(0, 0)], subm[(1, 0)]); + let v = Vector2::new(subm[(0, 0)].clone(), subm[(1, 0)].clone()); // TODO: does the case `v.y == 0` ever happen? let (rot2, norm2) = GivensRotation::cancel_y(&v) - .unwrap_or((GivensRotation::identity(), subm[(0, 0)])); + .unwrap_or((GivensRotation::identity(), subm[(0, 0)].clone())); rot2.rotate(&mut subm.fixed_columns_mut::<2>(1)); let rot2 = GivensRotation::new_unchecked(rot2.c(), T::from_real(rot2.s())); @@ -221,16 +222,16 @@ where } } - diagonal[k] = subm[(0, 0)]; - diagonal[k + 1] = subm[(1, 1)]; - off_diagonal[k] = subm[(0, 1)]; + diagonal[k] = subm[(0, 0)].clone(); + diagonal[k + 1] = subm[(1, 1)].clone(); + off_diagonal[k] = subm[(0, 1)].clone(); if k != n - 1 { - off_diagonal[k + 1] = subm[(1, 2)]; + off_diagonal[k + 1] = subm[(1, 2)].clone(); } - vec.x = subm[(0, 1)]; - vec.y = subm[(0, 2)]; + vec.x = subm[(0, 1)].clone(); + vec.y = subm[(0, 2)].clone(); } else { break; } @@ -238,9 +239,9 @@ where } else if subdim == 2 { // Solve the remaining 2x2 subproblem. let (u2, s, v2) = compute_2x2_uptrig_svd( - diagonal[start], - off_diagonal[start], - diagonal[start + 1], + diagonal[start].clone(), + off_diagonal[start].clone(), + diagonal[start + 1].clone(), compute_u && bi_matrix.is_upper_diagonal() || compute_v && !bi_matrix.is_upper_diagonal(), compute_v && bi_matrix.is_upper_diagonal() @@ -249,15 +250,15 @@ where 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()))); - diagonal[start] = s[0]; - diagonal[start + 1] = s[1]; + diagonal[start] = s[0].clone(); + diagonal[start + 1] = s[1].clone(); off_diagonal[start] = T::RealField::zero(); if let Some(ref mut u) = u { let rot = if bi_matrix.is_upper_diagonal() { - u2.unwrap() + u2.clone().unwrap() } else { - v2.unwrap() + v2.clone().unwrap() }; rot.rotate_rows(&mut u.fixed_columns_mut::<2>(start)); } @@ -282,7 +283,7 @@ where &mut v_t, bi_matrix.is_upper_diagonal(), end, - eps, + eps.clone(), ); start = sub.0; end = sub.1; @@ -297,7 +298,7 @@ where // Ensure all singular value are non-negative. for i in 0..dim { - let sval = diagonal[i]; + let sval = diagonal[i].clone(); if sval < T::RealField::zero() { diagonal[i] = -sval; @@ -345,10 +346,11 @@ where let m = n - 1; if off_diagonal[m].is_zero() - || off_diagonal[m].norm1() <= eps * (diagonal[n].norm1() + diagonal[m].norm1()) + || off_diagonal[m].clone().norm1() + <= eps.clone() * (diagonal[n].clone().norm1() + diagonal[m].clone().norm1()) { off_diagonal[m] = T::RealField::zero(); - } else if diagonal[m].norm1() <= eps { + } else if diagonal[m].clone().norm1() <= eps { diagonal[m] = T::RealField::zero(); Self::cancel_horizontal_off_diagonal_elt( diagonal, @@ -370,7 +372,7 @@ where m - 1, ); } - } else if diagonal[n].norm1() <= eps { + } else if diagonal[n].clone().norm1() <= eps { diagonal[n] = T::RealField::zero(); Self::cancel_vertical_off_diagonal_elt( diagonal, @@ -395,13 +397,14 @@ where while new_start > 0 { let m = new_start - 1; - if off_diagonal[m].norm1() <= eps * (diagonal[new_start].norm1() + diagonal[m].norm1()) + if off_diagonal[m].clone().norm1() + <= eps.clone() * (diagonal[new_start].clone().norm1() + diagonal[m].clone().norm1()) { off_diagonal[m] = T::RealField::zero(); break; } // TODO: write a test that enters this case. - else if diagonal[m].norm1() <= eps { + else if diagonal[m].clone().norm1() <= eps { diagonal[m] = T::RealField::zero(); Self::cancel_horizontal_off_diagonal_elt( diagonal, @@ -442,7 +445,7 @@ where i: usize, end: usize, ) { - let mut v = Vector2::new(off_diagonal[i], diagonal[i + 1]); + let mut v = Vector2::new(off_diagonal[i].clone(), diagonal[i + 1].clone()); off_diagonal[i] = T::RealField::zero(); for k in i..end { @@ -460,8 +463,8 @@ where } if k + 1 != end { - v.x = -rot.s().real() * off_diagonal[k + 1]; - v.y = diagonal[k + 2]; + v.x = -rot.s().real() * off_diagonal[k + 1].clone(); + v.y = diagonal[k + 2].clone(); off_diagonal[k + 1] *= rot.c(); } } else { @@ -479,7 +482,7 @@ where is_upper_diagonal: bool, i: usize, ) { - let mut v = Vector2::new(diagonal[i], off_diagonal[i]); + let mut v = Vector2::new(diagonal[i].clone(), off_diagonal[i].clone()); off_diagonal[i] = T::RealField::zero(); for k in (0..i + 1).rev() { @@ -497,8 +500,8 @@ where } if k > 0 { - v.x = diagonal[k - 1]; - v.y = rot.s().real() * off_diagonal[k - 1]; + v.x = diagonal[k - 1].clone(); + v.y = rot.s().real() * off_diagonal[k - 1].clone(); off_diagonal[k - 1] *= rot.c(); } } else { @@ -527,7 +530,7 @@ where match (self.u, self.v_t) { (Some(mut u), Some(v_t)) => { for i in 0..self.singular_values.len() { - let val = self.singular_values[i]; + let val = self.singular_values[i].clone(); u.column_mut(i).scale_mut(val); } Ok(u * v_t) @@ -551,7 +554,7 @@ where Err("SVD pseudo inverse: the epsilon must be non-negative.") } else { for i in 0..self.singular_values.len() { - let val = self.singular_values[i]; + let val = self.singular_values[i].clone(); if val > eps { self.singular_values[i] = T::RealField::one() / val; @@ -590,9 +593,9 @@ where let mut col = ut_b.column_mut(j); for i in 0..self.singular_values.len() { - let val = self.singular_values[i]; + let val = self.singular_values[i].clone(); if val > eps { - col[i] = col[i].unscale(val); + col[i] = col[i].clone().unscale(val); } else { col[i] = T::zero(); } @@ -665,33 +668,37 @@ fn compute_2x2_uptrig_svd( let two: T::RealField = crate::convert(2.0f64); let half: T::RealField = crate::convert(0.5f64); - let denom = (m11 + m22).hypot(m12) + (m11 - m22).hypot(m12); + let denom = (m11.clone() + m22.clone()).hypot(m12.clone()) + + (m11.clone() - m22.clone()).hypot(m12.clone()); // NOTE: v1 is the singular value that is the closest to m22. // This prevents cancellation issues when constructing the vector `csv` below. If we chose // otherwise, we would have v1 ~= m11 when m12 is small. This would cause catastrophic // cancellation on `v1 * v1 - m11 * m11` below. - let mut v1 = m11 * m22 * two / denom; + let mut v1 = m11.clone() * m22.clone() * two / denom.clone(); let mut v2 = half * denom; let mut u = None; let mut v_t = None; if compute_u || compute_v { - let (csv, sgn_v) = GivensRotation::new(m11 * m12, v1 * v1 - m11 * m11); - v1 *= sgn_v; + let (csv, sgn_v) = GivensRotation::new( + m11.clone() * m12.clone(), + v1.clone() * v1.clone() - m11.clone() * m11.clone(), + ); + v1 *= sgn_v.clone(); v2 *= sgn_v; if compute_v { - v_t = Some(csv); + v_t = Some(csv.clone()); } if compute_u { - let cu = (m11.scale(csv.c()) + m12 * csv.s()) / v1; - let su = (m22 * csv.s()) / v1; + let cu = (m11.scale(csv.c()) + m12 * csv.s()) / v1.clone(); + let su = (m22 * csv.s()) / v1.clone(); let (csu, sgn_u) = GivensRotation::new(cu, su); - v1 *= sgn_u; + v1 *= sgn_u.clone(); v2 *= sgn_u; u = Some(csu); } diff --git a/src/linalg/symmetric_eigen.rs b/src/linalg/symmetric_eigen.rs index 5ac6d5da..61e1d0c1 100644 --- a/src/linalg/symmetric_eigen.rs +++ b/src/linalg/symmetric_eigen.rs @@ -104,7 +104,7 @@ where let m_amax = matrix.camax(); if !m_amax.is_zero() { - matrix.unscale_mut(m_amax); + matrix.unscale_mut(m_amax.clone()); } let (mut q_mat, mut diag, mut off_diag); @@ -127,7 +127,8 @@ where } let mut niter = 0; - let (mut start, mut end) = Self::delimit_subproblem(&diag, &mut off_diag, dim - 1, eps); + let (mut start, mut end) = + Self::delimit_subproblem(&diag, &mut off_diag, dim - 1, eps.clone()); while end != start { let subdim = end - start + 1; @@ -138,8 +139,13 @@ where let n = end; let mut vec = Vector2::new( - diag[start] - wilkinson_shift(diag[m], diag[n], off_diag[m]), - off_diag[start], + diag[start].clone() + - wilkinson_shift( + diag[m].clone().clone(), + diag[n].clone(), + off_diag[m].clone().clone(), + ), + off_diag[start].clone(), ); for i in start..n { @@ -151,23 +157,23 @@ where off_diag[i - 1] = norm; } - let mii = diag[i]; - let mjj = diag[j]; - let mij = off_diag[i]; + let mii = diag[i].clone(); + let mjj = diag[j].clone(); + let mij = off_diag[i].clone(); let cc = rot.c() * rot.c(); let ss = rot.s() * rot.s(); let cs = rot.c() * rot.s(); - let b = cs * crate::convert(2.0) * mij; + let b = cs.clone() * crate::convert(2.0) * mij.clone(); - diag[i] = (cc * mii + ss * mjj) - b; - diag[j] = (ss * mii + cc * mjj) + b; + diag[i] = (cc.clone() * mii.clone() + ss.clone() * mjj.clone()) - b.clone(); + diag[j] = (ss.clone() * mii.clone() + cc.clone() * mjj.clone()) + b; off_diag[i] = cs * (mii - mjj) + mij * (cc - ss); if i != n - 1 { - vec.x = off_diag[i]; - vec.y = -rot.s() * off_diag[i + 1]; + vec.x = off_diag[i].clone(); + vec.y = -rot.s() * off_diag[i + 1].clone(); off_diag[i + 1] *= rot.c(); } @@ -180,24 +186,31 @@ where } } - if off_diag[m].norm1() <= eps * (diag[m].norm1() + diag[n].norm1()) { + if off_diag[m].clone().norm1() + <= eps.clone() * (diag[m].clone().norm1() + diag[n].clone().norm1()) + { end -= 1; } } else if subdim == 2 { let m = Matrix2::new( - diag[start], - off_diag[start].conjugate(), - off_diag[start], - diag[start + 1], + diag[start].clone(), + off_diag[start].clone().conjugate(), + off_diag[start].clone(), + diag[start + 1].clone(), ); let eigvals = m.eigenvalues().unwrap(); - let basis = Vector2::new(eigvals.x - diag[start + 1], off_diag[start]); + let basis = Vector2::new( + eigvals.x.clone() - diag[start + 1].clone(), + off_diag[start].clone(), + ); - diag[start] = eigvals[0]; - diag[start + 1] = eigvals[1]; + diag[start] = eigvals[0].clone(); + diag[start + 1] = eigvals[1].clone(); if let Some(ref mut q) = q_mat { - if let Some((rot, _)) = GivensRotation::try_new(basis.x, basis.y, eps) { + if let Some((rot, _)) = + GivensRotation::try_new(basis.x.clone(), basis.y.clone(), eps.clone()) + { let rot = GivensRotation::new_unchecked(rot.c(), T::from_real(rot.s())); rot.rotate_rows(&mut q.fixed_columns_mut::<2>(start)); } @@ -207,7 +220,7 @@ where } // Re-delimit the subproblem in case some decoupling occurred. - let sub = Self::delimit_subproblem(&diag, &mut off_diag, end, eps); + let sub = Self::delimit_subproblem(&diag, &mut off_diag, end, eps.clone()); start = sub.0; end = sub.1; @@ -238,7 +251,9 @@ where while n > 0 { let m = n - 1; - if off_diag[m].norm1() > eps * (diag[n].norm1() + diag[m].norm1()) { + if off_diag[m].clone().norm1() + > eps.clone() * (diag[n].clone().norm1() + diag[m].clone().norm1()) + { break; } @@ -253,8 +268,9 @@ where while new_start > 0 { let m = new_start - 1; - if off_diag[m].is_zero() - || off_diag[m].norm1() <= eps * (diag[new_start].norm1() + diag[m].norm1()) + if off_diag[m].clone().is_zero() + || off_diag[m].clone().norm1() + <= eps.clone() * (diag[new_start].clone().norm1() + diag[m].clone().norm1()) { off_diag[m] = T::RealField::zero(); break; @@ -273,7 +289,7 @@ where pub fn recompose(&self) -> OMatrix { let mut u_t = self.eigenvectors.clone(); for i in 0..self.eigenvalues.len() { - let val = self.eigenvalues[i]; + let val = self.eigenvalues[i].clone(); u_t.column_mut(i).scale_mut(val); } u_t.adjoint_mut(); @@ -288,11 +304,11 @@ where /// tmm tmn /// tmn tnn pub fn wilkinson_shift(tmm: T, tnn: T, tmn: T) -> T { - let sq_tmn = tmn * tmn; + let sq_tmn = tmn.clone() * tmn; if !sq_tmn.is_zero() { // We have the guarantee that the denominator won't be zero. - let d = (tmm - tnn) * crate::convert(0.5); - tnn - sq_tmn / (d + d.signum() * (d * d + sq_tmn).sqrt()) + let d = (tmm - tnn.clone()) * crate::convert(0.5); + tnn - sq_tmn.clone() / (d.clone() + d.clone().signum() * (d.clone() * d + sq_tmn).sqrt()) } else { tnn } diff --git a/src/linalg/symmetric_tridiagonal.rs b/src/linalg/symmetric_tridiagonal.rs index e071a916..742eb240 100644 --- a/src/linalg/symmetric_tridiagonal.rs +++ b/src/linalg/symmetric_tridiagonal.rs @@ -160,8 +160,8 @@ where self.tri.fill_upper_triangle(T::zero(), 2); for i in 0..self.off_diagonal.len() { - let val = T::from_real(self.off_diagonal[i].modulus()); - self.tri[(i + 1, i)] = val; + let val = T::from_real(self.off_diagonal[i].clone().modulus()); + self.tri[(i + 1, i)] = val.clone(); self.tri[(i, i + 1)] = val; } diff --git a/src/linalg/udu.rs b/src/linalg/udu.rs index 546fa95a..be4c007c 100644 --- a/src/linalg/udu.rs +++ b/src/linalg/udu.rs @@ -54,34 +54,34 @@ where let mut d = OVector::zeros_generic(n_dim, Const::<1>); let mut u = OMatrix::zeros_generic(n_dim, n_dim); - d[n - 1] = p[(n - 1, n - 1)]; + d[n - 1] = p[(n - 1, n - 1)].clone(); if d[n - 1].is_zero() { return None; } u.column_mut(n - 1) - .axpy(T::one() / d[n - 1], &p.column(n - 1), T::zero()); + .axpy(T::one() / d[n - 1].clone(), &p.column(n - 1), T::zero()); for j in (0..n - 1).rev() { - let mut d_j = d[j]; + let mut d_j = d[j].clone(); for k in j + 1..n { - d_j += d[k] * u[(j, k)].powi(2); + d_j += d[k].clone() * u[(j, k)].clone().powi(2); } - d[j] = p[(j, j)] - d_j; + d[j] = p[(j, j)].clone() - d_j; if d[j].is_zero() { return None; } for i in (0..=j).rev() { - let mut u_ij = u[(i, j)]; + let mut u_ij = u[(i, j)].clone(); for k in j + 1..n { - u_ij += d[k] * u[(j, k)] * u[(i, k)]; + u_ij += d[k].clone() * u[(j, k)].clone() * u[(i, k)].clone(); } - u[(i, j)] = (p[(i, j)] - u_ij) / d[j]; + u[(i, j)] = (p[(i, j)].clone() - u_ij) / d[j].clone(); } u[(j, j)] = T::one(); diff --git a/src/sparse/cs_matrix.rs b/src/sparse/cs_matrix.rs index bb9f50a0..14f8d41e 100644 --- a/src/sparse/cs_matrix.rs +++ b/src/sparse/cs_matrix.rs @@ -493,7 +493,7 @@ where // Permute the values too. for (i, irow) in range.clone().zip(self.data.i[range].iter().cloned()) { - self.data.vals[i] = workspace[irow].inlined_clone(); + self.data.vals[i] = workspace[irow].clone(); } } } @@ -517,11 +517,11 @@ where let curr_irow = self.data.i[idx]; if curr_irow == irow { - value += self.data.vals[idx].inlined_clone(); + value += self.data.vals[idx].clone(); } else { self.data.i[curr_i] = irow; self.data.vals[curr_i] = value; - value = self.data.vals[idx].inlined_clone(); + value = self.data.vals[idx].clone(); irow = curr_irow; curr_i += 1; } diff --git a/src/sparse/cs_matrix_cholesky.rs b/src/sparse/cs_matrix_cholesky.rs index ff9ca023..dcc930bb 100644 --- a/src/sparse/cs_matrix_cholesky.rs +++ b/src/sparse/cs_matrix_cholesky.rs @@ -107,28 +107,29 @@ where let irow = *self.original_i.get_unchecked(p); if irow >= k { - *self.work_x.vget_unchecked_mut(irow) = *values.get_unchecked(p); + *self.work_x.vget_unchecked_mut(irow) = values.get_unchecked(p).clone(); } } for j in self.u.data.column_row_indices(k) { - let factor = -*self + let factor = -self .l .data .vals - .get_unchecked(*self.work_c.vget_unchecked(j)); + .get_unchecked(*self.work_c.vget_unchecked(j)) + .clone(); *self.work_c.vget_unchecked_mut(j) += 1; if j < k { for (z, val) in self.l.data.column_entries(j) { if z >= k { - *self.work_x.vget_unchecked_mut(z) += val * factor; + *self.work_x.vget_unchecked_mut(z) += val * factor.clone(); } } } } - let diag = *self.work_x.vget_unchecked(k); + let diag = self.work_x.vget_unchecked(k).clone(); if diag > T::zero() { let denom = diag.sqrt(); @@ -136,10 +137,10 @@ where .l .data .vals - .get_unchecked_mut(*self.l.data.p.vget_unchecked(k)) = denom; + .get_unchecked_mut(*self.l.data.p.vget_unchecked(k)) = denom.clone(); for (p, val) in self.l.data.column_entries_mut(k) { - *val = *self.work_x.vget_unchecked(p) / denom; + *val = self.work_x.vget_unchecked(p).clone() / denom.clone(); *self.work_x.vget_unchecked_mut(p) = T::zero(); } } else { @@ -176,11 +177,11 @@ where let irow = *self.original_i.get_unchecked(p); if irow <= k { - *self.work_x.vget_unchecked_mut(irow) = *values.get_unchecked(p); + *self.work_x.vget_unchecked_mut(irow) = values.get_unchecked(p).clone(); } } - let mut diag = *self.work_x.vget_unchecked(k); + let mut diag = self.work_x.vget_unchecked(k).clone(); *self.work_x.vget_unchecked_mut(k) = T::zero(); // Triangular solve. @@ -189,12 +190,13 @@ where continue; } - let lki = *self.work_x.vget_unchecked(irow) - / *self + let lki = self.work_x.vget_unchecked(irow).clone() + / self .l .data .vals - .get_unchecked(*self.l.data.p.vget_unchecked(irow)); + .get_unchecked(*self.l.data.p.vget_unchecked(irow)) + .clone(); *self.work_x.vget_unchecked_mut(irow) = T::zero(); for p in @@ -203,10 +205,10 @@ where *self .work_x .vget_unchecked_mut(*self.l.data.i.get_unchecked(p)) -= - *self.l.data.vals.get_unchecked(p) * lki; + self.l.data.vals.get_unchecked(p).clone() * lki.clone(); } - diag -= lki * lki; + diag -= lki.clone() * lki.clone(); let p = *self.work_c.vget_unchecked(irow); *self.work_c.vget_unchecked_mut(irow) += 1; *self.l.data.i.get_unchecked_mut(p) = k; diff --git a/src/sparse/cs_matrix_conversion.rs b/src/sparse/cs_matrix_conversion.rs index 4fefd325..e7ff8c36 100644 --- a/src/sparse/cs_matrix_conversion.rs +++ b/src/sparse/cs_matrix_conversion.rs @@ -102,7 +102,7 @@ where for i in 0..nrows.value() { if !column[i].is_zero() { res.data.i[nz] = i; - res.data.vals[nz] = column[i].inlined_clone(); + res.data.vals[nz] = column[i].clone(); nz += 1; } } diff --git a/src/sparse/cs_matrix_ops.rs b/src/sparse/cs_matrix_ops.rs index 419862a7..1e695e94 100644 --- a/src/sparse/cs_matrix_ops.rs +++ b/src/sparse/cs_matrix_ops.rs @@ -28,9 +28,9 @@ impl> CsMatrix { timestamps[i] = timestamp; res.data.i[nz] = i; nz += 1; - workspace[i] = val * beta.inlined_clone(); + workspace[i] = val * beta.clone(); } else { - workspace[i] += val * beta.inlined_clone(); + workspace[i] += val * beta.clone(); } } @@ -88,18 +88,18 @@ impl> Vect unsafe { let k = x.data.row_index_unchecked(i); let y = self.vget_unchecked_mut(k); - *y = alpha.inlined_clone() * x.data.get_value_unchecked(i).inlined_clone(); + *y = alpha.clone() * x.data.get_value_unchecked(i).clone(); } } } else { // Needed to be sure even components not present on `x` are multiplied. - *self *= beta.inlined_clone(); + *self *= beta.clone(); for i in 0..x.len() { unsafe { let k = x.data.row_index_unchecked(i); let y = self.vget_unchecked_mut(k); - *y += alpha.inlined_clone() * x.data.get_value_unchecked(i).inlined_clone(); + *y += alpha.clone() * x.data.get_value_unchecked(i).clone(); } } } @@ -159,14 +159,14 @@ where for (i, beta) in rhs.data.column_entries(j) { for (k, val) in self.data.column_entries(i) { - workspace[k] += val.inlined_clone() * beta.inlined_clone(); + workspace[k] += val.clone() * beta.clone(); } } for (i, val) in workspace.as_mut_slice().iter_mut().enumerate() { if !val.is_zero() { res.data.i[nz] = i; - res.data.vals[nz] = val.inlined_clone(); + res.data.vals[nz] = val.clone(); *val = T::zero(); nz += 1; } @@ -273,7 +273,7 @@ where res.data.i[range.clone()].sort_unstable(); for p in range { - res.data.vals[p] = workspace[res.data.i[p]].inlined_clone() + res.data.vals[p] = workspace[res.data.i[p]].clone() } } @@ -296,7 +296,7 @@ where fn mul(mut self, rhs: T) -> Self::Output { for e in self.values_mut() { - *e *= rhs.inlined_clone() + *e *= rhs.clone() } self diff --git a/src/sparse/cs_matrix_solve.rs b/src/sparse/cs_matrix_solve.rs index 6136a0f8..2730310c 100644 --- a/src/sparse/cs_matrix_solve.rs +++ b/src/sparse/cs_matrix_solve.rs @@ -80,7 +80,7 @@ impl> CsMatrix { } for (i, val) in column { - let bj = b[j]; + let bj = b[j].clone(); b[i] -= bj * val; } } @@ -122,7 +122,7 @@ impl> CsMatrix { if let Some(diag) = diag { for (i, val) in column { - let bi = b[i]; + let bi = b[i].clone(); b[j] -= val * bi; } @@ -183,7 +183,7 @@ impl> CsMatrix { } for (i, val) in column { - let wj = workspace[j]; + let wj = workspace[j].clone(); workspace[i] -= wj * val; } } @@ -193,7 +193,7 @@ impl> CsMatrix { CsVector::new_uninitialized_generic(b.data.shape().0, Const::<1>, reach.len()); for (i, val) in reach.iter().zip(result.data.vals.iter_mut()) { - *val = workspace[*i]; + *val = workspace[*i].clone(); } result.data.i = reach; diff --git a/src/third_party/mint/mint_quaternion.rs b/src/third_party/mint/mint_quaternion.rs index f41815ce..7527a517 100644 --- a/src/third_party/mint/mint_quaternion.rs +++ b/src/third_party/mint/mint_quaternion.rs @@ -10,11 +10,11 @@ impl Into> for Quaternion { fn into(self) -> mint::Quaternion { mint::Quaternion { v: mint::Vector3 { - x: self[0].inlined_clone(), - y: self[1].inlined_clone(), - z: self[2].inlined_clone(), + x: self[0].clone(), + y: self[1].clone(), + z: self[2].clone(), }, - s: self[3].inlined_clone(), + s: self[3].clone(), } } } @@ -23,11 +23,11 @@ impl Into> for UnitQuaternion { fn into(self) -> mint::Quaternion { mint::Quaternion { v: mint::Vector3 { - x: self[0].inlined_clone(), - y: self[1].inlined_clone(), - z: self[2].inlined_clone(), + x: self[0].clone(), + y: self[1].clone(), + z: self[2].clone(), }, - s: self[3].inlined_clone(), + s: self[3].clone(), } } }