|
1 | 1 | //! Define trait for Hermite matrices
|
2 | 2 |
|
3 | 3 | use ndarray::{Ix2, Array, RcArray, ArrayBase, Data};
|
4 |
| -use lapack::c::Layout; |
5 | 4 |
|
6 | 5 | use super::matrix::{Matrix, MFloat};
|
7 | 6 | use super::error::{LinalgError, NotSquareError};
|
8 |
| -use super::impls::solve::ImplSolve; |
9 | 7 |
|
10 | 8 | /// Methods for square matrices
|
11 | 9 | ///
|
12 | 10 | /// This trait defines method for square matrices,
|
13 | 11 | /// but does not assure that the matrix is square.
|
14 | 12 | /// If not square, `NotSquareError` will be thrown.
|
15 | 13 | pub trait SquareMatrix: Matrix {
|
16 |
| - // fn eig(self) -> (Self::Vector, Self); |
17 |
| - /// inverse matrix |
18 |
| - fn inv(self) -> Result<Self, LinalgError>; |
19 | 14 | /// trace of matrix
|
20 | 15 | fn trace(&self) -> Result<Self::Scalar, LinalgError>;
|
21 | 16 | #[doc(hidden)]
|
@@ -46,30 +41,13 @@ fn trace<A: MFloat, S>(a: &ArrayBase<S, Ix2>) -> A
|
46 | 41 | }
|
47 | 42 |
|
48 | 43 | impl<A: MFloat> SquareMatrix for Array<A, Ix2> {
|
49 |
| - fn inv(self) -> Result<Self, LinalgError> { |
50 |
| - self.check_square()?; |
51 |
| - let (n, _) = self.size(); |
52 |
| - let layout = self.layout()?; |
53 |
| - let (ipiv, a) = ImplSolve::lu(layout, n, n, self.into_raw_vec())?; |
54 |
| - let a = ImplSolve::inv(layout, n, a, &ipiv)?; |
55 |
| - let m = Array::from_vec(a).into_shape((n, n)).unwrap(); |
56 |
| - match layout { |
57 |
| - Layout::RowMajor => Ok(m), |
58 |
| - Layout::ColumnMajor => Ok(m.reversed_axes()), |
59 |
| - } |
60 |
| - } |
61 | 44 | fn trace(&self) -> Result<Self::Scalar, LinalgError> {
|
62 | 45 | self.check_square()?;
|
63 | 46 | Ok(trace(self))
|
64 | 47 | }
|
65 | 48 | }
|
66 | 49 |
|
67 | 50 | impl<A: MFloat> SquareMatrix for RcArray<A, Ix2> {
|
68 |
| - fn inv(self) -> Result<Self, LinalgError> { |
69 |
| - // XXX unnecessary clone (should use into_owned()) |
70 |
| - let i = self.to_owned().inv()?; |
71 |
| - Ok(i.into_shared()) |
72 |
| - } |
73 | 51 | fn trace(&self) -> Result<Self::Scalar, LinalgError> {
|
74 | 52 | self.check_square()?;
|
75 | 53 | Ok(trace(self))
|
|
0 commit comments