root/library/bdm/math/chmat.cpp @ 495

Revision 495, 1.8 kB (checked in by vbarta, 15 years ago)

moved square matrices to namespace bdm

  • Property svn:eol-style set to native
Line 
1
2#include "chmat.h"
3
4//using std::endl;
5
6namespace bdm
7{
8
9void chmat::opupdt ( const vec &v, double w ) {
10//TODO see cholupdt in lhotse
11        mat Z;
12        mat R;
13        mat V ( 1, v.length() );
14        V.set_row ( 0, v*sqrt ( w ) );
15        Z = concat_vertical ( Ch, V );
16        qr ( Z, R );
17        Ch = R ( 0, Ch.rows() - 1, 0, Ch.cols() - 1 );
18};
19mat chmat::to_mat() const {
20        mat F = Ch.T() * Ch;
21        return F;
22};
23void chmat::mult_sym ( const mat &C ) {
24        it_assert_debug ( C.rows() == dim, "Wrong dimension of U" );
25        if ( !qr ( Ch*C.T(), Ch ) ) {
26                it_warning ( "QR unstable in chmat mult_sym" );
27        }
28};
29void chmat::mult_sym ( const mat &C , chmat &U ) const {
30        it_assert_debug ( C.rows() == U.dim, "Wrong dimension of U" );
31        if ( !qr ( Ch*C.T(), U.Ch ) ) {
32                it_warning ( "QR unstable in chmat mult_sym" );
33        }
34};
35void chmat::mult_sym_t ( const mat &C ) {
36        it_assert_debug ( C.cols() == dim, "Wrong dimension of U" );
37        if ( !qr ( Ch*C, Ch ) ) {
38                it_warning ( "QR unstable in chmat mult_sym" );
39        }
40};
41void chmat::mult_sym_t ( const mat &C, chmat &U ) const {
42        it_assert_debug ( C.cols() == U.dim, "Wrong dimension of U" );
43        if ( !qr ( Ch*C, U.Ch ) ) {
44                it_warning ( "QR unstable in chmat mult_sym" );
45        }
46}
47
48double chmat::logdet() const {
49        double ldet = 0.0;
50        int i;
51        //sum of logs of (possibly negative!) diagonal entries
52        for ( i = 0; i < Ch.rows(); i++ ) {
53                ldet += log ( std::fabs ( Ch ( i, i ) ) );
54        }
55        return 2*ldet; //compensate for Ch being sqrt()
56}
57
58//TODO can be done more efficiently using BLAS, see triangular matrices
59vec chmat::sqrt_mult ( const vec &v ) const {
60        vec pom;
61        pom = Ch * v;
62        return pom;
63}
64
65double chmat::qform ( const vec &v ) const {
66        vec pom;
67        pom = Ch * v;
68        return pom*pom;
69}
70
71double chmat::invqform ( const vec &v ) const {
72        vec pom ( v.length() );
73        forward_substitution ( Ch.T(), v, pom );
74        return pom*pom;
75}
76
77void chmat::clear() {
78        Ch.clear();
79}
80
81}
Note: See TracBrowser for help on using the browser.