| 38 |
|
#include "Vector.hpp" |
| 39 |
|
|
| 40 |
|
namespace oopse { |
| 41 |
– |
const double epsilon = 0.000001; |
| 41 |
|
|
| 43 |
– |
template<typename T> |
| 44 |
– |
inline bool equal(T e1, T e2) { |
| 45 |
– |
return e1 == e2; |
| 46 |
– |
} |
| 47 |
– |
|
| 48 |
– |
template<> |
| 49 |
– |
inline bool equal(float e1, float e2) { |
| 50 |
– |
return fabs(e1 - e2) < epsilon; |
| 51 |
– |
} |
| 52 |
– |
|
| 53 |
– |
template<> |
| 54 |
– |
inline bool equal(double e1, double e2) { |
| 55 |
– |
return fabs(e1 - e2) < epsilon; |
| 56 |
– |
} |
| 57 |
– |
|
| 42 |
|
/** |
| 43 |
|
* @class RectMatrix RectMatrix.hpp "math/RectMatrix.hpp" |
| 44 |
|
* @brief rectangular matrix class |
| 153 |
|
} |
| 154 |
|
|
| 155 |
|
/** |
| 156 |
+ |
* swap two rows of this matrix |
| 157 |
+ |
* @param i the first row |
| 158 |
+ |
* @param j the second row |
| 159 |
+ |
*/ |
| 160 |
+ |
void swapRow(unsigned int i, unsigned int j){ |
| 161 |
+ |
assert(i < Row && j < Row); |
| 162 |
+ |
|
| 163 |
+ |
for (unsigned int k = 0; k < Col; k++) |
| 164 |
+ |
std::swap(data_[i][k], data_[j][k]); |
| 165 |
+ |
} |
| 166 |
+ |
|
| 167 |
+ |
/** |
| 168 |
+ |
* swap two colums of this matrix |
| 169 |
+ |
* @param i the first colum |
| 170 |
+ |
* @param j the second colum |
| 171 |
+ |
*/ |
| 172 |
+ |
void swapColum(unsigned int i, unsigned int j){ |
| 173 |
+ |
assert(i < Col && j < Col); |
| 174 |
+ |
|
| 175 |
+ |
for (unsigned int k = 0; k < Row; k++) |
| 176 |
+ |
std::swap(data_[k][i], data_[k][j]); |
| 177 |
+ |
} |
| 178 |
+ |
|
| 179 |
+ |
/** |
| 180 |
|
* Tests if this matrix is identical to matrix m |
| 181 |
|
* @return true if this matrix is equal to the matrix m, return false otherwise |
| 182 |
|
* @m matrix to be compared |
| 436 |
|
for (unsigned int i = 0; i < Row; i++) |
| 437 |
|
for (unsigned int j = 0; j < Col; j++) |
| 438 |
|
for (unsigned int k = 0; k < SameDim; k++) |
| 439 |
< |
result(i, j) = m1(i, k) * m2(k, j); |
| 439 |
> |
result(i, j) += m1(i, k) * m2(k, j); |
| 440 |
|
|
| 441 |
|
return result; |
| 442 |
|
} |
| 471 |
|
result.div(s, m); |
| 472 |
|
|
| 473 |
|
return result; |
| 474 |
+ |
} |
| 475 |
+ |
|
| 476 |
+ |
/** |
| 477 |
+ |
* Write to an output stream |
| 478 |
+ |
*/ |
| 479 |
+ |
template<typename Real, unsigned int Row, unsigned int Col> |
| 480 |
+ |
std::ostream &operator<< ( std::ostream& o, const RectMatrix<Real, Row, Col>& m) { |
| 481 |
+ |
for (unsigned int i = 0; i < Row ; i++) { |
| 482 |
+ |
o << "(" |
| 483 |
+ |
for (unsigned int j = 0; j < Col ; j++) { |
| 484 |
+ |
o << m(i, j) << "\t" |
| 485 |
+ |
} |
| 486 |
+ |
o << ")" << std::endl; |
| 487 |
+ |
} |
| 488 |
+ |
return o; |
| 489 |
|
} |
| 490 |
|
} |
| 491 |
|
#endif //MATH_RECTMATRIX_HPP |