array_matrix/matrix/
cofactor.rs

1use crate::{SquareMatrix, Transpose, Adj};
2
3pub trait Cofactor: SquareMatrix
4where
5    Self::Output: SquareMatrix
6{
7    type Output;
8
9    /// Returns the cofactor matrix of the given matrix
10    /// 
11    /// adj(A)ᵀ
12    /// 
13    /// # Examples
14    /// 
15    /// ```rust
16    /// let a = [
17    ///     [1.0, 2.0],
18    ///     [3.0, 4.0]
19    /// ];
20    /// let ac = [
21    ///     [4.0, -3.0],
22    ///     [-2.0, 1.0]
23    /// ];
24    /// assert_eq!(a.cofactor(), ac);
25    /// ```
26    fn cofactor(&self) -> Self::Output;
27}
28
29impl<M> Cofactor for M
30where
31    Self: Adj,
32    <Self as Adj>::Output: Transpose,
33    <<Self as Adj>::Output as Transpose>::Output: SquareMatrix
34{
35    type Output = <<Self as Adj>::Output as Transpose>::Output;
36    fn cofactor(&self) -> Self::Output
37    {
38        self.adj().transpose()
39    }
40}