array_matrix/matrix/transpose.rs
1use crate::Matrix;
2
3use super::matrix_init;
4
5pub trait Transpose: Matrix
6where
7 Self::Output: Matrix
8{
9 type Output;
10
11 /// Returns the transposed version of the given matrix
12 ///
13 /// Aᵀ
14 ///
15 /// # Examples
16 ///
17 /// ```rust
18 /// let a = [
19 /// [1.0, 2.0, 3.0],
20 /// [4.0, 5.0, 6.0]
21 /// ];
22 /// let at = [
23 /// [1.0, 4.0],
24 /// [2.0, 5.0],
25 /// [3.0, 6.0]
26 /// ];
27 /// assert_eq!(a.transpose(), at);
28 /// ```
29 fn transpose(&self) -> Self::Output;
30}
31
32impl<F: Clone, const L: usize, const H: usize> Transpose for [[F; L]; H]
33where
34 Self: Matrix,
35 [[F; H]; L]: Matrix
36{
37 type Output = [[F; H]; L];
38
39 fn transpose(&self) -> Self::Output
40 {
41 matrix_init(|r, c| self[c][r].clone())
42 }
43}
44
45/*impl<F: Float, const L: usize> Transpose for [F; L]
46{
47 type Output = [[F; 1]; L];
48
49 fn transpose(&self) -> Self::Output
50 {
51 matrix_init(|r, c| self[r])
52 }
53}*/