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
54
55
56
use crate::matrix::Matrix;
use crate::number::Number;
use crate::types::*;
fn t<T, U, V>(slf: &Matrix<T, U>) -> Matrix<V, U>
where
T: Type,
U: Number,
V: Type,
{
let mut new_matrix = Matrix::<Standard, U>::zeros(slf.columns, slf.rows).transmute();
for i in 0..new_matrix.rows {
for j in 0..new_matrix.columns {
new_matrix[i][j] = slf[j][i];
}
}
new_matrix
}
macro_rules! implement {
{$t1: ty, $t2: ty} => {
impl<U> Matrix<$t1, U>
where
U: Number,
{
pub fn t(&self) -> Matrix<$t2, U> {
t(self)
}
}
};
}
implement! {Standard, Standard}
implement! {Square, Square}
implement! {UpperTriangle, LowerTriangle}
implement! {LowerTriangle, UpperTriangle}
macro_rules! implement_clone {
{$t1: ty} => {
impl<U> Matrix<$t1, U>
where
U: Number,
{
pub fn t(&self) -> Matrix<$t1, U> {
self.clone()
}
}
};
}
implement_clone! {Diagonal}
implement_clone! {PositiveDefinite}
implement_clone! {PositiveSemiDefinite}