Skip to content

Commit 5f6a2c3

Browse files
committed
Rewrite opnorm by LAPACK
1 parent 4a96e4d commit 5f6a2c3

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

lax/src/opnorm.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use crate::layout::MatrixLayout;
44
use cauchy::*;
5-
use lapacke::Layout::ColumnMajor as cm;
5+
use num_traits::Zero;
66

77
pub use super::NormType;
88

@@ -14,18 +14,24 @@ macro_rules! impl_opnorm {
1414
($scalar:ty, $lange:path) => {
1515
impl OperatorNorm_ for $scalar {
1616
unsafe fn opnorm(t: NormType, l: MatrixLayout, a: &[Self]) -> Self::Real {
17-
match l {
18-
MatrixLayout::F { col, lda } => $lange(cm, t as u8, lda, col, a, lda),
19-
MatrixLayout::C { row, lda } => {
20-
$lange(cm, t.transpose() as u8, lda, row, a, lda)
21-
}
22-
}
17+
let m = l.lda();
18+
let n = l.len();
19+
let t = match l {
20+
MatrixLayout::F { .. } => t,
21+
MatrixLayout::C { .. } => t.transpose(),
22+
};
23+
let mut work = if matches!(t, NormType::Infinity) {
24+
vec![Self::Real::zero(); m as usize]
25+
} else {
26+
Vec::new()
27+
};
28+
$lange(t as u8, m, n, a, m, &mut work)
2329
}
2430
}
2531
};
2632
} // impl_opnorm!
2733

28-
impl_opnorm!(f64, lapacke::dlange);
29-
impl_opnorm!(f32, lapacke::slange);
30-
impl_opnorm!(c64, lapacke::zlange);
31-
impl_opnorm!(c32, lapacke::clange);
34+
impl_opnorm!(f64, lapack::dlange);
35+
impl_opnorm!(f32, lapack::slange);
36+
impl_opnorm!(c64, lapack::zlange);
37+
impl_opnorm!(c32, lapack::clange);

0 commit comments

Comments
 (0)