Changeset 437

Show
Ignore:
Timestamp:
07/28/09 15:31:57 (15 years ago)
Author:
smidl
Message:

missing functions in chmat - square_matrix test now passes for chmat

Location:
library
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • library/bdm/math/chmat.cpp

    r434 r437  
    1717mat chmat::to_mat() const {mat F=Ch.T() *Ch;return F;}; 
    1818void chmat::mult_sym ( const mat &C ) { 
    19         it_error ( "not implemented" ); 
     19        it_assert_debug(C.cols()==dim, "Wrong dimension of U"); 
     20        if(!qr(Ch*C.T(), Ch)) {it_warning("QR unstable in chmat mult_sym");} 
    2021}; 
    2122void chmat::mult_sym ( const mat &C , chmat &U ) const { 
    22         mat Z=C*Ch; 
    23         U.Ch= chol(Z*Z.T()); 
     23        it_assert_debug(C.cols()==U.dim, "Wrong dimension of U"); 
     24        if(!qr(Ch*C.T(), U.Ch)) {it_warning("QR unstable in chmat mult_sym");} 
    2425}; 
    2526void chmat::mult_sym_t ( const mat &C ) { 
    26         it_error ( "not implemented" ); 
     27        it_assert_debug(C.rows()==dim, "Wrong dimension of U"); 
     28        if(!qr(Ch*C, Ch)) {it_warning("QR unstable in chmat mult_sym");} 
    2729}; 
    2830void chmat::mult_sym_t ( const mat &C, chmat &U ) const { 
    29         it_error ( "not implemented" ); 
     31        it_assert_debug(C.rows()==U.dim, "Wrong dimension of U"); 
     32        if(!qr(Ch*C, U.Ch)) {it_warning("QR unstable in chmat mult_sym");} 
    3033}; 
    3134double chmat::logdet() const { 
  • library/bdm/math/chmat.h

    r384 r437  
    4040        void clear(); 
    4141        //! add another chmat \c A2 with weight \c w. 
    42         void add ( const chmat &A2, double w=1.0 ) {}; 
     42        void add ( const chmat &A2, double w=1.0 ) { 
     43                it_assert_debug(dim==A2.dim,"Matrices of unequal dimension"); 
     44                mat pre=concat_vertical(Ch,sqrt(w)*A2.Ch);  
     45                mat post=zeros(pre.rows(),pre.cols());  
     46                if(!qr(pre,post)) {it_warning("Unstable QR in chmat add");} 
     47                Ch=post(0,dim-1,0,dim-1); 
     48        }; 
    4349        //!Inversion in the same form, i.e. cholesky 
    4450        void inv ( chmat &Inv ) const   { ( Inv.Ch ) = itpp::inv ( Ch ).T();}; //Fixme: can be more efficient 
     
    8086        //! Operators 
    8187        chmat& operator += ( const chmat &A2 ); 
    82         chmat& operator -= ( const chmat &A2 ) ; 
    83         chmat& operator * ( const chmat &A2 ); 
    84         chmat& operator * ( const double &d ){Ch*d; return *this;}; 
     88        chmat& operator -= ( const chmat &A2 ); 
     89        chmat& operator * ( const double &d ){Ch*sqrt(d); return *this;}; 
    8590        chmat& operator = ( const chmat &A2 ){Ch=A2.Ch;dim=A2.dim;return *this;} 
     91        chmat& operator *= ( double x ){Ch*=sqrt(x); return *this;}; 
    8692}; 
    8793 
  • library/tests/square_mat_test.cpp

    r434 r437  
    100100 
    101101TEST(test_chmat) { 
    102     test_square_matrix_minimum<chmat>(epsilon); 
     102    test_square_matrix<chmat>(epsilon); 
    103103}