1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
use lax::Tridiagonal;
use ndarray::*;
use crate::error::*;
use crate::layout::*;
use crate::types::*;
pub use lax::NormType;
pub trait OperationNorm {
type Output: Scalar;
fn opnorm(&self, t: NormType) -> Result<Self::Output>;
fn opnorm_one(&self) -> Result<Self::Output> {
self.opnorm(NormType::One)
}
fn opnorm_inf(&self) -> Result<Self::Output> {
self.opnorm(NormType::Infinity)
}
fn opnorm_fro(&self) -> Result<Self::Output> {
self.opnorm(NormType::Frobenius)
}
}
impl<A, S> OperationNorm for ArrayBase<S, Ix2>
where
A: Scalar + Lapack,
S: Data<Elem = A>,
{
type Output = A::Real;
fn opnorm(&self, t: NormType) -> Result<Self::Output> {
let l = self.layout()?;
let a = self.as_allocated()?;
Ok(A::opnorm(t, l, a))
}
}
impl<A> OperationNorm for Tridiagonal<A>
where
A: Scalar + Lapack,
{
type Output = A::Real;
fn opnorm(&self, t: NormType) -> Result<Self::Output> {
let arr = match t {
NormType::One => {
let zl: Array1<A> = Array::zeros(1);
let zu: Array1<A> = Array::zeros(1);
let dl = concatenate![Axis(0), &self.dl, zl];
let du = concatenate![Axis(0), zu, &self.du];
stack![Axis(0), du, &self.d, dl]
}
NormType::Infinity => {
let zl: Array1<A> = Array::zeros(1);
let zu: Array1<A> = Array::zeros(1);
let dl = concatenate![Axis(0), zl, &self.dl];
let du = concatenate![Axis(0), &self.du, zu];
stack![Axis(1), dl, &self.d, du]
}
NormType::Frobenius => {
concatenate![Axis(0), &self.dl, &self.d, &self.du].insert_axis(Axis(0))
}
};
let l = arr.layout()?;
let a = arr.as_allocated()?;
Ok(A::opnorm(t, l, a))
}
}