- Timestamp:
- 03/05/08 16:01:56 (16 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
bdm/math/libDC.h
r32 r33 86 86 sqmat(const int dim0): dim(dim0){}; 87 87 protected: 88 //! dimension of the square matrix 88 89 int dim; 89 90 }; … … 97 98 { 98 99 protected: 100 //! Full matrix on which the operations are performed 99 101 mat M; 100 102 public: … … 103 105 void mult_sym ( const mat &C); 104 106 void mult_sym_t ( const mat &C); 107 //! store result of \c mult_sym in external matrix $U$ 105 108 void mult_sym ( const mat &C, fsqmat &U) const; 109 //! store result of \c mult_sym_t in external matrix $U$ 106 110 void mult_sym_t ( const mat &C, fsqmat &U) const; 107 111 void clear(); … … 129 133 vec sqrt_mult (const vec &v ) const {it_error ( "not implemented" );return v;}; 130 134 135 //! add another fsqmat matrix 131 136 fsqmat& operator += ( const fsqmat &A ) {M+=A.M;return *this;}; 137 //! subtrack another fsqmat matrix 132 138 fsqmat& operator -= ( const fsqmat &A ) {M-=A.M;return *this;}; 139 //! multiply by a scalar 133 140 fsqmat& operator *= ( double x ) {M*=x;return *this;}; 134 141 // fsqmat& operator = ( const fsqmat &A) {M=A.M; return *this;}; 135 142 //! print full matrix 136 143 friend std::ostream &operator<< ( std::ostream &os, const fsqmat &sq ); 137 144 138 145 }; 139 146 147 /*! \brief Matrix stored in LD form, (typically known as UD) 148 149 Matrix is decomposed as follows: \f[M = L'DL\f] where only $L$ and $D$ matrices are stored. 150 All inplace operations modifies only these and the need to compose and decompose the matrix is avoided. 151 */ 140 152 class ldmat: sqmat 141 153 { … … 162 174 void mult_sym ( const mat &C); 163 175 void mult_sym_t ( const mat &C); 176 //! Add another matrix in LD form with weight w 164 177 void add ( const ldmat &ld2, double w=1.0 ); 165 178 double logdet() const; … … 172 185 173 186 /*! \brief Matrix inversion preserving the chosen form. 174 175 187 @param Inv a space where the inverse is stored. 176 177 188 */ 178 189 virtual void inv ( ldmat &Inv ) const; 179 190 180 191 /*! \brief Symmetric multiplication of $U$ by a general matrix $C$, result of which is stored in the current class. 181 192 @param C matrix to multiply with 182 193 @param U a space where the inverse is stored. 183 184 194 */ 185 195 void mult_sym ( const mat &C, ldmat &U) const; 186 196 187 197 /*! \brief Symmetric multiplication of $U$ by a transpose of a general matrix $C$, result of which is stored in the current class. 188 198 @param C matrix to multiply with 189 199 @param U a space where the inverse is stored. 190 191 200 */ 192 201 void mult_sym_t ( const mat &C, ldmat &U) const; … … 196 205 197 206 The new decomposition fullfills: $A'*diag(D)*A = self.L'*diag(self.D)*self.L$ 198 199 207 @param A general matrix 200 208 @param D0 general vector 201 202 209 */ 203 210 void ldform (const mat &A,const vec &D0 ); … … 205 212 //! Access functions 206 213 void setD (const vec &nD){D=nD;} 214 //! Access functions 215 void setD (const vec &nD, int i){D.replace_mid(i,nD);} //Fixme can be more general 216 //! Access functions 207 217 void setL (const vec &nL){L=nL;} 208 218 219 //! add another ldmat matrix 209 220 ldmat& operator += ( const ldmat &ldA ); 221 //! subtract another ldmat matrix 210 222 ldmat& operator -= ( const ldmat &ldA ); 223 //! multiply by a scalar 211 224 ldmat& operator *= ( double x ); 212 225 226 //! print both \c L and \c D 213 227 friend std::ostream &operator<< ( std::ostream &os, const ldmat &sq ); 214 228 215 229 216 230 protected: 231 //! Positive vector $D$ 217 232 vec D; 233 //! Lower-triangular matrix $L$ 218 234 mat L; 219 235 … … 221 237 222 238 //////// Operations: 223 239 //!mapping of add operation to operators 224 240 inline ldmat& ldmat::operator += ( const ldmat &ldA ) {this->add ( ldA );return *this;} 241 //!mapping of negative add operation to operators 225 242 inline ldmat& ldmat::operator -= ( const ldmat &ldA ) {this->add ( ldA,-1.0 );return *this;} 243 //!access function 226 244 inline int ldmat::cols() const {return dim;} 245 //!access function 227 246 inline int ldmat::rows() const {return dim;} 228 247