root/library/tests/chmat_test.cpp @ 386

Revision 386, 1.4 kB (checked in by mido, 15 years ago)

possibly broken? 4th part

  • Property svn:eol-style set to native
Line 
1
2#include "math/chmat.h"
3
4using namespace itpp;
5
6//These lines are needed for use of cout and endl
7using std::cout;
8using std::endl;
9
10int main() {
11        // Kalman filter
12        mat A0 = randu(3,3);
13        mat A = A0*A0.T();
14       
15        //Test constructor
16        chmat Ch(A);
17   cout << "Testing constructors:" << endl
18       << "A = " << A << endl
19       << "Ch = " << Ch._Ch() << endl
20       << "Ch.to_mat() = " << Ch.to_mat() << endl << endl;
21       
22   //Test inversion
23        chmat iCh(3);
24        Ch.inv(iCh);
25   cout << "inv(A) = " << inv(A) <<endl
26        << "inv(Ch).to_mat() = " << iCh.to_mat() <<endl <<endl;
27       
28   //Test logdet
29   cout << "logdet(A) = " << log(det(A)) << endl
30                        << "logdet(Ch) = " << Ch.logdet() << endl <<endl;
31                               
32   //Test add
33   chmat Ch2(Ch);
34   Ch2.add(Ch);
35   cout << "A+A = " << A+A << endl
36                        <<      "Ch2.add(Ch) = " << Ch2.to_mat() << endl <<endl;
37                               
38        vec v=randu(3);
39   //Test qform
40   cout << "vAv' = " << v*(A*v) << endl
41                        <<      "qform(Ch,v) = " << Ch.qform(v) << endl <<endl;
42       
43   //Test invqform
44   cout << "v inv(A)v' = " << v*(inv(A)*v) << endl
45                        <<      "invqform(Ch,v) = " << Ch.invqform(v) << endl <<endl;
46                               
47   //Test opupdate
48   Ch2=Ch;
49   Ch2.opupdt(v,1.0);
50   cout << "A+vv' = " << A+outer_product(v,v) << endl
51                        <<      "opupdt(Ch,v) = " << Ch2.to_mat() << endl <<endl;
52
53   vec vCh=vec(Ch._Ch()._data(),9);
54   cout << "vectorized Ch: " << vCh <<endl;
55   chmat nCh(3);
56   nCh.setCh(vCh);
57   cout << "Ch from vec: " << nCh._Ch() <<endl;
58
59}
Note: See TracBrowser for help on using the browser.