Skip to content

Commit 3e90e15

Browse files
committed
Replace inv()
1 parent 83be10b commit 3e90e15

File tree

3 files changed

+5
-24
lines changed

3 files changed

+5
-24
lines changed

src/prelude.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ pub use assert::*;
99
pub use qr::*;
1010
pub use svd::*;
1111
pub use opnorm::*;
12+
pub use solve::*;

src/solve.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ impl<A, S> Factorized<S>
1818
pub fn solve<Sb>(&self, t: Transpose, mut rhs: ArrayBase<Sb, Ix1>) -> Result<ArrayBase<Sb, Ix1>>
1919
where Sb: DataMut<Elem = A>
2020
{
21-
A::solve(self.a.layout()?,
21+
A::solve(self.a.square_layout()?,
2222
t,
2323
self.a.as_allocated()?,
2424
&self.ipiv,
@@ -32,7 +32,9 @@ impl<A, S> Factorized<S>
3232
S: DataMut<Elem = A>
3333
{
3434
pub fn into_inverse(mut self) -> Result<ArrayBase<S, Ix2>> {
35-
A::inv(self.a.layout()?, self.a.as_allocated_mut()?, &self.ipiv)?;
35+
A::inv(self.a.square_layout()?,
36+
self.a.as_allocated_mut()?,
37+
&self.ipiv)?;
3638
Ok(self.a)
3739
}
3840
}

src/square.rs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
11
//! Define trait for Hermite matrices
22
33
use ndarray::{Ix2, Array, RcArray, ArrayBase, Data};
4-
use lapack::c::Layout;
54

65
use super::matrix::{Matrix, MFloat};
76
use super::error::{LinalgError, NotSquareError};
8-
use super::impls::solve::ImplSolve;
97

108
/// Methods for square matrices
119
///
1210
/// This trait defines method for square matrices,
1311
/// but does not assure that the matrix is square.
1412
/// If not square, `NotSquareError` will be thrown.
1513
pub trait SquareMatrix: Matrix {
16-
// fn eig(self) -> (Self::Vector, Self);
17-
/// inverse matrix
18-
fn inv(self) -> Result<Self, LinalgError>;
1914
/// trace of matrix
2015
fn trace(&self) -> Result<Self::Scalar, LinalgError>;
2116
#[doc(hidden)]
@@ -46,30 +41,13 @@ fn trace<A: MFloat, S>(a: &ArrayBase<S, Ix2>) -> A
4641
}
4742

4843
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-
}
6144
fn trace(&self) -> Result<Self::Scalar, LinalgError> {
6245
self.check_square()?;
6346
Ok(trace(self))
6447
}
6548
}
6649

6750
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-
}
7351
fn trace(&self) -> Result<Self::Scalar, LinalgError> {
7452
self.check_square()?;
7553
Ok(trace(self))

0 commit comments

Comments
 (0)