|
| 1 | +//! Solve symmetric linear problem using the Bunch-Kaufman diagonal pivoting method. |
| 2 | +//! |
| 3 | +//! See also [the manual of dsytrf](http://www.netlib.org/lapack/lapack-3.1.1/html/dsytrf.f.html) |
| 4 | +
|
| 5 | +use lapack::c; |
| 6 | + |
| 7 | +use error::*; |
| 8 | +use layout::MatrixLayout; |
| 9 | +use types::*; |
| 10 | + |
| 11 | +use super::{Pivot, UPLO, into_result}; |
| 12 | + |
| 13 | +pub trait Solveh_: Sized { |
| 14 | + /// Bunch-Kaufman: wrapper of `*sytrf` and `*hetrf` |
| 15 | + unsafe fn bk(MatrixLayout, UPLO, a: &mut [Self]) -> Result<Pivot>; |
| 16 | + /// Wrapper of `*sytri` and `*hetri` |
| 17 | + unsafe fn inv(MatrixLayout, UPLO, a: &mut [Self], &Pivot) -> Result<()>; |
| 18 | + /// Wrapper of `*sytrs` and `*hetrs` |
| 19 | + unsafe fn solve(MatrixLayout, UPLO, a: &[Self], &Pivot, b: &mut [Self]) -> Result<()>; |
| 20 | +} |
| 21 | + |
| 22 | +macro_rules! impl_solveh { |
| 23 | + ($scalar:ty, $trf:path, $tri:path, $trs:path) => { |
| 24 | + |
| 25 | +impl Solveh_ for $scalar { |
| 26 | + unsafe fn bk(l: MatrixLayout, uplo: UPLO, a: &mut [Self]) -> Result<Pivot> { |
| 27 | + let (n, _) = l.size(); |
| 28 | + let mut ipiv = vec![0; n as usize]; |
| 29 | + let info = $trf(l.lapacke_layout(), uplo as u8, n, a, l.lda(), &mut ipiv); |
| 30 | + into_result(info, ipiv) |
| 31 | + } |
| 32 | + |
| 33 | + unsafe fn inv(l: MatrixLayout, uplo: UPLO, a: &mut [Self], ipiv: &Pivot) -> Result<()> { |
| 34 | + let (n, _) = l.size(); |
| 35 | + let info = $tri(l.lapacke_layout(), uplo as u8, n, a, l.lda(), ipiv); |
| 36 | + into_result(info, ()) |
| 37 | + } |
| 38 | + |
| 39 | + unsafe fn solve(l: MatrixLayout, uplo: UPLO, a: &[Self], ipiv: &Pivot, b: &mut [Self]) -> Result<()> { |
| 40 | + let (n, _) = l.size(); |
| 41 | + let nrhs = 1; |
| 42 | + let ldb = 1; |
| 43 | + let info = $trs(l.lapacke_layout(), uplo as u8, n, nrhs, a, l.lda(), ipiv, b, ldb); |
| 44 | + into_result(info, ()) |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +}} // impl_solveh! |
| 49 | + |
| 50 | +impl_solveh!(f64, c::dsytrf, c::dsytri, c::dsytrs); |
| 51 | +impl_solveh!(f32, c::ssytrf, c::ssytri, c::ssytrs); |
| 52 | +impl_solveh!(c64, c::zhetrf, c::zhetri, c::zhetrs); |
| 53 | +impl_solveh!(c32, c::chetrf, c::chetri, c::chetrs); |
0 commit comments