Skip to content

Commit 52a504f

Browse files
committed
Merge OperatorNorm_ into Lapack trait
1 parent dfc720a commit 52a504f

File tree

2 files changed

+11
-41
lines changed

2 files changed

+11
-41
lines changed

lax/src/lib.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ pub mod eig;
9393
pub mod eigh;
9494
pub mod eigh_generalized;
9595
pub mod least_squares;
96+
pub mod opnorm;
9697
pub mod qr;
9798
pub mod rcond;
9899
pub mod solve;
@@ -101,7 +102,6 @@ pub mod svd;
101102
pub mod svddc;
102103

103104
mod alloc;
104-
mod opnorm;
105105
mod triangular;
106106
mod tridiagonal;
107107

@@ -121,7 +121,7 @@ pub type Pivot = Vec<i32>;
121121

122122
#[cfg_attr(doc, katexit::katexit)]
123123
/// Trait for primitive types which implements LAPACK subroutines
124-
pub trait Lapack: OperatorNorm_ + Triangular_ + Tridiagonal_ {
124+
pub trait Lapack: Triangular_ + Tridiagonal_ {
125125
/// Compute right eigenvalue and eigenvectors for a general matrix
126126
fn eig(
127127
calc_v: bool,
@@ -261,6 +261,9 @@ pub trait Lapack: OperatorNorm_ + Triangular_ + Tridiagonal_ {
261261
///
262262
/// `anorm` should be the 1-norm of the matrix `a`.
263263
fn rcond(l: MatrixLayout, a: &[Self], anorm: Self::Real) -> Result<Self::Real>;
264+
265+
/// Compute operator norm of a matrix
266+
fn opnorm(t: NormType, l: MatrixLayout, a: &[Self]) -> Self::Real;
264267
}
265268

266269
macro_rules! impl_lapack {
@@ -428,6 +431,12 @@ macro_rules! impl_lapack {
428431
let mut work = RcondWork::<$s>::new(l);
429432
work.calc(a, anorm)
430433
}
434+
435+
fn opnorm(t: NormType, l: MatrixLayout, a: &[Self]) -> Self::Real {
436+
use opnorm::*;
437+
let mut work = OperatorNormWork::<$s>::new(t, l);
438+
work.calc(a)
439+
}
431440
}
432441
};
433442
}

lax/src/opnorm.rs

-39
Original file line numberDiff line numberDiff line change
@@ -56,42 +56,3 @@ impl_operator_norm!(c64, lapack_sys::zlange_);
5656
impl_operator_norm!(c32, lapack_sys::clange_);
5757
impl_operator_norm!(f64, lapack_sys::dlange_);
5858
impl_operator_norm!(f32, lapack_sys::slange_);
59-
60-
pub trait OperatorNorm_: Scalar {
61-
fn opnorm(t: NormType, l: MatrixLayout, a: &[Self]) -> Self::Real;
62-
}
63-
64-
macro_rules! impl_opnorm {
65-
($scalar:ty, $lange:path) => {
66-
impl OperatorNorm_ for $scalar {
67-
fn opnorm(t: NormType, l: MatrixLayout, a: &[Self]) -> Self::Real {
68-
let m = l.lda();
69-
let n = l.len();
70-
let t = match l {
71-
MatrixLayout::F { .. } => t,
72-
MatrixLayout::C { .. } => t.transpose(),
73-
};
74-
let mut work: Vec<MaybeUninit<Self::Real>> = if matches!(t, NormType::Infinity) {
75-
vec_uninit(m as usize)
76-
} else {
77-
Vec::new()
78-
};
79-
unsafe {
80-
$lange(
81-
t.as_ptr(),
82-
&m,
83-
&n,
84-
AsPtr::as_ptr(a),
85-
&m,
86-
AsPtr::as_mut_ptr(&mut work),
87-
)
88-
}
89-
}
90-
}
91-
};
92-
} // impl_opnorm!
93-
94-
impl_opnorm!(f64, lapack_sys::dlange_);
95-
impl_opnorm!(f32, lapack_sys::slange_);
96-
impl_opnorm!(c64, lapack_sys::zlange_);
97-
impl_opnorm!(c32, lapack_sys::clange_);

0 commit comments

Comments
 (0)