use crate::layout::*;
use cauchy::*;
use std::ops::{Index, IndexMut};
#[derive(Clone, PartialEq, Eq)]
pub struct Tridiagonal<A: Scalar> {
pub l: MatrixLayout,
pub dl: Vec<A>,
pub d: Vec<A>,
pub du: Vec<A>,
}
impl<A: Scalar> Index<(i32, i32)> for Tridiagonal<A> {
type Output = A;
#[inline]
fn index(&self, (row, col): (i32, i32)) -> &A {
let (n, _) = self.l.size();
assert!(
std::cmp::max(row, col) < n,
"ndarray: index {:?} is out of bounds for array of shape {}",
[row, col],
n
);
match row - col {
0 => &self.d[row as usize],
1 => &self.dl[col as usize],
-1 => &self.du[row as usize],
_ => panic!(
"ndarray-linalg::tridiagonal: index {:?} is not tridiagonal element",
[row, col]
),
}
}
}
impl<A: Scalar> Index<[i32; 2]> for Tridiagonal<A> {
type Output = A;
#[inline]
fn index(&self, [row, col]: [i32; 2]) -> &A {
&self[(row, col)]
}
}
impl<A: Scalar> IndexMut<(i32, i32)> for Tridiagonal<A> {
#[inline]
fn index_mut(&mut self, (row, col): (i32, i32)) -> &mut A {
let (n, _) = self.l.size();
assert!(
std::cmp::max(row, col) < n,
"ndarray: index {:?} is out of bounds for array of shape {}",
[row, col],
n
);
match row - col {
0 => &mut self.d[row as usize],
1 => &mut self.dl[col as usize],
-1 => &mut self.du[row as usize],
_ => panic!(
"ndarray-linalg::tridiagonal: index {:?} is not tridiagonal element",
[row, col]
),
}
}
}
impl<A: Scalar> IndexMut<[i32; 2]> for Tridiagonal<A> {
#[inline]
fn index_mut(&mut self, [row, col]: [i32; 2]) -> &mut A {
&mut self[(row, col)]
}
}