array_matrix/matrix/
herm.rs

1use num_complex::{Complex};
2use num_traits::Float;
3
4use crate::{matrix_init, Matrix};
5
6pub trait Herm: Matrix
7where
8    Self::Output: Matrix
9{
10    type Output;
11    
12    /// Returns the Hermitian complex-conjugate transposed matrix
13    /// 
14    /// Aᴴ = (A*)ᵀ
15    /// 
16    /// # Examples
17    /// 
18    /// ```rust
19    /// let a = [
20    ///     [Complex::new(1.0, 1.0), Complex::new(2.0, -1.0)],
21    ///     [Complex::new(3.0, 1.0), Complex::new(4.0, -1.0)]
22    /// ];
23    /// let ah = [
24    ///     [a[0][0].conj(), a[1][0].conj()],
25    ///     [a[0][1].conj(), a[1][1].conj()]
26    /// ];
27    /// assert_eq!(a.herm(), ah);
28    /// ```
29    fn herm(&self) -> Self::Output;
30}
31
32impl<F: Float, const L: usize, const H: usize> Herm for [[Complex<F>; L]; H]
33where
34    Self: Matrix,
35    [[Complex<F>; H]; L]: Matrix
36{
37    type Output = [[Complex<F>; H]; L];
38    fn herm(&self) -> Self::Output
39    {
40        matrix_init(|r, c| self[c][r].conj())
41    }
42}