Skip to content

Commit a118bf0

Browse files
committed
Merge Rcond_ into Lapack trait
1 parent 09f9226 commit a118bf0

File tree

2 files changed

+13
-85
lines changed

2 files changed

+13
-85
lines changed

lax/src/lib.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,22 +94,21 @@ pub mod eigh;
9494
pub mod eigh_generalized;
9595
pub mod least_squares;
9696
pub mod qr;
97+
pub mod rcond;
9798
pub mod solve;
9899
pub mod solveh;
99100
pub mod svd;
100101
pub mod svddc;
101102

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

108108
pub use self::cholesky::*;
109109
pub use self::flags::*;
110110
pub use self::least_squares::LeastSquaresOwned;
111111
pub use self::opnorm::*;
112-
pub use self::rcond::*;
113112
pub use self::svd::{SvdOwned, SvdRef};
114113
pub use self::triangular::*;
115114
pub use self::tridiagonal::*;
@@ -122,7 +121,7 @@ pub type Pivot = Vec<i32>;
122121

123122
#[cfg_attr(doc, katexit::katexit)]
124123
/// Trait for primitive types which implements LAPACK subroutines
125-
pub trait Lapack: OperatorNorm_ + Triangular_ + Tridiagonal_ + Rcond_ {
124+
pub trait Lapack: OperatorNorm_ + Triangular_ + Tridiagonal_ {
126125
/// Compute right eigenvalue and eigenvectors for a general matrix
127126
fn eig(
128127
calc_v: bool,
@@ -257,6 +256,11 @@ pub trait Lapack: OperatorNorm_ + Triangular_ + Tridiagonal_ + Rcond_ {
257256

258257
/// Solve linear equation $Ax = b$ using $U$ or $L$ calculated by [Lapack::cholesky]
259258
fn solve_cholesky(l: MatrixLayout, uplo: UPLO, a: &[Self], b: &mut [Self]) -> Result<()>;
259+
260+
/// Estimates the the reciprocal of the condition number of the matrix in 1-norm.
261+
///
262+
/// `anorm` should be the 1-norm of the matrix `a`.
263+
fn rcond(l: MatrixLayout, a: &[Self], anorm: Self::Real) -> Result<Self::Real>;
260264
}
261265

262266
macro_rules! impl_lapack {
@@ -418,6 +422,12 @@ macro_rules! impl_lapack {
418422
use cholesky::*;
419423
SolveCholeskyImpl::solve_cholesky(l, uplo, a, b)
420424
}
425+
426+
fn rcond(l: MatrixLayout, a: &[Self], anorm: Self::Real) -> Result<Self::Real> {
427+
use rcond::*;
428+
let mut work = RcondWork::<$s>::new(l);
429+
work.calc(a, anorm)
430+
}
421431
}
422432
};
423433
}

lax/src/rcond.rs

Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -120,85 +120,3 @@ macro_rules! impl_rcond_work_r {
120120
}
121121
impl_rcond_work_r!(f64, lapack_sys::dgecon_);
122122
impl_rcond_work_r!(f32, lapack_sys::sgecon_);
123-
124-
pub trait Rcond_: Scalar + Sized {
125-
/// Estimates the the reciprocal of the condition number of the matrix in 1-norm.
126-
///
127-
/// `anorm` should be the 1-norm of the matrix `a`.
128-
fn rcond(l: MatrixLayout, a: &[Self], anorm: Self::Real) -> Result<Self::Real>;
129-
}
130-
131-
macro_rules! impl_rcond_real {
132-
($scalar:ty, $gecon:path) => {
133-
impl Rcond_ for $scalar {
134-
fn rcond(l: MatrixLayout, a: &[Self], anorm: Self::Real) -> Result<Self::Real> {
135-
let (n, _) = l.size();
136-
let mut rcond = Self::Real::zero();
137-
let mut info = 0;
138-
139-
let mut work: Vec<MaybeUninit<Self>> = vec_uninit(4 * n as usize);
140-
let mut iwork: Vec<MaybeUninit<i32>> = vec_uninit(n as usize);
141-
let norm_type = match l {
142-
MatrixLayout::C { .. } => NormType::Infinity,
143-
MatrixLayout::F { .. } => NormType::One,
144-
};
145-
unsafe {
146-
$gecon(
147-
norm_type.as_ptr(),
148-
&n,
149-
AsPtr::as_ptr(a),
150-
&l.lda(),
151-
&anorm,
152-
&mut rcond,
153-
AsPtr::as_mut_ptr(&mut work),
154-
AsPtr::as_mut_ptr(&mut iwork),
155-
&mut info,
156-
)
157-
};
158-
info.as_lapack_result()?;
159-
160-
Ok(rcond)
161-
}
162-
}
163-
};
164-
}
165-
166-
impl_rcond_real!(f32, lapack_sys::sgecon_);
167-
impl_rcond_real!(f64, lapack_sys::dgecon_);
168-
169-
macro_rules! impl_rcond_complex {
170-
($scalar:ty, $gecon:path) => {
171-
impl Rcond_ for $scalar {
172-
fn rcond(l: MatrixLayout, a: &[Self], anorm: Self::Real) -> Result<Self::Real> {
173-
let (n, _) = l.size();
174-
let mut rcond = Self::Real::zero();
175-
let mut info = 0;
176-
let mut work: Vec<MaybeUninit<Self>> = vec_uninit(2 * n as usize);
177-
let mut rwork: Vec<MaybeUninit<Self::Real>> = vec_uninit(2 * n as usize);
178-
let norm_type = match l {
179-
MatrixLayout::C { .. } => NormType::Infinity,
180-
MatrixLayout::F { .. } => NormType::One,
181-
};
182-
unsafe {
183-
$gecon(
184-
norm_type.as_ptr(),
185-
&n,
186-
AsPtr::as_ptr(a),
187-
&l.lda(),
188-
&anorm,
189-
&mut rcond,
190-
AsPtr::as_mut_ptr(&mut work),
191-
AsPtr::as_mut_ptr(&mut rwork),
192-
&mut info,
193-
)
194-
};
195-
info.as_lapack_result()?;
196-
197-
Ok(rcond)
198-
}
199-
}
200-
};
201-
}
202-
203-
impl_rcond_complex!(c32, lapack_sys::cgecon_);
204-
impl_rcond_complex!(c64, lapack_sys::zgecon_);

0 commit comments

Comments
 (0)