Jpp
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
examples
JMath
JMatrixNS.cc
Go to the documentation of this file.
1
#include <string>
2
#include <iostream>
3
#include <iomanip>
4
5
#include "TRandom3.h"
6
7
#include "
JLang/JException.hh
"
8
#include "
JMath/JMatrixNS.hh
"
9
#include "
JMath/JMathTestkit.hh
"
10
11
#include "
Jeep/JTimer.hh
"
12
#include "
Jeep/JParser.hh
"
13
#include "
Jeep/JMessage.hh
"
14
15
16
/**
17
* \file
18
*
19
* Example program to test inversion of symmetric matrix.
20
* \author mdejong
21
*/
22
int
main
(
int
argc,
char
**argv)
23
{
24
using namespace
std;
25
using namespace
JPP;
26
27
int
N
;
28
double
precision;
29
size_t
numberOfInversions;
30
UInt_t seed;
31
int
debug
;
32
33
try
{
34
35
JParser<>
zap(
"Example program to test inversion of symmetric matrix."
);
36
37
zap[
'N'
] =
make_field
(
N
);
38
zap[
'e'
] =
make_field
(precision) = 1.0e-6;
39
zap[
'n'
] =
make_field
(numberOfInversions) = 1;
40
zap[
'S'
] =
make_field
(seed) = 0;
41
zap[
'd'
] =
make_field
(
debug
) = 3;
42
43
zap(argc, argv);
44
}
45
catch
(
const
exception &error) {
46
FATAL
(error.what() << endl);
47
}
48
49
50
gRandom->SetSeed(seed);
51
52
const
Double_t xmin = -1.0;
53
const
Double_t xmax = +1.0;
54
55
JMatrixNS
A
(
N
);
56
57
for
(
int
i = 0; i !=
N
; ++i) {
58
59
A
(i,i) = gRandom->Uniform(xmin,xmax);
60
61
for
(
int
j
= 0;
j
!= i; ++
j
) {
62
A
(
j
,i) =
A
(i,
j
) = gRandom->Uniform(xmin,xmax);
63
}
64
}
65
66
67
try
{
68
69
DEBUG
(
"Matrix A"
<< endl);
70
DEBUG
(A << endl);
71
72
JMatrixNS B(A);
73
74
JTimer timer;
75
76
timer.start();
77
78
for
(
size_t
i = 2*(numberOfInversions/2) + 1; i != 0; --i) {
79
B.invert();
80
}
81
82
timer.stop();
83
84
NOTICE
(
"Elapsed time [us] "
<< setw(8) << timer.usec_wall << endl);
85
DEBUG
(
"Matrix A^-1"
<< endl);
86
DEBUG
(B << endl);
87
88
JMatrixNS
C
(A);
89
90
C.mul(B);
91
92
DEBUG
(
"Matrix A x A^-1"
<< endl);
93
DEBUG
(C << endl);
94
95
NOTICE
(
"A x A^-1 = I ? "
<< C.isIdentity(precision) << endl);
96
97
if
(!C.isIdentity(precision)) {
98
ERROR
(
"Matrix A x A^-1 /= I"
<< endl);
99
}
100
101
ASSERT
(C.isIdentity(precision));
102
103
const
double
big = 1.0e5;
104
105
for
(
int
i = 0; i !=
N
; ++i) {
106
107
A
(i,i) += big;
108
109
timer.reset();
110
timer.start();
111
112
B.update(i, big);
113
114
timer.stop();
115
116
NOTICE
(
"Elapsed time [us] "
<< setw(8) << timer.usec_wall << endl);
117
NOTICE
(
"Pivot "
<< setw(2) << i <<
'+'
<< big <<
' '
<< (JMatrixNS(A).mul(B).isIdentity(precision) ?
"okay"
:
"error"
) << endl);
118
119
ASSERT
(JMatrixNS(A).mul(B).isIdentity(precision));
120
121
A
(i,i) -= big;
122
123
B.update(i, -big);
124
}
125
126
}
127
catch
(
const
JException& error) {
128
FATAL
(error << endl);
129
}
130
131
return
0;
132
}
JPARSER::JParser
Utility class to parse command line options.
Definition:
JParser.hh:1493
JException.hh
Exceptions.
JTimer.hh
JMathTestkit.hh
ASSERT
#define ASSERT(A,...)
Assert macro.
Definition:
JMessage.hh:90
make_field
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition:
JParser.hh:1954
NOTICE
#define NOTICE(A)
Definition:
JMessage.hh:64
ERROR
#define ERROR(A)
Definition:
JMessage.hh:66
debug
int debug
debug level
Definition:
JSirene.cc:61
JMessage.hh
General purpose messaging.
FATAL
#define FATAL(A)
Definition:
JMessage.hh:67
JParser.hh
Utility class to parse command line options.
JTOOLS::j
int j
Definition:
JPolint.hh:634
JTOOLS::C
static const double C
Speed of light in vacuum [m/ns].
Definition:
JConstants.hh:22
JMatrixNS.hh
N
then usage $script[input file[working directory[option]]] nWhere option can be N
Definition:
JMuonPostfit.sh:37
A
source $JPP_DIR setenv csh $JPP_DIR eval JShellParser o a A
Definition:
JShellParser.csh:15
DEBUG
#define DEBUG(A)
Message macros.
Definition:
JMessage.hh:62
main
int main(int argc, char *argv[])
Definition:
Main.cpp:15
Generated by
1.8.5