Skip to content

Commit a0ef374

Browse files
committed
Add impl2/triangular.rs
1 parent a5ee745 commit a0ef374

File tree

4 files changed

+70
-9
lines changed

4 files changed

+70
-9
lines changed

src/impl2/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ pub mod svd;
55
pub mod solve;
66
pub mod cholesky;
77
pub mod eigh;
8+
pub mod triangular;
89

910
pub use self::opnorm::*;
1011
pub use self::qr::*;
@@ -32,3 +33,11 @@ pub enum UPLO {
3233
Upper = b'U',
3334
Lower = b'L',
3435
}
36+
37+
#[derive(Debug, Clone, Copy)]
38+
#[repr(u8)]
39+
pub enum Transpose {
40+
No = b'N',
41+
Transpose = b'T',
42+
Hermite = b'C',
43+
}

src/impl2/solve.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,10 @@ use types::*;
55
use error::*;
66
use layout::Layout;
77

8-
use super::into_result;
8+
use super::{Transpose, into_result};
99

1010
pub type Pivot = Vec<i32>;
1111

12-
#[derive(Debug, Clone, Copy)]
13-
#[repr(u8)]
14-
pub enum Transpose {
15-
No = b'N',
16-
Transpose = b'T',
17-
Hermite = b'C',
18-
}
19-
2012
pub trait Solve_: Sized {
2113
fn lu(Layout, a: &mut [Self]) -> Result<Pivot>;
2214
fn inv(Layout, a: &mut [Self], &Pivot) -> Result<()>;

src/impl2/triangular.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//! Implement linear solver and inverse matrix
2+
3+
use lapack::c;
4+
5+
use error::*;
6+
use layout::Layout;
7+
use super::{UPLO, Transpose, into_result};
8+
9+
#[derive(Debug, Clone, Copy)]
10+
#[repr(u8)]
11+
pub enum TriangularDiag {
12+
Unit = b'U',
13+
NonUnit = b'N',
14+
}
15+
16+
pub trait Triangular_: Sized {
17+
fn inv_triangular(l: Layout, UPLO, TriangularDiag, a: &mut [Self]) -> Result<()>;
18+
fn solve_triangular(al: Layout, bl: Layout, UPLO, TriangularDiag, a: &[Self], b: &mut [Self]) -> Result<()>;
19+
}
20+
21+
impl Triangular_ for f64 {
22+
fn inv_triangular(l: Layout, uplo: UPLO, diag: TriangularDiag, a: &mut [Self]) -> Result<()> {
23+
let (n, _) = l.size();
24+
let lda = l.lda();
25+
let info = c::dtrtri(l.lapacke_layout(), uplo as u8, diag as u8, n, a, lda);
26+
into_result(info, ())
27+
}
28+
29+
fn solve_triangular(al: Layout,
30+
bl: Layout,
31+
uplo: UPLO,
32+
diag: TriangularDiag,
33+
a: &[Self],
34+
mut b: &mut [Self])
35+
-> Result<()> {
36+
let (n, _) = al.size();
37+
let lda = al.lda();
38+
let nrhs = bl.len();
39+
let ldb = bl.lda();
40+
let info = c::dtrtrs(al.lapacke_layout(),
41+
uplo as u8,
42+
Transpose::No as u8,
43+
diag as u8,
44+
n,
45+
nrhs,
46+
a,
47+
lda,
48+
&mut b,
49+
ldb);
50+
into_result(info, ())
51+
}
52+
}

src/layout.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use lapack::c;
55
use super::error::*;
66

77
pub type LDA = i32;
8+
pub type LEN = i32;
89
pub type Col = i32;
910
pub type Row = i32;
1011

@@ -36,6 +37,13 @@ impl Layout {
3637
}
3738
}
3839

40+
pub fn len(&self) -> LEN {
41+
match *self {
42+
Layout::C((row, _)) => row,
43+
Layout::F((col, _)) => col,
44+
}
45+
}
46+
3947
pub fn lapacke_layout(&self) -> c::Layout {
4048
match *self {
4149
Layout::C(_) => c::Layout::RowMajor,

0 commit comments

Comments
 (0)