opensrdk_linear_algebra/matrix/ge/operations/
t.rs1use crate::matrix::ge::Matrix;
2use crate::number::Number;
3use rayon::prelude::*;
4
5impl<T> Matrix<T>
6where
7 T: Number,
8{
9 pub fn t(&self) -> Matrix<T> {
11 let elems = (0..self.rows)
12 .into_par_iter()
13 .flat_map(|i| (0..self.cols).into_par_iter().map(move |j| (i, j)))
14 .map(|(i, j)| self[(i, j)])
15 .collect();
16
17 Matrix::from(self.cols, elems).unwrap()
18 }
19}
20
21#[cfg(test)]
22mod tests {
23 use crate::*;
24 #[test]
25 fn it_works() {
26 let a = mat![
27 1.0, 3.0;
28 2.0, 4.0;
29 3.0, 6.0
30 ];
31 let at = a.t();
32
33 assert_eq!(at[(1, 0)], 3.0);
34 assert_eq!(at[(1, 2)], 6.0);
35 }
36}