Skip to content

Commit ec4ff5a

Browse files
committed
Split traits.rs
1 parent 4e65a47 commit ec4ff5a

File tree

4 files changed

+42
-32
lines changed

4 files changed

+42
-32
lines changed

src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ pub mod layout;
4848
pub mod impls;
4949
pub mod impl2;
5050

51-
pub mod traits;
51+
pub mod qr;
52+
pub mod opnorm;
5253

5354
pub mod vector;
5455
pub mod matrix;

src/opnorm.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
use ndarray::*;
3+
4+
use super::types::*;
5+
use super::error::*;
6+
use super::layout::*;
7+
8+
pub use impl2::NormType;
9+
use impl2::LapackScalar;
10+
11+
pub trait OperationNorm {
12+
type Output;
13+
fn opnorm(&self, t: NormType) -> Self::Output;
14+
fn opnorm_one(&self) -> Self::Output {
15+
self.opnorm(NormType::One)
16+
}
17+
fn opnorm_inf(&self) -> Self::Output {
18+
self.opnorm(NormType::Infinity)
19+
}
20+
fn opnorm_fro(&self) -> Self::Output {
21+
self.opnorm(NormType::Frobenius)
22+
}
23+
}
24+
25+
impl<A, S> OperationNorm for ArrayBase<S, Ix2>
26+
where A: LapackScalar + AssociatedReal,
27+
S: Data<Elem = A>
28+
{
29+
type Output = Result<A::Real>;
30+
31+
fn opnorm(&self, t: NormType) -> Self::Output {
32+
let l = self.layout()?;
33+
let a = self.as_allocated()?;
34+
Ok(A::opnorm(t, l, a))
35+
}
36+
}

src/prelude.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ pub use hermite::HermiteMatrix;
55
pub use triangular::*;
66
pub use util::*;
77
pub use assert::*;
8-
pub use traits::*;
8+
9+
pub use qr::*;
10+
pub use opnorm::*;

src/traits.rs renamed to src/qr.rs

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,11 @@
11

2-
pub use impl2::LapackScalar;
3-
pub use impl2::NormType;
4-
52
use num_traits::Zero;
63
use ndarray::*;
74

8-
use super::types::*;
95
use super::error::*;
106
use super::layout::*;
117

12-
pub trait OperationNorm {
13-
type Output;
14-
fn opnorm(&self, t: NormType) -> Self::Output;
15-
fn opnorm_one(&self) -> Self::Output {
16-
self.opnorm(NormType::One)
17-
}
18-
fn opnorm_inf(&self) -> Self::Output {
19-
self.opnorm(NormType::Infinity)
20-
}
21-
fn opnorm_fro(&self) -> Self::Output {
22-
self.opnorm(NormType::Frobenius)
23-
}
24-
}
25-
26-
impl<A, S> OperationNorm for ArrayBase<S, Ix2>
27-
where A: LapackScalar + AssociatedReal,
28-
S: Data<Elem = A>
29-
{
30-
type Output = Result<A::Real>;
31-
32-
fn opnorm(&self, t: NormType) -> Self::Output {
33-
let l = self.layout()?;
34-
let a = self.as_allocated()?;
35-
Ok(A::opnorm(t, l, a))
36-
}
37-
}
8+
use impl2::LapackScalar;
389

3910
pub trait QR<Q, R> {
4011
fn qr(self) -> Result<(Q, R)>;

0 commit comments

Comments
 (0)