|
1 | 1 | //! Cholesky decomposition |
2 | 2 |
|
3 | 3 | use ndarray::*; |
4 | | -use num_traits::Zero; |
5 | 4 |
|
6 | 5 | use super::convert::*; |
7 | 6 | use super::error::*; |
8 | 7 | use super::layout::*; |
9 | 8 | use super::triangular::IntoTriangular; |
| 9 | +use super::types::*; |
10 | 10 |
|
11 | | -use lapack_traits::LapackScalar; |
12 | 11 | pub use lapack_traits::UPLO; |
13 | 12 |
|
14 | | -pub trait Cholesky<K> { |
15 | | - fn cholesky(self, UPLO) -> Result<K>; |
| 13 | +pub trait Cholesky { |
| 14 | + type Output; |
| 15 | + fn cholesky(&self, UPLO) -> Result<Self::Output>; |
16 | 16 | } |
17 | 17 |
|
18 | | -impl<A, S> Cholesky<ArrayBase<S, Ix2>> for ArrayBase<S, Ix2> |
| 18 | +pub trait CholeskyInto: Sized { |
| 19 | + fn cholesky_into(self, UPLO) -> Result<Self>; |
| 20 | +} |
| 21 | + |
| 22 | +pub trait CholeskyMut { |
| 23 | + fn cholesky_mut(&mut self, UPLO) -> Result<&mut Self>; |
| 24 | +} |
| 25 | + |
| 26 | +impl<A, S> CholeskyInto for ArrayBase<S, Ix2> |
19 | 27 | where |
20 | | - A: LapackScalar + Zero, |
| 28 | + A: Scalar, |
21 | 29 | S: DataMut<Elem = A>, |
22 | 30 | { |
23 | | - fn cholesky(mut self, uplo: UPLO) -> Result<ArrayBase<S, Ix2>> { |
| 31 | + fn cholesky_into(mut self, uplo: UPLO) -> Result<Self> { |
24 | 32 | A::cholesky(self.square_layout()?, uplo, self.as_allocated_mut()?)?; |
25 | 33 | Ok(self.into_triangular(uplo)) |
26 | 34 | } |
27 | 35 | } |
28 | 36 |
|
29 | | -impl<'a, A, S> Cholesky<&'a mut ArrayBase<S, Ix2>> for &'a mut ArrayBase<S, Ix2> |
| 37 | +impl<A, S> CholeskyMut for ArrayBase<S, Ix2> |
30 | 38 | where |
31 | | - A: LapackScalar + Zero, |
| 39 | + A: Scalar, |
32 | 40 | S: DataMut<Elem = A>, |
33 | 41 | { |
34 | | - fn cholesky(mut self, uplo: UPLO) -> Result<&'a mut ArrayBase<S, Ix2>> { |
| 42 | + fn cholesky_mut(&mut self, uplo: UPLO) -> Result<&mut Self> { |
35 | 43 | A::cholesky(self.square_layout()?, uplo, self.as_allocated_mut()?)?; |
36 | 44 | Ok(self.into_triangular(uplo)) |
37 | 45 | } |
38 | 46 | } |
39 | 47 |
|
40 | | -impl<'a, A, Si, So> Cholesky<ArrayBase<So, Ix2>> for &'a ArrayBase<Si, Ix2> |
| 48 | +impl<A, S> Cholesky for ArrayBase<S, Ix2> |
41 | 49 | where |
42 | | - A: LapackScalar + Copy + Zero, |
43 | | - Si: Data<Elem = A>, |
44 | | - So: DataMut<Elem = A> + DataOwned, |
| 50 | + A: Scalar, |
| 51 | + S: Data<Elem = A>, |
45 | 52 | { |
46 | | - fn cholesky(self, uplo: UPLO) -> Result<ArrayBase<So, Ix2>> { |
| 53 | + type Output = Array2<A>; |
| 54 | + |
| 55 | + fn cholesky(&self, uplo: UPLO) -> Result<Self::Output> { |
47 | 56 | let mut a = replicate(self); |
48 | 57 | A::cholesky(a.square_layout()?, uplo, a.as_allocated_mut()?)?; |
49 | 58 | Ok(a.into_triangular(uplo)) |
|
0 commit comments