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
use crate::{
    matrix::Matrix,
    number::{c64, Number},
    types::{Diagonal, Square},
};

/// # Diagonalized
/// `A = P * Lambda * P^{-1}`
pub struct Diagonalized<U>(
    pub Matrix<Square, U>,
    pub Matrix<Diagonal, U>,
    pub Matrix<Square, U>,
)
where
    U: Number;

macro_rules! implement {
    {$t: ty} => {
      impl Diagonalized<$t> {
            pub fn inv(&self) -> Matrix<Square, $t> {
                &self.0 * self.1.clone().inv() * &self.2
            }

            pub fn det(&self) -> $t {
                self.1.det()
            }
        }
    };
}

implement! {f64}
implement! {c64}