Skip to content

Commit

Permalink
Merge OperatorNorm_ into Lapack trait
Browse files Browse the repository at this point in the history
  • Loading branch information
termoshtt committed Oct 1, 2022
1 parent dfc720a commit 52a504f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 41 deletions.
13 changes: 11 additions & 2 deletions lax/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ pub mod eig;
pub mod eigh;
pub mod eigh_generalized;
pub mod least_squares;
pub mod opnorm;
pub mod qr;
pub mod rcond;
pub mod solve;
Expand All @@ -101,7 +102,6 @@ pub mod svd;
pub mod svddc;

mod alloc;
mod opnorm;
mod triangular;
mod tridiagonal;

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

#[cfg_attr(doc, katexit::katexit)]
/// Trait for primitive types which implements LAPACK subroutines
pub trait Lapack: OperatorNorm_ + Triangular_ + Tridiagonal_ {
pub trait Lapack: Triangular_ + Tridiagonal_ {
/// Compute right eigenvalue and eigenvectors for a general matrix
fn eig(
calc_v: bool,
Expand Down Expand Up @@ -261,6 +261,9 @@ pub trait Lapack: OperatorNorm_ + Triangular_ + Tridiagonal_ {
///
/// `anorm` should be the 1-norm of the matrix `a`.
fn rcond(l: MatrixLayout, a: &[Self], anorm: Self::Real) -> Result<Self::Real>;

/// Compute operator norm of a matrix
fn opnorm(t: NormType, l: MatrixLayout, a: &[Self]) -> Self::Real;
}

macro_rules! impl_lapack {
Expand Down Expand Up @@ -428,6 +431,12 @@ macro_rules! impl_lapack {
let mut work = RcondWork::<$s>::new(l);
work.calc(a, anorm)
}

fn opnorm(t: NormType, l: MatrixLayout, a: &[Self]) -> Self::Real {
use opnorm::*;
let mut work = OperatorNormWork::<$s>::new(t, l);
work.calc(a)
}
}
};
}
Expand Down
39 changes: 0 additions & 39 deletions lax/src/opnorm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,42 +56,3 @@ impl_operator_norm!(c64, lapack_sys::zlange_);
impl_operator_norm!(c32, lapack_sys::clange_);
impl_operator_norm!(f64, lapack_sys::dlange_);
impl_operator_norm!(f32, lapack_sys::slange_);

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_);

0 comments on commit 52a504f

Please # to comment.