lax/
opnorm.rs

1//! Operator norms of matrices
2
3use super::NormType;
4use crate::{layout::MatrixLayout, *};
5use cauchy::*;
6
7pub trait OperatorNorm_: Scalar {
8    fn opnorm(t: NormType, l: MatrixLayout, a: &[Self]) -> Self::Real;
9}
10
11macro_rules! impl_opnorm {
12    ($scalar:ty, $lange:path) => {
13        impl OperatorNorm_ for $scalar {
14            fn opnorm(t: NormType, l: MatrixLayout, a: &[Self]) -> Self::Real {
15                let m = l.lda();
16                let n = l.len();
17                let t = match l {
18                    MatrixLayout::F { .. } => t,
19                    MatrixLayout::C { .. } => t.transpose(),
20                };
21                let mut work = if matches!(t, NormType::Infinity) {
22                    unsafe { vec_uninit(m as usize) }
23                } else {
24                    Vec::new()
25                };
26                unsafe { $lange(t as u8, m, n, a, m, &mut work) }
27            }
28        }
29    };
30} // impl_opnorm!
31
32impl_opnorm!(f64, lapack::dlange);
33impl_opnorm!(f32, lapack::slange);
34impl_opnorm!(c64, lapack::zlange);
35impl_opnorm!(c32, lapack::clange);