--- trunk/OOPSE-4/src/math/RectMatrix.hpp 2005/04/15 22:04:00 2204 +++ trunk/OOPSE-4/src/math/RectMatrix.hpp 2006/02/22 20:35:16 2596 @@ -151,7 +151,7 @@ namespace oopse { Vector getRow(unsigned int row) { Vector v; - for (unsigned int i = 0; i < Row; i++) + for (unsigned int i = 0; i < Col; i++) v[i] = this->data_[row][i]; return v; @@ -164,7 +164,7 @@ namespace oopse { */ void setRow(unsigned int row, const Vector& v) { - for (unsigned int i = 0; i < Row; i++) + for (unsigned int i = 0; i < Col; i++) this->data_[row][i] = v[i]; } @@ -176,7 +176,7 @@ namespace oopse { Vector getColumn(unsigned int col) { Vector v; - for (unsigned int j = 0; j < Col; j++) + for (unsigned int j = 0; j < Row; j++) v[j] = this->data_[j][col]; return v; @@ -189,7 +189,7 @@ namespace oopse { */ void setColumn(unsigned int col, const Vector& v){ - for (unsigned int j = 0; j < Col; j++) + for (unsigned int j = 0; j < Row; j++) this->data_[j][col] = v[j]; } @@ -389,7 +389,30 @@ namespace oopse { return result; } - + + template + void setSubMatrix(unsigned int beginRow, unsigned int beginCol, const MatrixType& m) { + assert(beginRow + m.getNRow() -1 <= getNRow()); + assert(beginCol + m.getNCol() -1 <= getNCol()); + + for (unsigned int i = 0; i < m.getNRow(); ++i) + for (unsigned int j = 0; j < m.getNCol(); ++j) + this->data_[beginRow+i][beginCol+j] = m(i, j); + } + + template + void getSubMatrix(unsigned int beginRow, unsigned int beginCol, MatrixType& m) { + assert(beginRow + m.getNRow() -1 <= getNRow()); + assert(beginCol + m.getNCol() - 1 <= getNCol()); + + for (unsigned int i = 0; i < m.getNRow(); ++i) + for (unsigned int j = 0; j < m.getNCol(); ++j) + m(i, j) = this->data_[beginRow+i][beginCol+j]; + } + + unsigned int getNRow() const {return Row;} + unsigned int getNCol() const {return Col;} + protected: Real data_[Row][Col]; };