Jpp - the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Functions
JMatrixNS.cc File Reference

Example program to test inversion of symmetric matrix. More...

#include <string>
#include <iostream>
#include <iomanip>
#include "TRandom3.h"
#include "TMatrixTSym.h"
#include "JLang/JException.hh"
#include "JMath/JMatrixNS.hh"
#include "JMath/JMathTestkit.hh"
#include "Jeep/JTimer.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Example program to test inversion of symmetric matrix.

Author
mdejong

Definition in file JMatrixNS.cc.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 23 of file JMatrixNS.cc.

24 {
25  using namespace std;
26  using namespace JPP;
27 
28  int N;
29  double precision;
30  size_t numberOfInversions;
31  UInt_t seed;
32  int debug;
33 
34  try {
35 
36  JParser<> zap("Example program to test inversion of symmetric matrix.");
37 
38  zap['N'] = make_field(N);
39  zap['e'] = make_field(precision) = 1.0e-6;
40  zap['n'] = make_field(numberOfInversions) = 1;
41  zap['S'] = make_field(seed) = 0;
42  zap['d'] = make_field(debug) = 3;
43 
44  zap(argc, argv);
45  }
46  catch(const exception &error) {
47  FATAL(error.what() << endl);
48  }
49 
50 
51  gRandom->SetSeed(seed);
52 
53  const Double_t xmin = -1.0;
54  const Double_t xmax = +1.0;
55 
56  JMatrixNS A(N);
57 
58  for (int i = 0; i != N; ++i) {
59 
60  A(i,i) = gRandom->Uniform(xmin,xmax);
61 
62  for (int j = 0; j != i; ++j) {
63  A(j,i) = A(i,j) = gRandom->Uniform(xmin,xmax);
64  }
65  }
66 
67 
68  try {
69 
70  DEBUG("Matrix A" << endl);
71  DEBUG(A << endl);
72 
73  JMatrixNS B(A);
74 
75  JTimer timer;
76 
77  timer.start();
78 
79  for (size_t i = 2*(numberOfInversions/2) + 1; i != 0; --i) {
80  B.invert();
81  }
82 
83  timer.stop();
84 
85  NOTICE("Elapsed time [us] " << setw(8) << timer.usec_wall << endl);
86  DEBUG("Matrix A^-1" << endl);
87  DEBUG(B << endl);
88 
89  {
90  TMatrixTSym<double> R(B.size());
91 
92  for (size_t row = 0; row != B.size(); ++row) {
93  for (size_t col = 0; col != B.size(); ++col) {
94  R(row, col) = B(row, col);
95  }
96  }
97 
98  timer.start();
99 
100  for (size_t i = 2*(numberOfInversions/2) + 1; i != 0; --i) {
101  R.InvertFast();
102  }
103 
104  timer.stop();
105 
106  NOTICE("Elapsed time (ROOT) [us] " << setw(8) << timer.usec_wall << endl);
107  }
108 
109  JMatrixNS C(A);
110 
111  C.mul(B);
112 
113  DEBUG("Matrix A x A^-1" << endl);
114  DEBUG(C << endl);
115 
116  NOTICE("A x A^-1 = I ? " << C.isIdentity(precision) << endl);
117 
118  if (!C.isIdentity(precision)) {
119  ERROR("Matrix A x A^-1 /= I" << endl);
120  }
121 
122  ASSERT (C.isIdentity(precision));
123 
124  const double big = 1.0e5;
125 
126  for (int i = 0; i != N; ++i) {
127 
128  A(i,i) += big;
129 
130  timer.reset();
131  timer.start();
132 
133  B.update(i, big);
134 
135  timer.stop();
136 
137  NOTICE("Elapsed time [us] " << setw(8) << timer.usec_wall << endl);
138  NOTICE("Pivot " << setw(2) << i << '+' << big << ' ' << (JMatrixNS(A).mul(B).isIdentity(precision) ? "okay" : "error") << endl);
139 
140  ASSERT(JMatrixNS(A).mul(B).isIdentity(precision));
141 
142  A(i,i) -= big;
143 
144  B.update(i, -big);
145  }
146 
147  }
148  catch (const JException& error) {
149  FATAL(error << endl);
150  }
151 
152  return 0;
153 }
Utility class to parse command line options.
Definition: JParser.hh:1500
static const double C
Physics constants.
#define ASSERT(A,...)
Assert macro.
Definition: JMessage.hh:90
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:1961
#define NOTICE(A)
Definition: JMessage.hh:64
#define ERROR(A)
Definition: JMessage.hh:66
int debug
debug level
Definition: JSirene.cc:63
#define FATAL(A)
Definition: JMessage.hh:67
then echo Variable JPP_DIR undefined exit fi source $JPP_DIR setenv sh $JPP_DIR set_variable NORTH set_variable EAST set_variable SOUTH set_variable WEST set_variable WORKDIR tmp set_variable R set_variable CT set_variable YMAX set_variable YMIN if do_usage *then usage $script[distance] fi case set_variable R
Definition: JDrawLED.sh:35
then usage $script< input_file >< detector_file > fi set_variable OUTPUT_DIR set_variable SELECTOR JDAQTimesliceL1 set_variable DEBUG case set_variable DEBUG
int j
Definition: JPolint.hh:666
then usage $script[input file[working directory[option]]] nWhere option can be N
Definition: JMuonPostfit.sh:35
source $JPP_DIR setenv csh $JPP_DIR eval JShellParser o a A