| 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 | 
| 46 | 
  | 
    template<typename Real, unsigned int Row, unsigned int Col>  | 
| 47 | 
  | 
    class RectMatrix { | 
| 48 | 
  | 
        public: | 
| 49 | 
+ | 
            typedef Real ElemType; | 
| 50 | 
+ | 
            typedef Real* ElemPoinerType; | 
| 51 | 
+ | 
             | 
| 52 | 
+ | 
            /** default constructor */ | 
| 53 | 
+ | 
            RectMatrix() { | 
| 54 | 
+ | 
                for (unsigned int i = 0; i < Row; i++) | 
| 55 | 
+ | 
                    for (unsigned int j = 0; j < Col; j++) | 
| 56 | 
+ | 
                        data_[i][j] = 0.0; | 
| 57 | 
+ | 
             } | 
| 58 | 
  | 
 | 
| 59 | 
< | 
        /** default constructor */ | 
| 60 | 
< | 
        RectMatrix() { | 
| 61 | 
< | 
            for (unsigned int i = 0; i < Row; i++) | 
| 62 | 
< | 
                for (unsigned int j = 0; j < Col; j++) | 
| 63 | 
< | 
                    data_[i][j] = 0.0; | 
| 64 | 
< | 
         } | 
| 59 | 
> | 
            /** Constructs and initializes every element of this matrix to a scalar */  | 
| 60 | 
> | 
            RectMatrix(Real s) { | 
| 61 | 
> | 
                for (unsigned int i = 0; i < Row; i++) | 
| 62 | 
> | 
                    for (unsigned int j = 0; j < Col; j++) | 
| 63 | 
> | 
                        data_[i][j] = s; | 
| 64 | 
> | 
            } | 
| 65 | 
  | 
 | 
| 66 | 
< | 
        /** Constructs and initializes every element of this matrix to a scalar */  | 
| 67 | 
< | 
        RectMatrix(Real s) { | 
| 68 | 
< | 
            for (unsigned int i = 0; i < Row; i++) | 
| 69 | 
< | 
                for (unsigned int j = 0; j < Col; j++) | 
| 70 | 
< | 
                    data_[i][j] = s; | 
| 71 | 
< | 
        } | 
| 66 | 
> | 
            /** copy constructor */ | 
| 67 | 
> | 
            RectMatrix(const RectMatrix<Real, Row, Col>& m) { | 
| 68 | 
> | 
                *this = m; | 
| 69 | 
> | 
            } | 
| 70 | 
> | 
             | 
| 71 | 
> | 
            /** destructor*/ | 
| 72 | 
> | 
            ~RectMatrix() {} | 
| 73 | 
  | 
 | 
| 74 | 
< | 
        /** copy constructor */ | 
| 75 | 
< | 
        RectMatrix(const RectMatrix<Real, Row, Col>& m) { | 
| 76 | 
< | 
            *this = m; | 
| 77 | 
< | 
        } | 
| 78 | 
< | 
         | 
| 79 | 
< | 
        /** destructor*/ | 
| 80 | 
< | 
        ~RectMatrix() {} | 
| 81 | 
< | 
 | 
| 88 | 
< | 
        /** copy assignment operator */ | 
| 89 | 
< | 
        RectMatrix<Real, Row, Col>& operator =(const RectMatrix<Real, Row, Col>& m) { | 
| 90 | 
< | 
            if (this == &m) | 
| 74 | 
> | 
            /** copy assignment operator */ | 
| 75 | 
> | 
            RectMatrix<Real, Row, Col>& operator =(const RectMatrix<Real, Row, Col>& m) { | 
| 76 | 
> | 
                if (this == &m) | 
| 77 | 
> | 
                    return *this; | 
| 78 | 
> | 
                 | 
| 79 | 
> | 
                for (unsigned int i = 0; i < Row; i++) | 
| 80 | 
> | 
                    for (unsigned int j = 0; j < Col; j++) | 
| 81 | 
> | 
                        data_[i][j] = m.data_[i][j]; | 
| 82 | 
  | 
                return *this; | 
| 83 | 
+ | 
            } | 
| 84 | 
  | 
             | 
| 85 | 
< | 
            for (unsigned int i = 0; i < Row; i++) | 
| 86 | 
< | 
                for (unsigned int j = 0; j < Col; j++) | 
| 87 | 
< | 
                    data_[i][j] = m.data_[i][j]; | 
| 88 | 
< | 
            return *this; | 
| 89 | 
< | 
        } | 
| 90 | 
< | 
         | 
| 91 | 
< | 
        /** | 
| 92 | 
< | 
         * Return the reference of a single element of this matrix. | 
| 93 | 
< | 
         * @return the reference of a single element of this matrix  | 
| 94 | 
< | 
         * @param i row index | 
| 103 | 
< | 
         * @param j colum index | 
| 104 | 
< | 
         */ | 
| 105 | 
< | 
        double& operator()(unsigned int i, unsigned int j) { | 
| 106 | 
< | 
            //assert( i < Row && j < Col); | 
| 107 | 
< | 
            return data_[i][j]; | 
| 108 | 
< | 
        } | 
| 85 | 
> | 
            /** | 
| 86 | 
> | 
             * Return the reference of a single element of this matrix. | 
| 87 | 
> | 
             * @return the reference of a single element of this matrix  | 
| 88 | 
> | 
             * @param i row index | 
| 89 | 
> | 
             * @param j colum index | 
| 90 | 
> | 
             */ | 
| 91 | 
> | 
            Real& operator()(unsigned int i, unsigned int j) { | 
| 92 | 
> | 
                //assert( i < Row && j < Col); | 
| 93 | 
> | 
                return data_[i][j]; | 
| 94 | 
> | 
            } | 
| 95 | 
  | 
 | 
| 96 | 
< | 
        /** | 
| 97 | 
< | 
         * Return the value of a single element of this matrix. | 
| 98 | 
< | 
         * @return the value of a single element of this matrix  | 
| 99 | 
< | 
         * @param i row index | 
| 100 | 
< | 
         * @param j colum index | 
| 101 | 
< | 
         */         | 
| 102 | 
< | 
        double operator()(unsigned int i, unsigned int j) const  { | 
| 103 | 
< | 
             | 
| 104 | 
< | 
            return data_[i][j];   | 
| 105 | 
< | 
        } | 
| 96 | 
> | 
            /** | 
| 97 | 
> | 
             * Return the value of a single element of this matrix. | 
| 98 | 
> | 
             * @return the value of a single element of this matrix  | 
| 99 | 
> | 
             * @param i row index | 
| 100 | 
> | 
             * @param j colum index | 
| 101 | 
> | 
             */         | 
| 102 | 
> | 
            Real operator()(unsigned int i, unsigned int j) const  { | 
| 103 | 
> | 
                 | 
| 104 | 
> | 
                return data_[i][j];   | 
| 105 | 
> | 
            } | 
| 106 | 
  | 
 | 
| 107 | 
< | 
        /** | 
| 108 | 
< | 
         * Returns a row of  this matrix as a vector. | 
| 109 | 
< | 
         * @return a row of  this matrix as a vector  | 
| 110 | 
< | 
         * @param row the row index | 
| 125 | 
< | 
         */                 | 
| 126 | 
< | 
        Vector<Real, Row> getRow(unsigned int row) { | 
| 127 | 
< | 
            Vector<Real, Row> v; | 
| 107 | 
> | 
            /** Returns the pointer of internal array */ | 
| 108 | 
> | 
            Real* getArrayPointer() { | 
| 109 | 
> | 
                return &data_[0][0]; | 
| 110 | 
> | 
            } | 
| 111 | 
  | 
 | 
| 112 | 
< | 
            for (unsigned int i = 0; i < Row; i++) | 
| 113 | 
< | 
                v[i] = data_[row][i]; | 
| 112 | 
> | 
            /** | 
| 113 | 
> | 
             * Returns a row of  this matrix as a vector. | 
| 114 | 
> | 
             * @return a row of  this matrix as a vector  | 
| 115 | 
> | 
             * @param row the row index | 
| 116 | 
> | 
             */                 | 
| 117 | 
> | 
            Vector<Real, Row> getRow(unsigned int row) { | 
| 118 | 
> | 
                Vector<Real, Row> v; | 
| 119 | 
  | 
 | 
| 120 | 
< | 
            return v; | 
| 121 | 
< | 
        } | 
| 120 | 
> | 
                for (unsigned int i = 0; i < Row; i++) | 
| 121 | 
> | 
                    v[i] = data_[row][i]; | 
| 122 | 
  | 
 | 
| 123 | 
< | 
        /** | 
| 124 | 
< | 
         * Sets a row of  this matrix | 
| 137 | 
< | 
         * @param row the row index | 
| 138 | 
< | 
         * @param v the vector to be set | 
| 139 | 
< | 
         */                 | 
| 140 | 
< | 
         void setRow(unsigned int row, const Vector<Real, Row>& v) { | 
| 123 | 
> | 
                return v; | 
| 124 | 
> | 
            } | 
| 125 | 
  | 
 | 
| 126 | 
< | 
            for (unsigned int i = 0; i < Row; i++) | 
| 127 | 
< | 
                data_[row][i] = v[i]; | 
| 128 | 
< | 
         } | 
| 126 | 
> | 
            /** | 
| 127 | 
> | 
             * Sets a row of  this matrix | 
| 128 | 
> | 
             * @param row the row index | 
| 129 | 
> | 
             * @param v the vector to be set | 
| 130 | 
> | 
             */                 | 
| 131 | 
> | 
             void setRow(unsigned int row, const Vector<Real, Row>& v) { | 
| 132 | 
  | 
 | 
| 133 | 
< | 
        /** | 
| 134 | 
< | 
         * Returns a column of  this matrix as a vector. | 
| 135 | 
< | 
         * @return a column of  this matrix as a vector  | 
| 149 | 
< | 
         * @param col the column index | 
| 150 | 
< | 
         */                 | 
| 151 | 
< | 
        Vector<Real, Col> getColum(unsigned int col) { | 
| 152 | 
< | 
            Vector<Real, Col> v; | 
| 133 | 
> | 
                for (unsigned int i = 0; i < Row; i++) | 
| 134 | 
> | 
                    data_[row][i] = v[i]; | 
| 135 | 
> | 
             } | 
| 136 | 
  | 
 | 
| 137 | 
< | 
            for (unsigned int j = 0; j < Col; j++) | 
| 138 | 
< | 
                v[j] = data_[j][col]; | 
| 137 | 
> | 
            /** | 
| 138 | 
> | 
             * Returns a column of  this matrix as a vector. | 
| 139 | 
> | 
             * @return a column of  this matrix as a vector  | 
| 140 | 
> | 
             * @param col the column index | 
| 141 | 
> | 
             */                 | 
| 142 | 
> | 
            Vector<Real, Col> getColum(unsigned int col) { | 
| 143 | 
> | 
                Vector<Real, Col> v; | 
| 144 | 
  | 
 | 
| 145 | 
< | 
            return v; | 
| 146 | 
< | 
        } | 
| 145 | 
> | 
                for (unsigned int j = 0; j < Col; j++) | 
| 146 | 
> | 
                    v[j] = data_[j][col]; | 
| 147 | 
  | 
 | 
| 148 | 
< | 
        /** | 
| 149 | 
< | 
         * Sets a column of  this matrix | 
| 162 | 
< | 
         * @param col the column index | 
| 163 | 
< | 
         * @param v the vector to be set | 
| 164 | 
< | 
         */                 | 
| 165 | 
< | 
         void setColum(unsigned int col, const Vector<Real, Col>& v){ | 
| 148 | 
> | 
                return v; | 
| 149 | 
> | 
            } | 
| 150 | 
  | 
 | 
| 151 | 
< | 
            for (unsigned int j = 0; j < Col; j++) | 
| 152 | 
< | 
                data_[j][col] = v[j]; | 
| 153 | 
< | 
         }          | 
| 151 | 
> | 
            /** | 
| 152 | 
> | 
             * Sets a column of  this matrix | 
| 153 | 
> | 
             * @param col the column index | 
| 154 | 
> | 
             * @param v the vector to be set | 
| 155 | 
> | 
             */                 | 
| 156 | 
> | 
             void setColum(unsigned int col, const Vector<Real, Col>& v){ | 
| 157 | 
  | 
 | 
| 171 | 
– | 
        /** | 
| 172 | 
– | 
         * Tests if this matrix is identical to matrix m | 
| 173 | 
– | 
         * @return true if this matrix is equal to the matrix m, return false otherwise | 
| 174 | 
– | 
         * @m matrix to be compared | 
| 175 | 
– | 
         * | 
| 176 | 
– | 
         * @todo replace operator == by template function equal | 
| 177 | 
– | 
         */ | 
| 178 | 
– | 
        bool operator ==(const RectMatrix<Real, Row, Col>& m) { | 
| 179 | 
– | 
            for (unsigned int i = 0; i < Row; i++) | 
| 158 | 
  | 
                for (unsigned int j = 0; j < Col; j++) | 
| 159 | 
< | 
                    if (!equal(data_[i][j], m.data_[i][j])) | 
| 160 | 
< | 
                        return false; | 
| 159 | 
> | 
                    data_[j][col] = v[j]; | 
| 160 | 
> | 
             }          | 
| 161 | 
  | 
 | 
| 162 | 
< | 
            return true; | 
| 163 | 
< | 
        } | 
| 162 | 
> | 
            /** | 
| 163 | 
> | 
             * swap two rows of this matrix | 
| 164 | 
> | 
             * @param i the first row | 
| 165 | 
> | 
             * @param j the second row | 
| 166 | 
> | 
             */ | 
| 167 | 
> | 
            void swapRow(unsigned int i, unsigned int j){ | 
| 168 | 
> | 
                    assert(i < Row && j < Row); | 
| 169 | 
  | 
 | 
| 170 | 
< | 
        /** | 
| 171 | 
< | 
         * Tests if this matrix is not equal to matrix m | 
| 172 | 
< | 
         * @return true if this matrix is not equal to the matrix m, return false otherwise | 
| 190 | 
< | 
         * @m matrix to be compared | 
| 191 | 
< | 
         */ | 
| 192 | 
< | 
        bool operator !=(const RectMatrix<Real, Row, Col>& m) { | 
| 193 | 
< | 
            return !(*this == m); | 
| 194 | 
< | 
        } | 
| 170 | 
> | 
                    for (unsigned int k = 0; k < Col; k++) | 
| 171 | 
> | 
                        std::swap(data_[i][k], data_[j][k]); | 
| 172 | 
> | 
            } | 
| 173 | 
  | 
 | 
| 174 | 
< | 
        /** Negates the value of this matrix in place. */            | 
| 175 | 
< | 
        inline void negate() { | 
| 176 | 
< | 
            for (unsigned int i = 0; i < Row; i++) | 
| 177 | 
< | 
                for (unsigned int j = 0; j < Col; j++) | 
| 178 | 
< | 
                    data_[i][j] = -data_[i][j]; | 
| 179 | 
< | 
        } | 
| 180 | 
< | 
         | 
| 181 | 
< | 
        /** | 
| 182 | 
< | 
        * Sets the value of this matrix to the negation of matrix m. | 
| 183 | 
< | 
        * @param m the source matrix | 
| 184 | 
< | 
        */ | 
| 207 | 
< | 
        inline void negate(const RectMatrix<Real, Row, Col>& m) { | 
| 208 | 
< | 
            for (unsigned int i = 0; i < Row; i++) | 
| 209 | 
< | 
                for (unsigned int j = 0; j < Col; j++) | 
| 210 | 
< | 
                    data_[i][j] = -m.data_[i][j];         | 
| 211 | 
< | 
        } | 
| 212 | 
< | 
         | 
| 213 | 
< | 
        /** | 
| 214 | 
< | 
        * Sets the value of this matrix to the sum of itself and m (*this += m). | 
| 215 | 
< | 
        * @param m the other matrix | 
| 216 | 
< | 
        */ | 
| 217 | 
< | 
        inline void add( const RectMatrix<Real, Row, Col>& m ) { | 
| 218 | 
< | 
            for (unsigned int i = 0; i < Row; i++) | 
| 219 | 
< | 
                for (unsigned int j = 0; j < Col; j++)         | 
| 220 | 
< | 
                data_[i][j] += m.data_[i][j]; | 
| 221 | 
< | 
        } | 
| 222 | 
< | 
         | 
| 223 | 
< | 
        /** | 
| 224 | 
< | 
        * Sets the value of this matrix to the sum of m1 and m2 (*this = m1 + m2). | 
| 225 | 
< | 
        * @param m1 the first matrix | 
| 226 | 
< | 
        * @param m2 the second matrix | 
| 227 | 
< | 
        */ | 
| 228 | 
< | 
        inline void add( const RectMatrix<Real, Row, Col>& m1, const RectMatrix<Real, Row, Col>& m2 ) { | 
| 229 | 
< | 
            for (unsigned int i = 0; i < Row; i++) | 
| 230 | 
< | 
                for (unsigned int j = 0; j < Col; j++)         | 
| 231 | 
< | 
                data_[i][j] = m1.data_[i][j] + m2.data_[i][j]; | 
| 232 | 
< | 
        } | 
| 233 | 
< | 
         | 
| 234 | 
< | 
        /** | 
| 235 | 
< | 
        * Sets the value of this matrix to the difference  of itself and m (*this -= m). | 
| 236 | 
< | 
        * @param m the other matrix | 
| 237 | 
< | 
        */ | 
| 238 | 
< | 
        inline void sub( const RectMatrix<Real, Row, Col>& m ) { | 
| 239 | 
< | 
            for (unsigned int i = 0; i < Row; i++) | 
| 240 | 
< | 
                for (unsigned int j = 0; j < Col; j++)         | 
| 241 | 
< | 
                    data_[i][j] -= m.data_[i][j]; | 
| 242 | 
< | 
        } | 
| 243 | 
< | 
         | 
| 244 | 
< | 
        /** | 
| 245 | 
< | 
        * Sets the value of this matrix to the difference of matrix m1 and m2 (*this = m1 - m2). | 
| 246 | 
< | 
        * @param m1 the first matrix | 
| 247 | 
< | 
        * @param m2 the second matrix | 
| 248 | 
< | 
        */ | 
| 249 | 
< | 
        inline void sub( const RectMatrix<Real, Row, Col>& m1, const RectMatrix<Real, Row, Col>& m2){ | 
| 250 | 
< | 
            for (unsigned int i = 0; i < Row; i++) | 
| 251 | 
< | 
                for (unsigned int j = 0; j < Col; j++)         | 
| 252 | 
< | 
                    data_[i][j] = m1.data_[i][j] - m2.data_[i][j]; | 
| 253 | 
< | 
        } | 
| 174 | 
> | 
           /** | 
| 175 | 
> | 
             * swap two colums of this matrix | 
| 176 | 
> | 
             * @param i the first colum | 
| 177 | 
> | 
             * @param j the second colum | 
| 178 | 
> | 
             */ | 
| 179 | 
> | 
            void swapColum(unsigned int i, unsigned int j){ | 
| 180 | 
> | 
                    assert(i < Col && j < Col); | 
| 181 | 
> | 
                     | 
| 182 | 
> | 
                    for (unsigned int k = 0; k < Row; k++) | 
| 183 | 
> | 
                        std::swap(data_[k][i], data_[k][j]); | 
| 184 | 
> | 
            } | 
| 185 | 
  | 
 | 
| 186 | 
< | 
        /** | 
| 187 | 
< | 
        * Sets the value of this matrix to the scalar multiplication of itself (*this *= s). | 
| 188 | 
< | 
        * @param s the scalar value | 
| 189 | 
< | 
        */ | 
| 190 | 
< | 
        inline void mul( double s ) { | 
| 191 | 
< | 
            for (unsigned int i = 0; i < Row; i++) | 
| 192 | 
< | 
                for (unsigned int j = 0; j < Col; j++)   | 
| 193 | 
< | 
                    data_[i][j] *= s; | 
| 194 | 
< | 
        } | 
| 186 | 
> | 
            /** | 
| 187 | 
> | 
             * Tests if this matrix is identical to matrix m | 
| 188 | 
> | 
             * @return true if this matrix is equal to the matrix m, return false otherwise | 
| 189 | 
> | 
             * @m matrix to be compared | 
| 190 | 
> | 
             * | 
| 191 | 
> | 
             * @todo replace operator == by template function equal | 
| 192 | 
> | 
             */ | 
| 193 | 
> | 
            bool operator ==(const RectMatrix<Real, Row, Col>& m) { | 
| 194 | 
> | 
                for (unsigned int i = 0; i < Row; i++) | 
| 195 | 
> | 
                    for (unsigned int j = 0; j < Col; j++) | 
| 196 | 
> | 
                        if (!equal(data_[i][j], m.data_[i][j])) | 
| 197 | 
> | 
                            return false; | 
| 198 | 
  | 
 | 
| 199 | 
< | 
        /** | 
| 200 | 
< | 
        * Sets the value of this matrix to the scalar multiplication of matrix m  (*this = s * m). | 
| 267 | 
< | 
        * @param s the scalar value | 
| 268 | 
< | 
        * @param m the matrix | 
| 269 | 
< | 
        */ | 
| 270 | 
< | 
        inline void mul( double s, const RectMatrix<Real, Row, Col>& m ) { | 
| 271 | 
< | 
            for (unsigned int i = 0; i < Row; i++) | 
| 272 | 
< | 
                for (unsigned int j = 0; j < Col; j++)   | 
| 273 | 
< | 
                    data_[i][j] = s * m.data_[i][j]; | 
| 274 | 
< | 
        } | 
| 199 | 
> | 
                return true; | 
| 200 | 
> | 
            } | 
| 201 | 
  | 
 | 
| 202 | 
< | 
        /** | 
| 203 | 
< | 
        * Sets the value of this matrix to the scalar division of itself  (*this /= s ). | 
| 204 | 
< | 
        * @param s the scalar value | 
| 205 | 
< | 
        */              | 
| 206 | 
< | 
        inline void div( double s) { | 
| 207 | 
< | 
            for (unsigned int i = 0; i < Row; i++) | 
| 208 | 
< | 
                for (unsigned int j = 0; j < Col; j++)   | 
| 209 | 
< | 
                    data_[i][j] /= s; | 
| 284 | 
< | 
        } | 
| 202 | 
> | 
            /** | 
| 203 | 
> | 
             * Tests if this matrix is not equal to matrix m | 
| 204 | 
> | 
             * @return true if this matrix is not equal to the matrix m, return false otherwise | 
| 205 | 
> | 
             * @m matrix to be compared | 
| 206 | 
> | 
             */ | 
| 207 | 
> | 
            bool operator !=(const RectMatrix<Real, Row, Col>& m) { | 
| 208 | 
> | 
                return !(*this == m); | 
| 209 | 
> | 
            } | 
| 210 | 
  | 
 | 
| 211 | 
< | 
        /** | 
| 212 | 
< | 
        * Sets the value of this matrix to the scalar division of matrix m  (*this = m /s). | 
| 213 | 
< | 
        * @param s the scalar value | 
| 214 | 
< | 
        * @param m the matrix | 
| 215 | 
< | 
        */ | 
| 216 | 
< | 
        inline void div( double s, const RectMatrix<Real, Row, Col>& m ) { | 
| 292 | 
< | 
            for (unsigned int i = 0; i < Row; i++) | 
| 293 | 
< | 
                for (unsigned int j = 0; j < Col; j++)   | 
| 294 | 
< | 
                    data_[i][j] = m.data_[i][j] / s; | 
| 295 | 
< | 
        } | 
| 296 | 
< | 
 | 
| 297 | 
< | 
        /** | 
| 298 | 
< | 
         *  Multiples a scalar into every element of this matrix. | 
| 299 | 
< | 
         * @param s the scalar value | 
| 300 | 
< | 
         */ | 
| 301 | 
< | 
        RectMatrix<Real, Row, Col>& operator *=(const double s) { | 
| 302 | 
< | 
            this->mul(s); | 
| 303 | 
< | 
            return *this; | 
| 304 | 
< | 
        } | 
| 305 | 
< | 
 | 
| 306 | 
< | 
        /** | 
| 307 | 
< | 
         *  Divides every element of this matrix by a scalar. | 
| 308 | 
< | 
         * @param s the scalar value | 
| 309 | 
< | 
         */ | 
| 310 | 
< | 
        RectMatrix<Real, Row, Col>& operator /=(const double s) { | 
| 311 | 
< | 
            this->div(s); | 
| 312 | 
< | 
            return *this; | 
| 313 | 
< | 
        } | 
| 314 | 
< | 
 | 
| 315 | 
< | 
        /** | 
| 316 | 
< | 
         * Sets the value of this matrix to the sum of the other matrix and itself (*this += m). | 
| 317 | 
< | 
         * @param m the other matrix | 
| 318 | 
< | 
         */ | 
| 319 | 
< | 
        RectMatrix<Real, Row, Col>& operator += (const RectMatrix<Real, Row, Col>& m) { | 
| 320 | 
< | 
            add(m); | 
| 321 | 
< | 
            return *this; | 
| 322 | 
< | 
         } | 
| 323 | 
< | 
 | 
| 324 | 
< | 
        /** | 
| 325 | 
< | 
         * Sets the value of this matrix to the differerence of itself and the other matrix (*this -= m)  | 
| 326 | 
< | 
         * @param m the other matrix | 
| 327 | 
< | 
         */ | 
| 328 | 
< | 
        RectMatrix<Real, Row, Col>& operator -= (const RectMatrix<Real, Row, Col>& m){ | 
| 329 | 
< | 
            sub(m); | 
| 330 | 
< | 
            return *this; | 
| 331 | 
< | 
        } | 
| 332 | 
< | 
 | 
| 333 | 
< | 
        /** Return the transpose of this matrix */ | 
| 334 | 
< | 
        RectMatrix<Real,  Col, Row> transpose(){ | 
| 335 | 
< | 
            RectMatrix<Real,  Col, Row> result; | 
| 211 | 
> | 
            /** Negates the value of this matrix in place. */            | 
| 212 | 
> | 
            inline void negate() { | 
| 213 | 
> | 
                for (unsigned int i = 0; i < Row; i++) | 
| 214 | 
> | 
                    for (unsigned int j = 0; j < Col; j++) | 
| 215 | 
> | 
                        data_[i][j] = -data_[i][j]; | 
| 216 | 
> | 
            } | 
| 217 | 
  | 
             | 
| 218 | 
< | 
            for (unsigned int i = 0; i < Row; i++) | 
| 219 | 
< | 
                for (unsigned int j = 0; j < Col; j++)               | 
| 220 | 
< | 
                    result(j, i) = data_[i][j]; | 
| 218 | 
> | 
            /** | 
| 219 | 
> | 
            * Sets the value of this matrix to the negation of matrix m. | 
| 220 | 
> | 
            * @param m the source matrix | 
| 221 | 
> | 
            */ | 
| 222 | 
> | 
            inline void negate(const RectMatrix<Real, Row, Col>& m) { | 
| 223 | 
> | 
                for (unsigned int i = 0; i < Row; i++) | 
| 224 | 
> | 
                    for (unsigned int j = 0; j < Col; j++) | 
| 225 | 
> | 
                        data_[i][j] = -m.data_[i][j];         | 
| 226 | 
> | 
            } | 
| 227 | 
> | 
             | 
| 228 | 
> | 
            /** | 
| 229 | 
> | 
            * Sets the value of this matrix to the sum of itself and m (*this += m). | 
| 230 | 
> | 
            * @param m the other matrix | 
| 231 | 
> | 
            */ | 
| 232 | 
> | 
            inline void add( const RectMatrix<Real, Row, Col>& m ) { | 
| 233 | 
> | 
                for (unsigned int i = 0; i < Row; i++) | 
| 234 | 
> | 
                    for (unsigned int j = 0; j < Col; j++)         | 
| 235 | 
> | 
                    data_[i][j] += m.data_[i][j]; | 
| 236 | 
> | 
            } | 
| 237 | 
> | 
             | 
| 238 | 
> | 
            /** | 
| 239 | 
> | 
            * Sets the value of this matrix to the sum of m1 and m2 (*this = m1 + m2). | 
| 240 | 
> | 
            * @param m1 the first matrix | 
| 241 | 
> | 
            * @param m2 the second matrix | 
| 242 | 
> | 
            */ | 
| 243 | 
> | 
            inline void add( const RectMatrix<Real, Row, Col>& m1, const RectMatrix<Real, Row, Col>& m2 ) { | 
| 244 | 
> | 
                for (unsigned int i = 0; i < Row; i++) | 
| 245 | 
> | 
                    for (unsigned int j = 0; j < Col; j++)         | 
| 246 | 
> | 
                    data_[i][j] = m1.data_[i][j] + m2.data_[i][j]; | 
| 247 | 
> | 
            } | 
| 248 | 
> | 
             | 
| 249 | 
> | 
            /** | 
| 250 | 
> | 
            * Sets the value of this matrix to the difference  of itself and m (*this -= m). | 
| 251 | 
> | 
            * @param m the other matrix | 
| 252 | 
> | 
            */ | 
| 253 | 
> | 
            inline void sub( const RectMatrix<Real, Row, Col>& m ) { | 
| 254 | 
> | 
                for (unsigned int i = 0; i < Row; i++) | 
| 255 | 
> | 
                    for (unsigned int j = 0; j < Col; j++)         | 
| 256 | 
> | 
                        data_[i][j] -= m.data_[i][j]; | 
| 257 | 
> | 
            } | 
| 258 | 
> | 
             | 
| 259 | 
> | 
            /** | 
| 260 | 
> | 
            * Sets the value of this matrix to the difference of matrix m1 and m2 (*this = m1 - m2). | 
| 261 | 
> | 
            * @param m1 the first matrix | 
| 262 | 
> | 
            * @param m2 the second matrix | 
| 263 | 
> | 
            */ | 
| 264 | 
> | 
            inline void sub( const RectMatrix<Real, Row, Col>& m1, const RectMatrix<Real, Row, Col>& m2){ | 
| 265 | 
> | 
                for (unsigned int i = 0; i < Row; i++) | 
| 266 | 
> | 
                    for (unsigned int j = 0; j < Col; j++)         | 
| 267 | 
> | 
                        data_[i][j] = m1.data_[i][j] - m2.data_[i][j]; | 
| 268 | 
> | 
            } | 
| 269 | 
  | 
 | 
| 270 | 
< | 
            return result; | 
| 271 | 
< | 
        } | 
| 270 | 
> | 
            /** | 
| 271 | 
> | 
            * Sets the value of this matrix to the scalar multiplication of itself (*this *= s). | 
| 272 | 
> | 
            * @param s the scalar value | 
| 273 | 
> | 
            */ | 
| 274 | 
> | 
            inline void mul( Real s ) { | 
| 275 | 
> | 
                for (unsigned int i = 0; i < Row; i++) | 
| 276 | 
> | 
                    for (unsigned int j = 0; j < Col; j++)   | 
| 277 | 
> | 
                        data_[i][j] *= s; | 
| 278 | 
> | 
            } | 
| 279 | 
> | 
 | 
| 280 | 
> | 
            /** | 
| 281 | 
> | 
            * Sets the value of this matrix to the scalar multiplication of matrix m  (*this = s * m). | 
| 282 | 
> | 
            * @param s the scalar value | 
| 283 | 
> | 
            * @param m the matrix | 
| 284 | 
> | 
            */ | 
| 285 | 
> | 
            inline void mul( Real s, const RectMatrix<Real, Row, Col>& m ) { | 
| 286 | 
> | 
                for (unsigned int i = 0; i < Row; i++) | 
| 287 | 
> | 
                    for (unsigned int j = 0; j < Col; j++)   | 
| 288 | 
> | 
                        data_[i][j] = s * m.data_[i][j]; | 
| 289 | 
> | 
            } | 
| 290 | 
> | 
 | 
| 291 | 
> | 
            /** | 
| 292 | 
> | 
            * Sets the value of this matrix to the scalar division of itself  (*this /= s ). | 
| 293 | 
> | 
            * @param s the scalar value | 
| 294 | 
> | 
            */              | 
| 295 | 
> | 
            inline void div( Real s) { | 
| 296 | 
> | 
                for (unsigned int i = 0; i < Row; i++) | 
| 297 | 
> | 
                    for (unsigned int j = 0; j < Col; j++)   | 
| 298 | 
> | 
                        data_[i][j] /= s; | 
| 299 | 
> | 
            } | 
| 300 | 
> | 
 | 
| 301 | 
> | 
            /** | 
| 302 | 
> | 
            * Sets the value of this matrix to the scalar division of matrix m  (*this = m /s). | 
| 303 | 
> | 
            * @param s the scalar value | 
| 304 | 
> | 
            * @param m the matrix | 
| 305 | 
> | 
            */ | 
| 306 | 
> | 
            inline void div( Real s, const RectMatrix<Real, Row, Col>& m ) { | 
| 307 | 
> | 
                for (unsigned int i = 0; i < Row; i++) | 
| 308 | 
> | 
                    for (unsigned int j = 0; j < Col; j++)   | 
| 309 | 
> | 
                        data_[i][j] = m.data_[i][j] / s; | 
| 310 | 
> | 
            } | 
| 311 | 
> | 
 | 
| 312 | 
> | 
            /** | 
| 313 | 
> | 
             *  Multiples a scalar into every element of this matrix. | 
| 314 | 
> | 
             * @param s the scalar value | 
| 315 | 
> | 
             */ | 
| 316 | 
> | 
            RectMatrix<Real, Row, Col>& operator *=(const Real s) { | 
| 317 | 
> | 
                this->mul(s); | 
| 318 | 
> | 
                return *this; | 
| 319 | 
> | 
            } | 
| 320 | 
> | 
 | 
| 321 | 
> | 
            /** | 
| 322 | 
> | 
             *  Divides every element of this matrix by a scalar. | 
| 323 | 
> | 
             * @param s the scalar value | 
| 324 | 
> | 
             */ | 
| 325 | 
> | 
            RectMatrix<Real, Row, Col>& operator /=(const Real s) { | 
| 326 | 
> | 
                this->div(s); | 
| 327 | 
> | 
                return *this; | 
| 328 | 
> | 
            } | 
| 329 | 
> | 
 | 
| 330 | 
> | 
            /** | 
| 331 | 
> | 
             * Sets the value of this matrix to the sum of the other matrix and itself (*this += m). | 
| 332 | 
> | 
             * @param m the other matrix | 
| 333 | 
> | 
             */ | 
| 334 | 
> | 
            RectMatrix<Real, Row, Col>& operator += (const RectMatrix<Real, Row, Col>& m) { | 
| 335 | 
> | 
                add(m); | 
| 336 | 
> | 
                return *this; | 
| 337 | 
> | 
             } | 
| 338 | 
> | 
 | 
| 339 | 
> | 
            /** | 
| 340 | 
> | 
             * Sets the value of this matrix to the differerence of itself and the other matrix (*this -= m)  | 
| 341 | 
> | 
             * @param m the other matrix | 
| 342 | 
> | 
             */ | 
| 343 | 
> | 
            RectMatrix<Real, Row, Col>& operator -= (const RectMatrix<Real, Row, Col>& m){ | 
| 344 | 
> | 
                sub(m); | 
| 345 | 
> | 
                return *this; | 
| 346 | 
> | 
            } | 
| 347 | 
> | 
 | 
| 348 | 
> | 
            /** Return the transpose of this matrix */ | 
| 349 | 
> | 
            RectMatrix<Real,  Col, Row> transpose(){ | 
| 350 | 
> | 
                RectMatrix<Real,  Col, Row> result; | 
| 351 | 
> | 
                 | 
| 352 | 
> | 
                for (unsigned int i = 0; i < Row; i++) | 
| 353 | 
> | 
                    for (unsigned int j = 0; j < Col; j++)               | 
| 354 | 
> | 
                        result(j, i) = data_[i][j]; | 
| 355 | 
> | 
 | 
| 356 | 
> | 
                return result; | 
| 357 | 
> | 
            } | 
| 358 | 
  | 
         | 
| 359 | 
  | 
        protected: | 
| 360 | 
  | 
            Real data_[Row][Col]; | 
| 443 | 
  | 
            for (unsigned int i = 0; i < Row; i++) | 
| 444 | 
  | 
                for (unsigned int j = 0; j < Col; j++) | 
| 445 | 
  | 
                    for (unsigned int k = 0; k < SameDim; k++) | 
| 446 | 
< | 
                        result(i, j)  = m1(i, k) * m2(k, j);                 | 
| 446 | 
> | 
                        result(i, j)  += m1(i, k) * m2(k, j);                 | 
| 447 | 
  | 
 | 
| 448 | 
  | 
        return result; | 
| 449 | 
  | 
    } | 
