--- trunk/OOPSE-3.0/src/math/RectMatrix.hpp 2004/10/13 23:53:40 1567 +++ trunk/OOPSE-3.0/src/math/RectMatrix.hpp 2004/10/19 21:28:55 1603 @@ -38,23 +38,7 @@ namespace oopse { #include "Vector.hpp" namespace oopse { - const double epsilon = 0.000001; - template - inline bool equal(T e1, T e2) { - return e1 == e2; - } - - template<> - inline bool equal(float e1, float e2) { - return fabs(e1 - e2) < epsilon; - } - - template<> - inline bool equal(double e1, double e2) { - return fabs(e1 - e2) < epsilon; - } - /** * @class RectMatrix RectMatrix.hpp "math/RectMatrix.hpp" * @brief rectangular matrix class @@ -169,6 +153,30 @@ namespace oopse { } /** + * swap two rows of this matrix + * @param i the first row + * @param j the second row + */ + void swapRow(unsigned int i, unsigned int j){ + assert(i < Row && j < Row); + + for (unsigned int k = 0; k < Col; k++) + std::swap(data_[i][k], data_[j][k]); + } + + /** + * swap two colums of this matrix + * @param i the first colum + * @param j the second colum + */ + void swapColum(unsigned int i, unsigned int j){ + assert(i < Col && j < Col); + + for (unsigned int k = 0; k < Row; k++) + std::swap(data_[k][i], data_[k][j]); + } + + /** * Tests if this matrix is identical to matrix m * @return true if this matrix is equal to the matrix m, return false otherwise * @m matrix to be compared @@ -428,7 +436,7 @@ namespace oopse { for (unsigned int i = 0; i < Row; i++) for (unsigned int j = 0; j < Col; j++) for (unsigned int k = 0; k < SameDim; k++) - result(i, j) = m1(i, k) * m2(k, j); + result(i, j) += m1(i, k) * m2(k, j); return result; } @@ -463,6 +471,21 @@ namespace oopse { result.div(s, m); return result; + } + + /** + * Write to an output stream + */ + template + std::ostream &operator<< ( std::ostream& o, const RectMatrix& m) { + for (unsigned int i = 0; i < Row ; i++) { + o << "("; + for (unsigned int j = 0; j < Col ; j++) { + o << m(i, j) << "\t"; + } + o << ")" << std::endl; + } + return o; } } #endif //MATH_RECTMATRIX_HPP