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
use crate::bd::BidiagonalMatrix;
use crate::matrix::*;
use lapack::dpttrs;

impl BidiagonalMatrix<f64> {
  /// # Solve equation
  /// with matrix decomposed by pttrf
  /// `Ax = b`
  /// return x
  pub fn pttrs(&self, d: &[f64], b: Matrix) -> Result<Matrix, MatrixError> {
    let e = self.e();
    let n = self.d().len() as i32;
    let mut b = b;
    let mut info = 0;

    unsafe { dpttrs(n, b.cols as i32, &d, &e, &mut b.elems, n, &mut info) }

    match info {
      0 => Ok(b),
      _ => Err(MatrixError::LapackRoutineError {
        routine: "dpttrs".to_owned(),
        info,
      }),
    }
  }
}