@@ -80,7 +80,26 @@ namespace klibrary::linear_algebra {
80
80
constexpr MatrixBaseShape shape () const noexcept {
81
81
return MatrixBaseShape (Rows, Cols);
82
82
}
83
-
83
+ void swap_rows (const SizeT& r1, const SizeT& r2) {
84
+ assert (r1 < Rows && r2 < Rows);
85
+ std::array<ElemT, Cols> temp;
86
+ auto r1_begin = std::next (this ->matrix_ .begin (), r1 * Cols);
87
+ auto r2_begin = std::next (this ->matrix_ .begin (), r2 * Cols);
88
+ auto r1_end = (r1 == Rows - 1 ) ? this ->matrix_ .end () : std::next (this ->matrix_ .begin (), (r1 + 1 ) * Cols);
89
+ auto r2_end = (r2 == Rows - 1 ) ? this ->matrix_ .end () : std::next (this ->matrix_ .begin (), (r2 + 1 ) * Cols);
90
+
91
+ std::move (r1_begin, r1_end, temp.begin ());
92
+ std::move (r2_begin, r2_end, r1_begin);
93
+ std::move (temp.begin (), temp.end (), r2_begin);
94
+ return ;
95
+ }
96
+ void swap_cols (const SizeT& c1, const SizeT& c2) {
97
+ assert (c1 < Cols && c2 < Cols);
98
+ for (SizeT r = 0 ; r < Rows; ++r) {
99
+ std::swap (this ->matrix_ .at (r * Cols + c1), this ->matrix_ .at (r * Cols + c2));
100
+ }
101
+ return ;
102
+ }
84
103
template <class ElemT_R , SizeT Rows_R, SizeT Cols_R>
85
104
auto & operator +=(const StaticMatrixBase<ElemT_R, Rows_R, Cols_R>& matrix) {
86
105
static_assert (Rows == Rows_R);
@@ -153,27 +172,6 @@ namespace klibrary::linear_algebra {
153
172
}
154
173
return (*this );
155
174
}
156
-
157
- void swap_rows (const SizeT& r1, const SizeT& r2) {
158
- assert (r1 < Rows && r2 < Rows);
159
- std::array<ElemT, Cols> temp;
160
- auto r1_begin = std::next (this ->matrix_ .begin (), r1 * Cols);
161
- auto r2_begin = std::next (this ->matrix_ .begin (), r2 * Cols);
162
- auto r1_end = (r1 == Rows - 1 ) ? this ->matrix_ .end () : std::next (this ->matrix_ .begin (), (r1 + 1 ) * Cols);
163
- auto r2_end = (r2 == Rows - 1 ) ? this ->matrix_ .end () : std::next (this ->matrix_ .begin (), (r2 + 1 ) * Cols);
164
-
165
- std::move (r1_begin, r1_end, temp.begin ());
166
- std::move (r2_begin, r2_end, r1_begin);
167
- std::move (temp.begin (), temp.end (), r2_begin);
168
- return ;
169
- }
170
- void swap_cols (const SizeT& c1, const SizeT& c2) {
171
- assert (c1 < Cols && c2 < Cols);
172
- for (SizeT r = 0 ; r < Rows; ++r) {
173
- std::swap (this ->matrix_ .at (r * Cols + c1), this ->matrix_ .at (r * Cols + c2));
174
- }
175
- return ;
176
- }
177
175
};
178
176
template <class ElemT , SizeT Rows, SizeT Cols>
179
177
auto operator +(const StaticMatrixBase<ElemT, Rows, Cols>& matrix) {
0 commit comments