- Main Page
- Related Pages
- Classes
- Files

- File List
- File Members

# chmat.h

Go to the documentation of this file.

    00001
    00013 #ifndef CHMAT_H
    00014 #define CHMAT_H
    00015
    00016
    00017 #include "square_mat.h"
    00018
    00024 class chmat : public sqmat {
    00025 protected:
    00027         mat Ch;
    00028 public:
    00029
    00030         void opupdt ( const vec &v, double w );
    00031         mat to_mat() const;
    00032         void mult_sym ( const mat &C );
    00033         void mult_sym ( const mat &C , chmat &U ) const;
    00034         void mult_sym_t ( const mat &C );
    00035         void mult_sym_t ( const mat &C, chmat &U ) const;
    00036         double logdet() const;
    00037         vec sqrt_mult ( const vec &v ) const;
    00038         double qform ( const vec &v ) const;
    00039         double invqform ( const vec &v ) const;
    00040         void clear();
    00042         void add ( const chmat &A2, double w=1.0 ) {
    00043                 it_assert_debug(dim==A2.dim,"Matrices of unequal dimension");
    00044                 mat pre=concat_vertical(Ch,sqrt(w)*A2.Ch);
    00045                 mat post=zeros(pre.rows(),pre.cols());
    00046                 if(!qr(pre,post)) {it_warning("Unstable QR in chmat add");}
    00047                 Ch=post(0,dim-1,0,dim-1);
    00048         };
    00050         void inv ( chmat &Inv ) const   { ( Inv.Ch ) = itpp::inv ( Ch ).T();}; //Fixme: can be more efficient
    00051         ;
    00052 //      void inv ( mat &Inv );
    00053
    00055         virtual ~chmat() {};
    00057         chmat ( ) : sqmat (),Ch ( ) {};
    00059         chmat ( const int dim0 ) : sqmat ( dim0 ),Ch ( dim0,dim0 ) {};
    00061         chmat ( const vec &v) : sqmat ( v.length() ),Ch ( diag(sqrt(v)) ) {};
    00063         chmat ( const chmat &Ch0) : sqmat ( Ch0.dim),Ch ( Ch0.dim,Ch0.dim ) {Ch=Ch0.Ch;};
    00065         chmat ( const mat &M ) : sqmat ( M.rows() ),Ch ( M.rows(),M.cols() ) {
    00066                 mat Q;
    00067                 it_assert_debug ( M.rows() ==M.cols(),"chmat:: input matrix must be square!" );
    00068                 Ch=chol ( M );
    00069         };
    00071         chmat ( const chmat &M, const ivec &perm ):sqmat(M.rows()){it_error("not implemneted");};
    00073         mat & _Ch() {return Ch;}
    00075         const mat & _Ch() const {return Ch;}
    00077         void setD ( const vec &nD ) {Ch=diag ( sqrt(nD) );}
    00079         void setCh ( const vec &chQ ) {
    00080                 it_assert_debug(chQ.length()==dim*dim,"");
    00081                 copy_vector(dim*dim, chQ._data(), Ch._data());
    00082         }
    00084         void setD ( const vec &nD, int i ) {for ( int j=i;j<nD.length();j++ ) {Ch( j,j ) =sqrt(nD ( j-i ));}} //Fixme can be more general
    00085
    00087         chmat& operator += ( const chmat &A2 );
    00088         chmat& operator -= ( const chmat &A2 );
    00089         chmat& operator * ( const double &d ){Ch*sqrt(d); return *this;};
    00090         chmat& operator = ( const chmat &A2 ){Ch=A2.Ch;dim=A2.dim;return *this;}
    00091         chmat& operator *= ( double x ){Ch*=sqrt(x); return *this;};
    00092 };
    00093
    00094
    00097 inline chmat& chmat::operator += ( const chmat &A2 )  {this->add ( A2 );return *this;}
    00099 inline chmat& chmat::operator -= ( const chmat &A2 )  {this->add ( A2,-1.0 );return *this;}
    00100
    00101 #endif // CHMAT_H