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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
use crate::Matrix;
use super::matrix_init;
pub trait Transpose: Matrix
where
Self::Output: Matrix
{
type Output;
/// Returns the transposed version of the given matrix
///
/// Aᵀ
///
/// # Examples
///
/// ```rust
/// let a = [
/// [1.0, 2.0, 3.0],
/// [4.0, 5.0, 6.0]
/// ];
/// let at = [
/// [1.0, 4.0],
/// [2.0, 5.0],
/// [3.0, 6.0]
/// ];
/// assert_eq!(a.transpose(), at);
/// ```
fn transpose(&self) -> Self::Output;
}
impl<F: Clone, const L: usize, const H: usize> Transpose for [[F; L]; H]
where
Self: Matrix,
[[F; H]; L]: Matrix
{
type Output = [[F; H]; L];
fn transpose(&self) -> Self::Output
{
matrix_init(|r, c| self[c][r].clone())
}
}
/*impl<F: Float, const L: usize> Transpose for [F; L]
{
type Output = [[F; 1]; L];
fn transpose(&self) -> Self::Output
{
matrix_init(|r, c| self[r])
}
}*/