-
Notifications
You must be signed in to change notification settings - Fork 65
/
opnorm.rs
44 lines (40 loc) · 1.34 KB
/
opnorm.rs
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
//! Operator norms of matrices
use super::{AsPtr, NormType};
use crate::{layout::MatrixLayout, *};
use cauchy::*;
pub trait OperatorNorm_: Scalar {
fn opnorm(t: NormType, l: MatrixLayout, a: &[Self]) -> Self::Real;
}
macro_rules! impl_opnorm {
($scalar:ty, $lange:path) => {
impl OperatorNorm_ for $scalar {
fn opnorm(t: NormType, l: MatrixLayout, a: &[Self]) -> Self::Real {
let m = l.lda();
let n = l.len();
let t = match l {
MatrixLayout::F { .. } => t,
MatrixLayout::C { .. } => t.transpose(),
};
let mut work: Vec<MaybeUninit<Self::Real>> = if matches!(t, NormType::Infinity) {
vec_uninit(m as usize)
} else {
Vec::new()
};
unsafe {
$lange(
t.as_ptr(),
&m,
&n,
AsPtr::as_ptr(a),
&m,
AsPtr::as_mut_ptr(&mut work),
)
}
}
}
};
} // impl_opnorm!
impl_opnorm!(f64, lapack_sys::dlange_);
impl_opnorm!(f32, lapack_sys::slange_);
impl_opnorm!(c64, lapack_sys::zlange_);
impl_opnorm!(c32, lapack_sys::clange_);