| 479 | 
  | 
 | 
| 480 | 
  | 
        return result; | 
| 481 | 
  | 
    }     | 
| 482 | 
+ | 
 | 
| 483 | 
+ | 
    /** | 
| 484 | 
+ | 
     * Write to an output stream | 
| 485 | 
+ | 
     */ | 
| 486 | 
+ | 
    template<typename Real,  unsigned int Row, unsigned int Col> | 
| 487 | 
+ | 
    std::ostream &operator<< ( std::ostream& o, const RectMatrix<Real, Row, Col>& m) { | 
| 488 | 
+ | 
        for (unsigned int i = 0; i < Row ; i++) { | 
| 489 | 
+ | 
            o << "("; | 
| 490 | 
+ | 
            for (unsigned int j = 0; j < Col ; j++) { | 
| 491 | 
+ | 
                o << m(i, j); | 
| 492 | 
+ | 
                if (j != Col -1) | 
| 493 | 
+ | 
                    o << "\t"; | 
| 494 | 
+ | 
            } | 
| 495 | 
+ | 
            o << ")" << std::endl; | 
| 496 | 
+ | 
        } | 
| 497 | 
+ | 
        return o;         | 
| 498 | 
+ | 
    }     | 
| 499 | 
  | 
} | 
| 500 | 
  | 
#endif //MATH_RECTMATRIX_HPP |