1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use lapack::c;
use super::{Transpose, UPLO, into_result};
use error::*;
use layout::MatrixLayout;
use types::*;
#[derive(Debug, Clone, Copy)]
#[repr(u8)]
pub enum Diag {
Unit = b'U',
NonUnit = b'N',
}
pub trait Triangular_: Sized {
fn inv_triangular(l: MatrixLayout, UPLO, Diag, a: &mut [Self]) -> Result<()>;
fn solve_triangular(al: MatrixLayout, bl: MatrixLayout, UPLO, Diag, a: &[Self], b: &mut [Self]) -> Result<()>;
}
macro_rules! impl_triangular {
($scalar:ty, $trtri:path, $trtrs:path) => {
impl Triangular_ for $scalar {
fn inv_triangular(l: MatrixLayout, uplo: UPLO, diag: Diag, a: &mut [Self]) -> Result<()> {
let (n, _) = l.size();
let lda = l.lda();
let info = $trtri(l.lapacke_layout(), uplo as u8, diag as u8, n, a, lda);
into_result(info, ())
}
fn solve_triangular(al: MatrixLayout, bl: MatrixLayout, uplo: UPLO, diag: Diag, a: &[Self], mut b: &mut [Self]) -> Result<()> {
let (n, _) = al.size();
let lda = al.lda();
let (_, nrhs) = bl.size();
let ldb = bl.lda();
println!("al = {:?}", al);
println!("bl = {:?}", bl);
println!("n = {}", n);
println!("lda = {}", lda);
println!("nrhs = {}", nrhs);
println!("ldb = {}", ldb);
let info = $trtrs(al.lapacke_layout(), uplo as u8, Transpose::No as u8, diag as u8, n, nrhs, a, lda, &mut b, ldb);
into_result(info, ())
}
}
}}
impl_triangular!(f64, c::dtrtri, c::dtrtrs);
impl_triangular!(f32, c::strtri, c::strtrs);
impl_triangular!(c64, c::ztrtri, c::ztrtrs);
impl_triangular!(c32, c::ctrtri, c::ctrtrs);