Skip to content

Commit 58f3775

Browse files
committed
Add Cholesky impl
1 parent dc1a71c commit 58f3775

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

src/impl2/cholesky.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//! implement Cholesky decomposition
2+
3+
use lapack::c;
4+
5+
use types::*;
6+
use error::*;
7+
use layout::Layout;
8+
9+
use super::into_result;
10+
11+
pub trait Cholesky_: Sized {
12+
fn cholesky(Layout, a: &mut [Self]) -> Result<()>;
13+
}
14+
15+
macro_rules! impl_cholesky {
16+
($scalar:ty, $potrf:path) => {
17+
impl Cholesky_ for $scalar {
18+
fn cholesky(l: Layout, mut a: &mut [Self]) -> Result<()> {
19+
let (n, _) = l.size();
20+
let info = $potrf(l.lapacke_layout(), b'U', n, &mut a, n);
21+
into_result(info, ())
22+
}
23+
}
24+
}} // end macro_rules
25+
26+
impl_cholesky!(f64, c::dpotrf);
27+
impl_cholesky!(f32, c::spotrf);
28+
impl_cholesky!(c64, c::zpotrf);
29+
impl_cholesky!(c32, c::cpotrf);

src/impl2/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@ pub mod opnorm;
33
pub mod qr;
44
pub mod svd;
55
pub mod solve;
6+
pub mod cholesky;
67

78
pub use self::opnorm::*;
89
pub use self::qr::*;
910
pub use self::svd::*;
1011
pub use self::solve::*;
12+
pub use self::cholesky::*;
1113

1214
use super::error::*;
1315

14-
pub trait LapackScalar: OperatorNorm_ + QR_ + SVD_ + Solve_ {}
15-
impl<A> LapackScalar for A where A: OperatorNorm_ + QR_ + SVD_ + Solve_ {}
16+
pub trait LapackScalar: OperatorNorm_ + QR_ + SVD_ + Solve_ + Cholesky_ {}
17+
impl<A> LapackScalar for A where A: OperatorNorm_ + QR_ + SVD_ + Solve_ + Cholesky_ {}
1618

1719
pub fn into_result<T>(info: i32, val: T) -> Result<T> {
1820
if info == 0 {

0 commit comments

Comments
 (0)