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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
use crateMatrixDataTrait;
use crateMatrix;
/// Creates an identity matrix of the given size.
///
/// An identity matrix is a square matrix with ones on the main diagonal and zeros elsewhere.
///
/// # Type Parameters
///
/// * `T` - The type of the elements in the matrix.
/// * `SIZE` - The number of rows and columns in the matrix.
///
/// # Returns
///
/// An identity matrix of the given size.
///
/// # Example
///
/// ```
/// use numberlab::structure::matrix::{Matrix, identity};
///
/// let matrix = identity::<i32, 3>();
///
/// assert_eq!(matrix[(0, 0)], 1);
/// assert_eq!(matrix[(1, 1)], 1);
/// assert_eq!(matrix[(2, 2)], 1);
/// assert_eq!(matrix[(0, 1)], 0);
/// assert_eq!(matrix[(0, 2)], 0);
/// assert_eq!(matrix[(1, 0)], 0);
/// assert_eq!(matrix[(1, 2)], 0);
/// assert_eq!(matrix[(2, 0)], 0);
/// assert_eq!(matrix[(2, 1)], 0);
/// ```
/// Transposes the given matrix.
///
/// # Type Parameters
///
/// * `T` - The type of the elements in the matrix.
/// * `ROWS` - The number of rows in the matrix.
/// * `COLS` - The number of columns in the matrix.
///
/// # Arguments
///
/// * `matrix` - The matrix to be transposed.
///
/// # Returns
///
/// A new matrix that is the transpose of the given matrix.
///
/// # Example
///
/// ```
/// use numberlab::structure::matrix::{Matrix, transpose};
///
/// let matrix = Matrix::<i32, 2, 3>::from_array([[1, 2, 3], [4, 5, 6]]);
/// let transposed = transpose(matrix);
///
/// assert_eq!(transposed[(0, 0)], 1);
/// assert_eq!(transposed[(1, 0)], 2);
/// assert_eq!(transposed[(2, 0)], 3);
/// assert_eq!(transposed[(0, 1)], 4);
/// assert_eq!(transposed[(1, 1)], 5);
/// assert_eq!(transposed[(2, 1)], 6);
/// ```
/// Converts the given matrix to its upper triangular form and returns it.
///
/// # Type Parameters
///
/// * `T` - The type of the elements in the matrix.
/// * `SIZE` - The number of rows and columns in the matrix.
///
/// # Arguments
///
/// * `matrix` - The matrix to be converted.
///
/// # Returns
///
/// A new matrix that is the upper triangular form of the given matrix.
///
/// # Example
///
/// ```
/// use numberlab::structure::matrix::{Matrix, upper_triangular};
///
/// let matrix = Matrix::<i32, 3, 3>::from_array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]);
/// let upper = upper_triangular(matrix);
///
/// assert_eq!(upper, Matrix::<i32, 3, 3>::from_array([[1, 2, 3], [0, 5, 6], [0, 0, 9]]));
/// ```
/// Converts the given matrix to its lower triangular form and returns it.
///
/// # Type Parameters
///
/// * `T` - The type of the elements in the matrix.
/// * `SIZE` - The number of rows and columns in the matrix.
///
/// # Arguments
///
/// * `matrix` - The matrix to be converted.
///
/// # Returns
///
/// A new matrix that is the lower triangular form of the given matrix.
///
/// # Example
///
/// ```
/// use numberlab::structure::matrix::{Matrix, lower_triangular};
///
/// let matrix = Matrix::<i32, 3, 3>::from_array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]);
/// let lower = lower_triangular(matrix);
///
/// assert_eq!(lower, Matrix::<i32, 3, 3>::from_array([[1, 0, 0], [4, 5, 0], [7, 8, 9]]));
/// ```