diff --git a/ndarray-linalg/src/assert.rs b/ndarray-linalg/src/assert.rs index 74c1618b..7acdd46d 100644 --- a/ndarray-linalg/src/assert.rs +++ b/ndarray-linalg/src/assert.rs @@ -29,11 +29,9 @@ pub fn aclose(test: A, truth: A, atol: A::Real) { } /// check two arrays are close in maximum norm -pub fn close_max(test: &ArrayBase, truth: &ArrayBase, atol: A::Real) +pub fn close_max(test: &ArrayRef, truth: &ArrayRef, atol: A::Real) where A: Scalar + Lapack, - S1: Data, - S2: Data, D: Dimension, D::Pattern: PartialEq + Debug, { @@ -48,11 +46,9 @@ where } /// check two arrays are close in L1 norm -pub fn close_l1(test: &ArrayBase, truth: &ArrayBase, rtol: A::Real) +pub fn close_l1(test: &ArrayRef, truth: &ArrayRef, rtol: A::Real) where A: Scalar + Lapack, - S1: Data, - S2: Data, D: Dimension, D::Pattern: PartialEq + Debug, { @@ -67,11 +63,9 @@ where } /// check two arrays are close in L2 norm -pub fn close_l2(test: &ArrayBase, truth: &ArrayBase, rtol: A::Real) +pub fn close_l2(test: &ArrayRef, truth: &ArrayRef, rtol: A::Real) where A: Scalar + Lapack, - S1: Data, - S2: Data, D: Dimension, D::Pattern: PartialEq + Debug, { diff --git a/ndarray-linalg/src/cholesky.rs b/ndarray-linalg/src/cholesky.rs index 58cc5cee..73ecf672 100644 --- a/ndarray-linalg/src/cholesky.rs +++ b/ndarray-linalg/src/cholesky.rs @@ -166,13 +166,7 @@ where A: Scalar + Lapack, S: Data, { - fn solvec_inplace<'a, Sb>( - &self, - b: &'a mut ArrayBase, - ) -> Result<&'a mut ArrayBase> - where - Sb: DataMut, - { + fn solvec_inplace<'a>(&self, b: &'a mut ArrayRef) -> Result<&'a mut ArrayRef> { A::solve_cholesky( self.factor.square_layout()?, self.uplo, @@ -225,10 +219,9 @@ pub trait CholeskyInplace { fn cholesky_inplace(&mut self, uplo: UPLO) -> Result<&mut Self>; } -impl Cholesky for ArrayBase +impl Cholesky for ArrayRef where A: Scalar + Lapack, - S: Data, { type Output = Array2; @@ -251,10 +244,9 @@ where } } -impl CholeskyInplace for ArrayBase +impl CholeskyInplace for ArrayRef where A: Scalar + Lapack, - S: DataMut, { fn cholesky_inplace(&mut self, uplo: UPLO) -> Result<&mut Self> { A::cholesky(self.square_layout()?, uplo, self.as_allocated_mut()?)?; @@ -301,10 +293,9 @@ where } } -impl FactorizeC> for ArrayBase +impl FactorizeC> for ArrayRef where A: Scalar + Lapack, - Si: Data, { fn factorizec(&self, uplo: UPLO) -> Result>> { Ok(CholeskyFactorized { @@ -320,7 +311,7 @@ pub trait SolveC { /// Solves a system of linear equations `A * x = b` with Hermitian (or real /// symmetric) positive definite matrix `A`, where `A` is `self`, `b` is /// the argument, and `x` is the successful result. - fn solvec>(&self, b: &ArrayBase) -> Result> { + fn solvec(&self, b: &ArrayRef) -> Result> { let mut b = replicate(b); self.solvec_inplace(&mut b)?; Ok(b) @@ -339,24 +330,14 @@ pub trait SolveC { /// symmetric) positive definite matrix `A`, where `A` is `self`, `b` is /// the argument, and `x` is the successful result. The value of `x` is /// also assigned to the argument. - fn solvec_inplace<'a, S: DataMut>( - &self, - b: &'a mut ArrayBase, - ) -> Result<&'a mut ArrayBase>; + fn solvec_inplace<'a>(&self, b: &'a mut ArrayRef) -> Result<&'a mut ArrayRef>; } -impl SolveC for ArrayBase +impl SolveC for ArrayRef where A: Scalar + Lapack, - S: Data, { - fn solvec_inplace<'a, Sb>( - &self, - b: &'a mut ArrayBase, - ) -> Result<&'a mut ArrayBase> - where - Sb: DataMut, - { + fn solvec_inplace<'a>(&self, b: &'a mut ArrayRef) -> Result<&'a mut ArrayRef> { self.factorizec(UPLO::Upper)?.solvec_inplace(b) } } @@ -377,10 +358,9 @@ pub trait InverseCInto { fn invc_into(self) -> Result; } -impl InverseC for ArrayBase +impl InverseC for ArrayRef where A: Scalar + Lapack, - S: Data, { type Output = Array2; @@ -435,10 +415,9 @@ pub trait DeterminantCInto { fn ln_detc_into(self) -> Self::Output; } -impl DeterminantC for ArrayBase +impl DeterminantC for ArrayRef where A: Scalar + Lapack, - S: Data, { type Output = Result<::Real>; diff --git a/ndarray-linalg/src/convert.rs b/ndarray-linalg/src/convert.rs index c808211e..d588b461 100644 --- a/ndarray-linalg/src/convert.rs +++ b/ndarray-linalg/src/convert.rs @@ -46,33 +46,31 @@ where } } -pub fn replicate(a: &ArrayBase) -> ArrayBase +pub fn replicate(a: &ArrayRef) -> ArrayBase where A: Copy, - Sv: Data, - So: DataOwned + DataMut, + S: DataOwned + DataMut, D: Dimension, { unsafe { - let ret = ArrayBase::::build_uninit(a.dim(), |view| { + let ret = ArrayBase::::build_uninit(a.dim(), |view| { a.assign_to(view); }); ret.assume_init() } } -fn clone_with_layout(l: MatrixLayout, a: &ArrayBase) -> ArrayBase +fn clone_with_layout(l: MatrixLayout, a: &ArrayRef) -> ArrayBase where A: Copy, - Si: Data, - So: DataOwned + DataMut, + S: DataOwned + DataMut, { let shape_builder = match l { MatrixLayout::C { row, lda } => (row as usize, lda as usize).set_f(false), MatrixLayout::F { col, lda } => (lda as usize, col as usize).set_f(true), }; unsafe { - let ret = ArrayBase::::build_uninit(shape_builder, |view| { + let ret = ArrayBase::::build_uninit(shape_builder, |view| { a.assign_to(view); }); ret.assume_init() @@ -119,10 +117,9 @@ where /// data in the triangular portion corresponding to `uplo`. /// /// ***Panics*** if `a` is not square. -pub(crate) fn triangular_fill_hermitian(a: &mut ArrayBase, uplo: UPLO) +pub(crate) fn triangular_fill_hermitian(a: &mut ArrayRef, uplo: UPLO) where A: Scalar + Lapack, - S: DataMut, { assert!(a.is_square()); match uplo { diff --git a/ndarray-linalg/src/diagonal.rs b/ndarray-linalg/src/diagonal.rs index a7adad4a..4006a1ef 100644 --- a/ndarray-linalg/src/diagonal.rs +++ b/ndarray-linalg/src/diagonal.rs @@ -24,7 +24,7 @@ impl IntoDiagonal for ArrayBase { } } -impl> AsDiagonal for ArrayBase { +impl AsDiagonal for ArrayRef { fn as_diagonal(&self) -> Diagonal> { Diagonal { diag: self.view() } } @@ -37,10 +37,7 @@ where { type Elem = A; - fn apply_mut(&self, a: &mut ArrayBase) - where - S: DataMut, - { + fn apply_mut(&self, a: &mut ArrayRef) { for (val, d) in a.iter_mut().zip(self.diag.iter()) { *val *= *d; } diff --git a/ndarray-linalg/src/eig.rs b/ndarray-linalg/src/eig.rs index 03e3ee03..ea61a232 100644 --- a/ndarray-linalg/src/eig.rs +++ b/ndarray-linalg/src/eig.rs @@ -39,10 +39,9 @@ pub trait Eig { fn eig(&self) -> Result<(Self::EigVal, Self::EigVec)>; } -impl Eig for ArrayBase +impl Eig for ArrayRef where A: Scalar + Lapack, - S: Data, { type EigVal = Array1; type EigVec = Array2; @@ -65,10 +64,9 @@ pub trait EigVals { fn eigvals(&self) -> Result; } -impl EigVals for ArrayBase +impl EigVals for ArrayRef where A: Scalar + Lapack, - S: Data, { type EigVal = Array1; @@ -127,27 +125,71 @@ pub trait EigGeneralized { /// computing the eigenvalues as α/β. If `None`, no approximate comparisons to zero will be /// made. fn eig_generalized( - &self, + self, thresh_opt: Option, ) -> Result<(Self::EigVal, Self::EigVec)>; } -impl EigGeneralized for (ArrayBase, ArrayBase) +/// Turn arrays, references to arrays, and [`ArrayRef`]s into owned arrays +pub trait MaybeOwnedMatrix { + type Elem; + + /// Convert into an owned array, cloning only when necessary. + fn into_owned(self) -> Array2; +} + +impl MaybeOwnedMatrix for ArrayBase where - A: Scalar + Lapack, - S: Data, + S: Data, + S::Elem: Clone, { - type EigVal = Array1>; - type EigVec = Array2; - type Real = A::Real; + type Elem = S::Elem; + + fn into_owned(self) -> Array2 { + ArrayBase::into_owned(self) + } +} + +impl MaybeOwnedMatrix for &ArrayBase +where + S: Data, + S::Elem: Clone, +{ + type Elem = S::Elem; + + fn into_owned(self) -> Array2 { + self.to_owned() + } +} + +impl MaybeOwnedMatrix for &ArrayRef2 +where + A: Clone, +{ + type Elem = A; + + fn into_owned(self) -> Array2 { + self.to_owned() + } +} + +impl EigGeneralized for (T1, T2) +where + T1: MaybeOwnedMatrix, + T1::Elem: Lapack + Scalar, + T2: MaybeOwnedMatrix, +{ + type EigVal = Array1::Complex>>; + type EigVec = Array2<::Complex>; + type Real = ::Real; fn eig_generalized( - &self, + self, thresh_opt: Option, ) -> Result<(Self::EigVal, Self::EigVec)> { - let (mut a, mut b) = (self.0.to_owned(), self.1.to_owned()); + let (mut a, mut b) = (self.0.into_owned(), self.1.into_owned()); let layout = a.square_layout()?; - let (s, t) = A::eig_generalized( + let (s, t) = T1::Elem::eig_generalized( true, layout, a.as_allocated_mut()?, @@ -161,3 +203,25 @@ where )) } } + +#[cfg(test)] +mod tests { + use crate::MaybeOwnedMatrix; + + #[test] + fn test_maybe_owned_matrix() { + let a = array![[1.0, 2.0], [3.0, 4.0]]; + let a_ptr = a.as_ptr(); + let a1 = MaybeOwnedMatrix::into_owned(a); + assert_eq!(a_ptr, a1.as_ptr()); + + let b = a1.clone(); + let b1 = MaybeOwnedMatrix::into_owned(&b); + assert_eq!(b, b1); + assert_ne!(b.as_ptr(), b1.as_ptr()); + + let b2 = MaybeOwnedMatrix::into_owned(&*b); + assert_eq!(b, b2); + assert_ne!(b.as_ptr(), b2.as_ptr()); + } +} diff --git a/ndarray-linalg/src/eigh.rs b/ndarray-linalg/src/eigh.rs index 837f51f8..a171e9ad 100644 --- a/ndarray-linalg/src/eigh.rs +++ b/ndarray-linalg/src/eigh.rs @@ -117,10 +117,9 @@ where } } -impl EighInplace for ArrayBase +impl EighInplace for ArrayRef where A: Scalar + Lapack, - S: DataMut, { type EigVal = Array1; diff --git a/ndarray-linalg/src/generate.rs b/ndarray-linalg/src/generate.rs index 5646c808..3397ea12 100644 --- a/ndarray-linalg/src/generate.rs +++ b/ndarray-linalg/src/generate.rs @@ -9,13 +9,12 @@ use super::qr::*; use super::types::*; /// Hermite conjugate matrix -pub fn conjugate(a: &ArrayBase) -> ArrayBase +pub fn conjugate(a: &ArrayRef) -> ArrayBase where A: Scalar, - Si: Data, - So: DataOwned + DataMut, + S: DataOwned + DataMut, { - let mut a: ArrayBase = replicate(&a.t()); + let mut a: ArrayBase = replicate(&a.t()); for val in a.iter_mut() { *val = val.conj(); } diff --git a/ndarray-linalg/src/inner.rs b/ndarray-linalg/src/inner.rs index 87ca96cc..4ab122b9 100644 --- a/ndarray-linalg/src/inner.rs +++ b/ndarray-linalg/src/inner.rs @@ -9,18 +9,16 @@ pub trait InnerProduct { type Elem: Scalar; /// Inner product `(self.conjugate, rhs) - fn inner(&self, rhs: &ArrayBase) -> Self::Elem - where - S: Data; + fn inner(&self, rhs: &ArrayRef) -> Self::Elem; } -impl InnerProduct for ArrayBase +impl InnerProduct for ArrayRef where A: Scalar, - S: Data, { type Elem = A; - fn inner>(&self, rhs: &ArrayBase) -> A { + + fn inner(&self, rhs: &ArrayRef) -> A { assert_eq!(self.len(), rhs.len()); Zip::from(self) .and(rhs) diff --git a/ndarray-linalg/src/krylov/householder.rs b/ndarray-linalg/src/krylov/householder.rs index c04d9049..88b0d5ed 100644 --- a/ndarray-linalg/src/krylov/householder.rs +++ b/ndarray-linalg/src/krylov/householder.rs @@ -8,10 +8,9 @@ use crate::{inner::*, norm::*}; use num_traits::One; /// Calc a reflactor `w` from a vector `x` -pub fn calc_reflector(x: &mut ArrayBase) +pub fn calc_reflector(x: &mut ArrayRef) where A: Scalar + Lapack, - S: DataMut, { assert!(!x.is_empty()); let norm = x.norm_l2(); @@ -26,11 +25,9 @@ where /// Panic /// ------ /// - if the size of `w` and `a` mismaches -pub fn reflect(w: &ArrayBase, a: &mut ArrayBase) +pub fn reflect(w: &ArrayRef, a: &mut ArrayRef) where A: Scalar + Lapack, - S1: Data, - S2: DataMut, { assert_eq!(w.len(), a.len()); let n = a.len(); @@ -66,10 +63,7 @@ impl Householder { } /// Take a Reflection `P = I - 2ww^T` - fn fundamental_reflection(&self, k: usize, a: &mut ArrayBase) - where - S: DataMut, - { + fn fundamental_reflection(&self, k: usize, a: &mut ArrayRef) { assert!(k < self.v.len()); assert_eq!( a.len(), @@ -80,10 +74,7 @@ impl Householder { } /// Take forward reflection `P = P_l ... P_1` - pub fn forward_reflection(&self, a: &mut ArrayBase) - where - S: DataMut, - { + pub fn forward_reflection(&self, a: &mut ArrayRef) { assert!(a.len() == self.dim); let l = self.v.len(); for k in 0..l { @@ -92,10 +83,7 @@ impl Householder { } /// Take backward reflection `P = P_1 ... P_l` - pub fn backward_reflection(&self, a: &mut ArrayBase) - where - S: DataMut, - { + pub fn backward_reflection(&self, a: &mut ArrayRef) { assert!(a.len() == self.dim); let l = self.v.len(); for k in (0..l).rev() { @@ -104,10 +92,7 @@ impl Householder { } /// Compose coefficients array using reflected vector - fn compose_coefficients(&self, a: &ArrayBase) -> Coefficients - where - S: Data, - { + fn compose_coefficients(&self, a: &ArrayRef) -> Coefficients { let k = self.len(); let res = a.slice(s![k..]).norm_l2(); let mut c = Array1::zeros(k + 1); @@ -122,10 +107,7 @@ impl Householder { } /// Construct the residual vector from reflected vector - fn construct_residual(&self, a: &mut ArrayBase) - where - S: DataMut, - { + fn construct_residual(&self, a: &mut ArrayRef) { let k = self.len(); azip!((a in a.slice_mut(s![..k])) *a = A::zero()); self.backward_reflection(a); @@ -147,10 +129,7 @@ impl Orthogonalizer for Householder { self.tol } - fn decompose(&self, a: &mut ArrayBase) -> Array1 - where - S: DataMut, - { + fn decompose(&self, a: &mut ArrayRef) -> Array1 { self.forward_reflection(a); let coef = self.compose_coefficients(a); self.construct_residual(a); @@ -166,10 +145,7 @@ impl Orthogonalizer for Householder { self.compose_coefficients(&a) } - fn div_append(&mut self, a: &mut ArrayBase) -> AppendResult - where - S: DataMut, - { + fn div_append(&mut self, a: &mut ArrayRef) -> AppendResult { assert_eq!(a.len(), self.dim); let k = self.len(); self.forward_reflection(a); diff --git a/ndarray-linalg/src/krylov/mgs.rs b/ndarray-linalg/src/krylov/mgs.rs index 67806a2c..25fa45c2 100644 --- a/ndarray-linalg/src/krylov/mgs.rs +++ b/ndarray-linalg/src/krylov/mgs.rs @@ -42,10 +42,7 @@ impl Orthogonalizer for MGS { self.tol } - fn decompose(&self, a: &mut ArrayBase) -> Array1 - where - S: DataMut, - { + fn decompose(&self, a: &mut ArrayRef) -> Array1 { assert_eq!(a.len(), self.dim()); let mut coef = Array1::zeros(self.len() + 1); for i in 0..self.len() { @@ -77,10 +74,9 @@ impl Orthogonalizer for MGS { self.div_append(&mut a) } - fn div_append(&mut self, a: &mut ArrayBase) -> AppendResult + fn div_append(&mut self, a: &mut ArrayRef) -> AppendResult where A: Lapack, - S: DataMut, { let coef = self.decompose(a); let nrm = coef[coef.len() - 1].re(); diff --git a/ndarray-linalg/src/krylov/mod.rs b/ndarray-linalg/src/krylov/mod.rs index 14c9f7ef..bc8e2a26 100644 --- a/ndarray-linalg/src/krylov/mod.rs +++ b/ndarray-linalg/src/krylov/mod.rs @@ -92,9 +92,7 @@ pub trait Orthogonalizer { /// - `a` becomes the tangent vector /// - The Coefficients to the current basis is returned. /// - fn decompose(&self, a: &mut ArrayBase) -> Coefficients - where - S: DataMut; + fn decompose(&self, a: &mut ArrayRef) -> Coefficients; /// Calculate the coefficient to the current basis basis /// @@ -112,9 +110,7 @@ pub trait Orthogonalizer { /// Add new vector if the residual is larger than relative tolerance, /// and return the residual vector - fn div_append(&mut self, a: &mut ArrayBase) -> AppendResult - where - S: DataMut; + fn div_append(&mut self, a: &mut ArrayRef) -> AppendResult; /// Get Q-matrix of generated basis fn get_q(&self) -> Q; diff --git a/ndarray-linalg/src/layout.rs b/ndarray-linalg/src/layout.rs index d0d13585..5bc9c9c9 100644 --- a/ndarray-linalg/src/layout.rs +++ b/ndarray-linalg/src/layout.rs @@ -18,10 +18,7 @@ pub trait AllocatedArrayMut: AllocatedArray { fn as_allocated_mut(&mut self) -> Result<&mut [Self::Elem]>; } -impl AllocatedArray for ArrayBase -where - S: Data, -{ +impl AllocatedArray for ArrayRef { type Elem = A; fn layout(&self) -> Result { @@ -72,10 +69,7 @@ where } } -impl AllocatedArrayMut for ArrayBase -where - S: DataMut, -{ +impl AllocatedArrayMut for ArrayRef { fn as_allocated_mut(&mut self) -> Result<&mut [A]> { self.as_slice_memory_order_mut() .ok_or(LinalgError::MemoryNotCont) diff --git a/ndarray-linalg/src/least_squares.rs b/ndarray-linalg/src/least_squares.rs index f376f569..62eb8503 100644 --- a/ndarray-linalg/src/least_squares.rs +++ b/ndarray-linalg/src/least_squares.rs @@ -91,9 +91,8 @@ pub struct LeastSquaresResult { pub residual_sum_of_squares: Option>, } /// Solve least squares for immutable references -pub trait LeastSquaresSvd +pub trait LeastSquaresSvd where - D: Data, E: Scalar + Lapack, I: Dimension, { @@ -104,7 +103,7 @@ where /// `A` and `rhs` must have the same layout, i.e. they must /// be both either row- or column-major format, otherwise a /// `IncompatibleShape` error is raised. - fn least_squares(&self, rhs: &ArrayBase) -> Result>; + fn least_squares(&self, rhs: &ArrayRef) -> Result>; } /// Solve least squares for owned matrices @@ -127,9 +126,8 @@ where /// Solve least squares for mutable references, overwriting /// the input fields in the process -pub trait LeastSquaresSvdInPlace +pub trait LeastSquaresSvdInPlace where - D: Data, E: Scalar + Lapack, I: Dimension, { @@ -143,7 +141,7 @@ where /// `IncompatibleShape` error is raised. fn least_squares_in_place( &mut self, - rhs: &mut ArrayBase, + rhs: &mut ArrayRef, ) -> Result>; } @@ -151,11 +149,9 @@ where /// column vector as a right-hand side. /// `E` is one of `f32`, `f64`, `c32`, `c64`. `D1`, `D2` can be any /// valid representation for `ArrayBase` (over `E`). -impl LeastSquaresSvd for ArrayBase +impl LeastSquaresSvd for ArrayRef where E: Scalar + Lapack, - D1: Data, - D2: Data, { /// Solve a least squares problem of the form `Ax = rhs` /// by calling `A.least_squares(&rhs)`, where `rhs` is a @@ -164,7 +160,7 @@ where /// `A` and `rhs` must have the same layout, i.e. they must /// be both either row- or column-major format, otherwise a /// `IncompatibleShape` error is raised. - fn least_squares(&self, rhs: &ArrayBase) -> Result> { + fn least_squares(&self, rhs: &ArrayRef) -> Result> { let a = self.to_owned(); let b = rhs.to_owned(); a.least_squares_into(b) @@ -175,11 +171,9 @@ where /// (=mulitipe vectors) as a right-hand side. /// `E` is one of `f32`, `f64`, `c32`, `c64`. `D1`, `D2` can be any /// valid representation for `ArrayBase` (over `E`). -impl LeastSquaresSvd for ArrayBase +impl LeastSquaresSvd for ArrayRef where E: Scalar + Lapack, - D1: Data, - D2: Data, { /// Solve a least squares problem of the form `Ax = rhs` /// by calling `A.least_squares(&rhs)`, where `rhs` is @@ -188,7 +182,7 @@ where /// `A` and `rhs` must have the same layout, i.e. they must /// be both either row- or column-major format, otherwise a /// `IncompatibleShape` error is raised. - fn least_squares(&self, rhs: &ArrayBase) -> Result> { + fn least_squares(&self, rhs: &ArrayRef) -> Result> { let a = self.to_owned(); let b = rhs.to_owned(); a.least_squares_into(b) @@ -255,11 +249,9 @@ where /// /// `E` is one of `f32`, `f64`, `c32`, `c64`. `D1`, `D2` can be any /// valid representation for `ArrayBase` (over `E`). -impl LeastSquaresSvdInPlace for ArrayBase +impl LeastSquaresSvdInPlace for ArrayRef where E: Scalar + Lapack, - D1: DataMut, - D2: DataMut, { /// Solve a least squares problem of the form `Ax = rhs` /// by calling `A.least_squares(rhs)`, where `rhs` is a @@ -270,7 +262,7 @@ where /// `IncompatibleShape` error is raised. fn least_squares_in_place( &mut self, - rhs: &mut ArrayBase, + rhs: &mut ArrayRef, ) -> Result> { if self.shape()[0] != rhs.shape()[0] { return Err(ShapeError::from_kind(ErrorKind::IncompatibleShape).into()); @@ -288,14 +280,12 @@ where } } -fn compute_least_squares_srhs( - a: &mut ArrayBase, - rhs: &mut ArrayBase, +fn compute_least_squares_srhs( + a: &mut ArrayRef, + rhs: &mut ArrayRef, ) -> Result> where E: Scalar + Lapack, - D1: DataMut, - D2: DataMut, { let LeastSquaresOwned:: { singular_values, @@ -318,11 +308,11 @@ where }) } -fn compute_residual_scalar>( +fn compute_residual_scalar( m: usize, n: usize, rank: i32, - b: &ArrayBase, + b: &ArrayRef, ) -> Option> { if m < n || n != rank as usize { return None; @@ -338,11 +328,9 @@ fn compute_residual_scalar>( /// /// `E` is one of `f32`, `f64`, `c32`, `c64`. `D1`, `D2` can be any /// valid representation for `ArrayBase` (over `E`). -impl LeastSquaresSvdInPlace for ArrayBase +impl LeastSquaresSvdInPlace for ArrayRef where E: Scalar + Lapack, - D1: DataMut, - D2: DataMut, { /// Solve a least squares problem of the form `Ax = rhs` /// by calling `A.least_squares(rhs)`, where `rhs` is a @@ -353,7 +341,7 @@ where /// `IncompatibleShape` error is raised. fn least_squares_in_place( &mut self, - rhs: &mut ArrayBase, + rhs: &mut ArrayRef, ) -> Result> { if self.shape()[0] != rhs.shape()[0] { return Err(ShapeError::from_kind(ErrorKind::IncompatibleShape).into()); @@ -375,14 +363,12 @@ where } } -fn compute_least_squares_nrhs( - a: &mut ArrayBase, - rhs: &mut ArrayBase, +fn compute_least_squares_nrhs( + a: &mut ArrayRef, + rhs: &mut ArrayRef, ) -> Result> where E: Scalar + Lapack, - D1: DataMut, - D2: DataMut, { let a_layout = a.layout()?; let rhs_layout = rhs.layout()?; @@ -408,11 +394,11 @@ where }) } -fn compute_residual_array1>( +fn compute_residual_array1( m: usize, n: usize, rank: i32, - b: &ArrayBase, + b: &ArrayRef, ) -> Option> { if m < n || n != rank as usize { return None; diff --git a/ndarray-linalg/src/norm.rs b/ndarray-linalg/src/norm.rs index e0dde1a4..ba28e73f 100644 --- a/ndarray-linalg/src/norm.rs +++ b/ndarray-linalg/src/norm.rs @@ -22,10 +22,9 @@ pub trait Norm { fn norm_max(&self) -> Self::Output; } -impl Norm for ArrayBase +impl Norm for ArrayRef where A: Scalar + Lapack, - S: Data, D: Dimension, { type Output = A::Real; diff --git a/ndarray-linalg/src/operator.rs b/ndarray-linalg/src/operator.rs index 368650bf..ae6f6cdc 100644 --- a/ndarray-linalg/src/operator.rs +++ b/ndarray-linalg/src/operator.rs @@ -10,20 +10,14 @@ pub trait LinearOperator { type Elem: Scalar; /// Apply operator out-place - fn apply(&self, a: &ArrayBase) -> Array1 - where - S: Data, - { + fn apply(&self, a: &ArrayRef) -> Array1 { let mut a = a.to_owned(); self.apply_mut(&mut a); a } /// Apply operator in-place - fn apply_mut(&self, a: &mut ArrayBase) - where - S: DataMut, - { + fn apply_mut(&self, a: &mut ArrayRef) { let b = self.apply(a); azip!((a in a, &b in &b) *a = b); } @@ -38,19 +32,13 @@ pub trait LinearOperator { } /// Apply operator to matrix out-place - fn apply2(&self, a: &ArrayBase) -> Array2 - where - S: Data, - { + fn apply2(&self, a: &ArrayRef) -> Array2 { let cols: Vec<_> = a.axis_iter(Axis(1)).map(|col| self.apply(&col)).collect(); hstack(&cols).unwrap() } /// Apply operator to matrix in-place - fn apply2_mut(&self, a: &mut ArrayBase) - where - S: DataMut, - { + fn apply2_mut(&self, a: &mut ArrayRef) { for mut col in a.axis_iter_mut(Axis(1)) { self.apply_mut(&mut col) } @@ -73,10 +61,7 @@ where { type Elem = A; - fn apply(&self, a: &ArrayBase) -> Array1 - where - S: Data, - { + fn apply(&self, a: &ArrayRef) -> Array1 { self.dot(a) } } diff --git a/ndarray-linalg/src/opnorm.rs b/ndarray-linalg/src/opnorm.rs index 0a412580..83b46b35 100644 --- a/ndarray-linalg/src/opnorm.rs +++ b/ndarray-linalg/src/opnorm.rs @@ -34,10 +34,9 @@ pub trait OperationNorm { } } -impl OperationNorm for ArrayBase +impl OperationNorm for ArrayRef where A: Scalar + Lapack, - S: Data, { type Output = A::Real; diff --git a/ndarray-linalg/src/solve.rs b/ndarray-linalg/src/solve.rs index 79df1f77..e1c043ab 100644 --- a/ndarray-linalg/src/solve.rs +++ b/ndarray-linalg/src/solve.rs @@ -72,7 +72,7 @@ pub trait Solve { /// /// Panics if the length of `b` is not the equal to the number of columns /// of `A`. - fn solve>(&self, b: &ArrayBase) -> Result> { + fn solve(&self, b: &ArrayRef) -> Result> { let mut b = replicate(b); self.solve_inplace(&mut b)?; Ok(b) @@ -100,10 +100,7 @@ pub trait Solve { /// /// Panics if the length of `b` is not the equal to the number of columns /// of `A`. - fn solve_inplace<'a, S: DataMut>( - &self, - b: &'a mut ArrayBase, - ) -> Result<&'a mut ArrayBase>; + fn solve_inplace<'a>(&self, b: &'a mut ArrayRef) -> Result<&'a mut ArrayRef>; /// Solves a system of linear equations `A^T * x = b` where `A` is `self`, `b` /// is the argument, and `x` is the successful result. @@ -112,7 +109,7 @@ pub trait Solve { /// /// Panics if the length of `b` is not the equal to the number of rows of /// `A`. - fn solve_t>(&self, b: &ArrayBase) -> Result> { + fn solve_t(&self, b: &ArrayRef) -> Result> { let mut b = replicate(b); self.solve_t_inplace(&mut b)?; Ok(b) @@ -140,10 +137,7 @@ pub trait Solve { /// /// Panics if the length of `b` is not the equal to the number of rows of /// `A`. - fn solve_t_inplace<'a, S: DataMut>( - &self, - b: &'a mut ArrayBase, - ) -> Result<&'a mut ArrayBase>; + fn solve_t_inplace<'a>(&self, b: &'a mut ArrayRef) -> Result<&'a mut ArrayRef>; /// Solves a system of linear equations `A^H * x = b` where `A` is `self`, `b` /// is the argument, and `x` is the successful result. @@ -152,7 +146,7 @@ pub trait Solve { /// /// Panics if the length of `b` is not the equal to the number of rows of /// `A`. - fn solve_h>(&self, b: &ArrayBase) -> Result> { + fn solve_h(&self, b: &ArrayRef) -> Result> { let mut b = replicate(b); self.solve_h_inplace(&mut b)?; Ok(b) @@ -178,10 +172,7 @@ pub trait Solve { /// /// Panics if the length of `b` is not the equal to the number of rows of /// `A`. - fn solve_h_inplace<'a, S: DataMut>( - &self, - b: &'a mut ArrayBase, - ) -> Result<&'a mut ArrayBase>; + fn solve_h_inplace<'a>(&self, b: &'a mut ArrayRef) -> Result<&'a mut ArrayRef>; } /// Represents the LU factorization of a matrix `A` as `A = P*L*U`. @@ -199,13 +190,7 @@ where A: Scalar + Lapack, S: Data + RawDataClone, { - fn solve_inplace<'a, Sb>( - &self, - rhs: &'a mut ArrayBase, - ) -> Result<&'a mut ArrayBase> - where - Sb: DataMut, - { + fn solve_inplace<'a>(&self, rhs: &'a mut ArrayRef) -> Result<&'a mut ArrayRef> { assert_eq!( rhs.len(), self.a.len_of(Axis(1)), @@ -220,13 +205,10 @@ where )?; Ok(rhs) } - fn solve_t_inplace<'a, Sb>( + fn solve_t_inplace<'a>( &self, - rhs: &'a mut ArrayBase, - ) -> Result<&'a mut ArrayBase> - where - Sb: DataMut, - { + rhs: &'a mut ArrayRef, + ) -> Result<&'a mut ArrayRef> { assert_eq!( rhs.len(), self.a.len_of(Axis(0)), @@ -241,13 +223,10 @@ where )?; Ok(rhs) } - fn solve_h_inplace<'a, Sb>( + fn solve_h_inplace<'a>( &self, - rhs: &'a mut ArrayBase, - ) -> Result<&'a mut ArrayBase> - where - Sb: DataMut, - { + rhs: &'a mut ArrayRef, + ) -> Result<&'a mut ArrayRef> { assert_eq!( rhs.len(), self.a.len_of(Axis(0)), @@ -264,38 +243,25 @@ where } } -impl Solve for ArrayBase +impl Solve for ArrayRef where A: Scalar + Lapack, - S: Data, { - fn solve_inplace<'a, Sb>( - &self, - rhs: &'a mut ArrayBase, - ) -> Result<&'a mut ArrayBase> - where - Sb: DataMut, - { + fn solve_inplace<'a>(&self, rhs: &'a mut ArrayRef) -> Result<&'a mut ArrayRef> { let f = self.factorize()?; f.solve_inplace(rhs) } - fn solve_t_inplace<'a, Sb>( + fn solve_t_inplace<'a>( &self, - rhs: &'a mut ArrayBase, - ) -> Result<&'a mut ArrayBase> - where - Sb: DataMut, - { + rhs: &'a mut ArrayRef, + ) -> Result<&'a mut ArrayRef> { let f = self.factorize()?; f.solve_t_inplace(rhs) } - fn solve_h_inplace<'a, Sb>( + fn solve_h_inplace<'a>( &self, - rhs: &'a mut ArrayBase, - ) -> Result<&'a mut ArrayBase> - where - Sb: DataMut, - { + rhs: &'a mut ArrayRef, + ) -> Result<&'a mut ArrayRef> { let f = self.factorize()?; f.solve_h_inplace(rhs) } @@ -326,10 +292,9 @@ where } } -impl Factorize> for ArrayBase +impl Factorize> for ArrayRef where A: Scalar + Lapack, - Si: Data, { fn factorize(&self) -> Result>> { let mut a: Array2 = replicate(self); @@ -405,10 +370,9 @@ where } } -impl Inverse for ArrayBase +impl Inverse for ArrayRef where A: Scalar + Lapack, - Si: Data, { type Output = Array2; @@ -520,10 +484,9 @@ where } } -impl Determinant for ArrayBase +impl Determinant for ArrayRef where A: Scalar + Lapack, - S: Data, { fn sln_det(&self) -> Result<(A, A::Real)> { self.ensure_square()?; @@ -612,10 +575,9 @@ where } } -impl ReciprocalConditionNum for ArrayBase +impl ReciprocalConditionNum for ArrayRef where A: Scalar + Lapack, - S: Data, { fn rcond(&self) -> Result { self.factorize()?.rcond_into() diff --git a/ndarray-linalg/src/solveh.rs b/ndarray-linalg/src/solveh.rs index df0b3a6f..00dd6f92 100644 --- a/ndarray-linalg/src/solveh.rs +++ b/ndarray-linalg/src/solveh.rs @@ -65,7 +65,7 @@ pub trait SolveH { /// /// Panics if the length of `b` is not the equal to the number of columns /// of `A`. - fn solveh>(&self, b: &ArrayBase) -> Result> { + fn solveh(&self, b: &ArrayRef) -> Result> { let mut b = replicate(b); self.solveh_inplace(&mut b)?; Ok(b) @@ -96,10 +96,7 @@ pub trait SolveH { /// /// Panics if the length of `b` is not the equal to the number of columns /// of `A`. - fn solveh_inplace<'a, S: DataMut>( - &self, - b: &'a mut ArrayBase, - ) -> Result<&'a mut ArrayBase>; + fn solveh_inplace<'a>(&self, b: &'a mut ArrayRef) -> Result<&'a mut ArrayRef>; } /// Represents the Bunch–Kaufman factorization of a Hermitian (or real @@ -114,13 +111,10 @@ where A: Scalar + Lapack, S: Data, { - fn solveh_inplace<'a, Sb>( + fn solveh_inplace<'a>( &self, - rhs: &'a mut ArrayBase, - ) -> Result<&'a mut ArrayBase> - where - Sb: DataMut, - { + rhs: &'a mut ArrayRef, + ) -> Result<&'a mut ArrayRef> { assert_eq!( rhs.len(), self.a.len_of(Axis(1)), @@ -137,18 +131,14 @@ where } } -impl SolveH for ArrayBase +impl SolveH for ArrayRef where A: Scalar + Lapack, - S: Data, { - fn solveh_inplace<'a, Sb>( + fn solveh_inplace<'a>( &self, - rhs: &'a mut ArrayBase, - ) -> Result<&'a mut ArrayBase> - where - Sb: DataMut, - { + rhs: &'a mut ArrayRef, + ) -> Result<&'a mut ArrayRef> { let f = self.factorizeh()?; f.solveh_inplace(rhs) } @@ -181,10 +171,9 @@ where } } -impl FactorizeH> for ArrayBase +impl FactorizeH> for ArrayRef where A: Scalar + Lapack, - Si: Data, { fn factorizeh(&self) -> Result>> { let mut a: Array2 = replicate(self); @@ -255,10 +244,9 @@ where } } -impl InverseH for ArrayBase +impl InverseH for ArrayRef where A: Scalar + Lapack, - Si: Data, { type Output = Array2; @@ -317,10 +305,9 @@ pub trait DeterminantHInto { } /// Returns the sign and natural log of the determinant. -fn bk_sln_det(uplo: UPLO, ipiv_iter: P, a: &ArrayBase) -> (A::Real, A::Real) +fn bk_sln_det(uplo: UPLO, ipiv_iter: P, a: &ArrayRef) -> (A::Real, A::Real) where P: Iterator, - S: Data, A: Scalar + Lapack, { let layout = a.layout().unwrap(); @@ -424,10 +411,9 @@ where } } -impl DeterminantH for ArrayBase +impl DeterminantH for ArrayRef where A: Scalar + Lapack, - S: Data, { type Elem = A; diff --git a/ndarray-linalg/src/svd.rs b/ndarray-linalg/src/svd.rs index 5c9d59b1..58584958 100644 --- a/ndarray-linalg/src/svd.rs +++ b/ndarray-linalg/src/svd.rs @@ -59,10 +59,9 @@ where } } -impl SVD for ArrayBase +impl SVD for ArrayRef where A: Scalar + Lapack, - S: Data, { type U = Array2; type VT = Array2; @@ -78,10 +77,9 @@ where } } -impl SVDInplace for ArrayBase +impl SVDInplace for ArrayRef where A: Scalar + Lapack, - S: DataMut, { type U = Array2; type VT = Array2; diff --git a/ndarray-linalg/src/svddc.rs b/ndarray-linalg/src/svddc.rs index 0b0ae237..3a2aafcb 100644 --- a/ndarray-linalg/src/svddc.rs +++ b/ndarray-linalg/src/svddc.rs @@ -35,10 +35,9 @@ pub trait SVDDCInplace { ) -> Result<(Option, Self::Sigma, Option)>; } -impl SVDDC for ArrayBase +impl SVDDC for ArrayRef where A: Scalar + Lapack, - S: Data, { type U = Array2; type VT = Array2; @@ -66,10 +65,9 @@ where } } -impl SVDDCInplace for ArrayBase +impl SVDDCInplace for ArrayRef where A: Scalar + Lapack, - S: DataMut, { type U = Array2; type VT = Array2; diff --git a/ndarray-linalg/src/trace.rs b/ndarray-linalg/src/trace.rs index feb119f2..5692bee3 100644 --- a/ndarray-linalg/src/trace.rs +++ b/ndarray-linalg/src/trace.rs @@ -11,10 +11,9 @@ pub trait Trace { fn trace(&self) -> Result; } -impl Trace for ArrayBase +impl Trace for ArrayRef where A: Scalar + Sum, - S: Data, { type Output = A; diff --git a/ndarray-linalg/src/triangular.rs b/ndarray-linalg/src/triangular.rs index 2741d7b0..ded0c801 100644 --- a/ndarray-linalg/src/triangular.rs +++ b/ndarray-linalg/src/triangular.rs @@ -146,12 +146,11 @@ pub trait IntoTriangular { fn into_triangular(self, uplo: UPLO) -> T; } -impl<'a, A, S> IntoTriangular<&'a mut ArrayBase> for &'a mut ArrayBase +impl<'a, A> IntoTriangular<&'a mut ArrayRef> for &'a mut ArrayRef where A: Zero, - S: DataMut, { - fn into_triangular(self, uplo: UPLO) -> &'a mut ArrayBase { + fn into_triangular(self, uplo: UPLO) -> &'a mut ArrayRef { match uplo { UPLO::Upper => { for ((i, j), val) in self.indexed_iter_mut() { @@ -178,7 +177,7 @@ where S: DataMut, { fn into_triangular(mut self, uplo: UPLO) -> ArrayBase { - (&mut self).into_triangular(uplo); + (&mut *self).into_triangular(uplo); self } } diff --git a/ndarray-linalg/src/tridiagonal.rs b/ndarray-linalg/src/tridiagonal.rs index b5aebbf2..9ff864e6 100644 --- a/ndarray-linalg/src/tridiagonal.rs +++ b/ndarray-linalg/src/tridiagonal.rs @@ -23,10 +23,9 @@ pub trait ExtractTridiagonal { fn extract_tridiagonal(&self) -> Result>; } -impl ExtractTridiagonal for ArrayBase +impl ExtractTridiagonal for ArrayRef where A: Scalar + Lapack, - S: Data, { fn extract_tridiagonal(&self) -> Result> { let l = self.square_layout()?; @@ -50,7 +49,7 @@ pub trait SolveTridiagonal { /// Solves a system of linear equations `A * x = b` with tridiagonal /// matrix `A`, where `A` is `self`, `b` is the argument, and /// `x` is the successful result. - fn solve_tridiagonal>(&self, b: &ArrayBase) -> Result>; + fn solve_tridiagonal(&self, b: &ArrayRef) -> Result>; /// Solves a system of linear equations `A * x = b` with tridiagonal /// matrix `A`, where `A` is `self`, `b` is the argument, and /// `x` is the successful result. @@ -61,7 +60,7 @@ pub trait SolveTridiagonal { /// Solves a system of linear equations `A^T * x = b` with tridiagonal /// matrix `A`, where `A` is `self`, `b` is the argument, and /// `x` is the successful result. - fn solve_t_tridiagonal>(&self, b: &ArrayBase) -> Result>; + fn solve_t_tridiagonal(&self, b: &ArrayRef) -> Result>; /// Solves a system of linear equations `A^T * x = b` with tridiagonal /// matrix `A`, where `A` is `self`, `b` is the argument, and /// `x` is the successful result. @@ -72,7 +71,7 @@ pub trait SolveTridiagonal { /// Solves a system of linear equations `A^H * x = b` with tridiagonal /// matrix `A`, where `A` is `self`, `b` is the argument, and /// `x` is the successful result. - fn solve_h_tridiagonal>(&self, b: &ArrayBase) -> Result>; + fn solve_h_tridiagonal(&self, b: &ArrayRef) -> Result>; /// Solves a system of linear equations `A^H * x = b` with tridiagonal /// matrix `A`, where `A` is `self`, `b` is the argument, and /// `x` is the successful result. @@ -87,33 +86,33 @@ pub trait SolveTridiagonalInplace { /// matrix `A`, where `A` is `self`, `b` is the argument, and /// `x` is the successful result. The value of `x` is also assigned to the /// argument. - fn solve_tridiagonal_inplace<'a, S: DataMut>( + fn solve_tridiagonal_inplace<'a>( &self, - b: &'a mut ArrayBase, - ) -> Result<&'a mut ArrayBase>; + b: &'a mut ArrayRef, + ) -> Result<&'a mut ArrayRef>; /// Solves a system of linear equations `A^T * x = b` tridiagonal /// matrix `A`, where `A` is `self`, `b` is the argument, and /// `x` is the successful result. The value of `x` is also assigned to the /// argument. - fn solve_t_tridiagonal_inplace<'a, S: DataMut>( + fn solve_t_tridiagonal_inplace<'a>( &self, - b: &'a mut ArrayBase, - ) -> Result<&'a mut ArrayBase>; + b: &'a mut ArrayRef, + ) -> Result<&'a mut ArrayRef>; /// Solves a system of linear equations `A^H * x = b` tridiagonal /// matrix `A`, where `A` is `self`, `b` is the argument, and /// `x` is the successful result. The value of `x` is also assigned to the /// argument. - fn solve_h_tridiagonal_inplace<'a, S: DataMut>( + fn solve_h_tridiagonal_inplace<'a>( &self, - b: &'a mut ArrayBase, - ) -> Result<&'a mut ArrayBase>; + b: &'a mut ArrayRef, + ) -> Result<&'a mut ArrayRef>; } impl SolveTridiagonal for LUFactorizedTridiagonal where A: Scalar + Lapack, { - fn solve_tridiagonal>(&self, b: &ArrayBase) -> Result> { + fn solve_tridiagonal(&self, b: &ArrayRef) -> Result> { let mut b = replicate(b); self.solve_tridiagonal_inplace(&mut b)?; Ok(b) @@ -125,10 +124,7 @@ where self.solve_tridiagonal_inplace(&mut b)?; Ok(b) } - fn solve_t_tridiagonal>( - &self, - b: &ArrayBase, - ) -> Result> { + fn solve_t_tridiagonal(&self, b: &ArrayRef) -> Result> { let mut b = replicate(b); self.solve_t_tridiagonal_inplace(&mut b)?; Ok(b) @@ -140,10 +136,7 @@ where self.solve_t_tridiagonal_inplace(&mut b)?; Ok(b) } - fn solve_h_tridiagonal>( - &self, - b: &ArrayBase, - ) -> Result> { + fn solve_h_tridiagonal(&self, b: &ArrayRef) -> Result> { let mut b = replicate(b); self.solve_h_tridiagonal_inplace(&mut b)?; Ok(b) @@ -161,10 +154,7 @@ impl SolveTridiagonal for Tridiagonal where A: Scalar + Lapack, { - fn solve_tridiagonal>( - &self, - b: &ArrayBase, - ) -> Result> { + fn solve_tridiagonal(&self, b: &ArrayRef) -> Result> { let mut b = replicate(b); self.solve_tridiagonal_inplace(&mut b)?; Ok(b) @@ -176,10 +166,7 @@ where self.solve_tridiagonal_inplace(&mut b)?; Ok(b) } - fn solve_t_tridiagonal>( - &self, - b: &ArrayBase, - ) -> Result> { + fn solve_t_tridiagonal(&self, b: &ArrayRef) -> Result> { let mut b = replicate(b); self.solve_t_tridiagonal_inplace(&mut b)?; Ok(b) @@ -191,10 +178,7 @@ where self.solve_t_tridiagonal_inplace(&mut b)?; Ok(b) } - fn solve_h_tridiagonal>( - &self, - b: &ArrayBase, - ) -> Result> { + fn solve_h_tridiagonal(&self, b: &ArrayRef) -> Result> { let mut b = replicate(b); self.solve_h_tridiagonal_inplace(&mut b)?; Ok(b) @@ -208,15 +192,11 @@ where } } -impl SolveTridiagonal for ArrayBase +impl SolveTridiagonal for ArrayRef where A: Scalar + Lapack, - S: Data, { - fn solve_tridiagonal>( - &self, - b: &ArrayBase, - ) -> Result> { + fn solve_tridiagonal(&self, b: &ArrayRef) -> Result> { let mut b = replicate(b); self.solve_tridiagonal_inplace(&mut b)?; Ok(b) @@ -228,10 +208,7 @@ where self.solve_tridiagonal_inplace(&mut b)?; Ok(b) } - fn solve_t_tridiagonal>( - &self, - b: &ArrayBase, - ) -> Result> { + fn solve_t_tridiagonal(&self, b: &ArrayRef) -> Result> { let mut b = replicate(b); self.solve_t_tridiagonal_inplace(&mut b)?; Ok(b) @@ -243,10 +220,7 @@ where self.solve_t_tridiagonal_inplace(&mut b)?; Ok(b) } - fn solve_h_tridiagonal>( - &self, - b: &ArrayBase, - ) -> Result> { + fn solve_h_tridiagonal(&self, b: &ArrayRef) -> Result> { let mut b = replicate(b); self.solve_h_tridiagonal_inplace(&mut b)?; Ok(b) @@ -264,13 +238,10 @@ impl SolveTridiagonalInplace for LUFactorizedTridiagonal where A: Scalar + Lapack, { - fn solve_tridiagonal_inplace<'a, Sb>( + fn solve_tridiagonal_inplace<'a>( &self, - rhs: &'a mut ArrayBase, - ) -> Result<&'a mut ArrayBase> - where - Sb: DataMut, - { + rhs: &'a mut ArrayRef, + ) -> Result<&'a mut ArrayRef> { A::solve_tridiagonal( self, rhs.layout()?, @@ -279,13 +250,10 @@ where )?; Ok(rhs) } - fn solve_t_tridiagonal_inplace<'a, Sb>( + fn solve_t_tridiagonal_inplace<'a>( &self, - rhs: &'a mut ArrayBase, - ) -> Result<&'a mut ArrayBase> - where - Sb: DataMut, - { + rhs: &'a mut ArrayRef, + ) -> Result<&'a mut ArrayRef> { A::solve_tridiagonal( self, rhs.layout()?, @@ -294,13 +262,10 @@ where )?; Ok(rhs) } - fn solve_h_tridiagonal_inplace<'a, Sb>( + fn solve_h_tridiagonal_inplace<'a>( &self, - rhs: &'a mut ArrayBase, - ) -> Result<&'a mut ArrayBase> - where - Sb: DataMut, - { + rhs: &'a mut ArrayRef, + ) -> Result<&'a mut ArrayRef> { A::solve_tridiagonal( self, rhs.layout()?, @@ -315,70 +280,51 @@ impl SolveTridiagonalInplace for Tridiagonal where A: Scalar + Lapack, { - fn solve_tridiagonal_inplace<'a, Sb>( + fn solve_tridiagonal_inplace<'a>( &self, - rhs: &'a mut ArrayBase, - ) -> Result<&'a mut ArrayBase> - where - Sb: DataMut, - { + rhs: &'a mut ArrayRef, + ) -> Result<&'a mut ArrayRef> { let f = self.factorize_tridiagonal()?; f.solve_tridiagonal_inplace(rhs) } - fn solve_t_tridiagonal_inplace<'a, Sb>( + fn solve_t_tridiagonal_inplace<'a>( &self, - rhs: &'a mut ArrayBase, - ) -> Result<&'a mut ArrayBase> - where - Sb: DataMut, - { + rhs: &'a mut ArrayRef, + ) -> Result<&'a mut ArrayRef> { let f = self.factorize_tridiagonal()?; f.solve_t_tridiagonal_inplace(rhs) } - fn solve_h_tridiagonal_inplace<'a, Sb>( + fn solve_h_tridiagonal_inplace<'a>( &self, - rhs: &'a mut ArrayBase, - ) -> Result<&'a mut ArrayBase> - where - Sb: DataMut, - { + rhs: &'a mut ArrayRef, + ) -> Result<&'a mut ArrayRef> { let f = self.factorize_tridiagonal()?; f.solve_h_tridiagonal_inplace(rhs) } } -impl SolveTridiagonalInplace for ArrayBase +impl SolveTridiagonalInplace for ArrayRef where A: Scalar + Lapack, - S: Data, { - fn solve_tridiagonal_inplace<'a, Sb>( + fn solve_tridiagonal_inplace<'a>( &self, - rhs: &'a mut ArrayBase, - ) -> Result<&'a mut ArrayBase> - where - Sb: DataMut, - { + rhs: &'a mut ArrayRef, + ) -> Result<&'a mut ArrayRef> { let f = self.factorize_tridiagonal()?; f.solve_tridiagonal_inplace(rhs) } - fn solve_t_tridiagonal_inplace<'a, Sb>( + fn solve_t_tridiagonal_inplace<'a>( &self, - rhs: &'a mut ArrayBase, - ) -> Result<&'a mut ArrayBase> - where - Sb: DataMut, - { + rhs: &'a mut ArrayRef, + ) -> Result<&'a mut ArrayRef> { let f = self.factorize_tridiagonal()?; f.solve_t_tridiagonal_inplace(rhs) } - fn solve_h_tridiagonal_inplace<'a, Sb>( + fn solve_h_tridiagonal_inplace<'a>( &self, - rhs: &'a mut ArrayBase, - ) -> Result<&'a mut ArrayBase> - where - Sb: DataMut, - { + rhs: &'a mut ArrayRef, + ) -> Result<&'a mut ArrayRef> { let f = self.factorize_tridiagonal()?; f.solve_h_tridiagonal_inplace(rhs) } @@ -388,7 +334,7 @@ impl SolveTridiagonal for LUFactorizedTridiagonal where A: Scalar + Lapack, { - fn solve_tridiagonal>(&self, b: &ArrayBase) -> Result> { + fn solve_tridiagonal(&self, b: &ArrayRef) -> Result> { let b = b.to_owned(); self.solve_tridiagonal_into(b) } @@ -400,10 +346,7 @@ where let b = self.solve_tridiagonal_into(b)?; Ok(flatten(b)) } - fn solve_t_tridiagonal>( - &self, - b: &ArrayBase, - ) -> Result> { + fn solve_t_tridiagonal(&self, b: &ArrayRef) -> Result> { let b = b.to_owned(); self.solve_t_tridiagonal_into(b) } @@ -415,10 +358,7 @@ where let b = self.solve_t_tridiagonal_into(b)?; Ok(flatten(b)) } - fn solve_h_tridiagonal>( - &self, - b: &ArrayBase, - ) -> Result> { + fn solve_h_tridiagonal(&self, b: &ArrayRef) -> Result> { let b = b.to_owned(); self.solve_h_tridiagonal_into(b) } @@ -436,10 +376,7 @@ impl SolveTridiagonal for Tridiagonal where A: Scalar + Lapack, { - fn solve_tridiagonal>( - &self, - b: &ArrayBase, - ) -> Result> { + fn solve_tridiagonal(&self, b: &ArrayRef) -> Result> { let b = b.to_owned(); self.solve_tridiagonal_into(b) } @@ -452,10 +389,7 @@ where let b = f.solve_tridiagonal_into(b)?; Ok(flatten(b)) } - fn solve_t_tridiagonal>( - &self, - b: &ArrayBase, - ) -> Result> { + fn solve_t_tridiagonal(&self, b: &ArrayRef) -> Result> { let b = b.to_owned(); self.solve_t_tridiagonal_into(b) } @@ -468,10 +402,7 @@ where let b = f.solve_t_tridiagonal_into(b)?; Ok(flatten(b)) } - fn solve_h_tridiagonal>( - &self, - b: &ArrayBase, - ) -> Result> { + fn solve_h_tridiagonal(&self, b: &ArrayRef) -> Result> { let b = b.to_owned(); self.solve_h_tridiagonal_into(b) } @@ -486,15 +417,11 @@ where } } -impl SolveTridiagonal for ArrayBase +impl SolveTridiagonal for ArrayRef where A: Scalar + Lapack, - S: Data, { - fn solve_tridiagonal>( - &self, - b: &ArrayBase, - ) -> Result> { + fn solve_tridiagonal(&self, b: &ArrayRef) -> Result> { let b = b.to_owned(); self.solve_tridiagonal_into(b) } @@ -507,10 +434,7 @@ where let b = f.solve_tridiagonal_into(b)?; Ok(flatten(b)) } - fn solve_t_tridiagonal>( - &self, - b: &ArrayBase, - ) -> Result> { + fn solve_t_tridiagonal(&self, b: &ArrayRef) -> Result> { let b = b.to_owned(); self.solve_t_tridiagonal_into(b) } @@ -523,10 +447,7 @@ where let b = f.solve_t_tridiagonal_into(b)?; Ok(flatten(b)) } - fn solve_h_tridiagonal>( - &self, - b: &ArrayBase, - ) -> Result> { + fn solve_h_tridiagonal(&self, b: &ArrayRef) -> Result> { let b = b.to_owned(); self.solve_h_tridiagonal_into(b) } @@ -574,10 +495,9 @@ where } } -impl FactorizeTridiagonal for ArrayBase +impl FactorizeTridiagonal for ArrayRef where A: Scalar + Lapack, - S: Data, { fn factorize_tridiagonal(&self) -> Result> { let a = self.extract_tridiagonal()?; @@ -626,10 +546,9 @@ where } } -impl DeterminantTridiagonal for ArrayBase +impl DeterminantTridiagonal for ArrayRef where A: Scalar + Lapack, - S: Data, { fn det_tridiagonal(&self) -> Result { let tridiag = self.extract_tridiagonal()?; @@ -684,10 +603,9 @@ where } } -impl ReciprocalConditionNumTridiagonal for ArrayBase +impl ReciprocalConditionNumTridiagonal for ArrayRef where A: Scalar + Lapack, - S: Data, { fn rcond_tridiagonal(&self) -> Result { self.factorize_tridiagonal()?.rcond_tridiagonal_into()