25{
28
29 int N;
30 double precision;
34
35 try {
36
37 JParser<> zap(
"Example program to test inversion of symmetric matrix.");
38
44
46 }
47 catch(const exception &error) {
49 }
50
51
53
55
58
60
61 for (int i = 0; i != N; ++i) {
62
63 A(i,i) =
gRandom->Uniform(xmin,xmax);
64
65 for (
int j = 0;
j != i; ++
j) {
66 A(j,i) = A(i,j) =
gRandom->Uniform(xmin,xmax);
67 }
68 }
69
72
73 try {
74
76
77 const chrono::steady_clock::time_point t0 = chrono::steady_clock::now();
78
80 B.invert();
81 }
82
83 const chrono::steady_clock::time_point t1 = chrono::steady_clock::now();
84
85 NOTICE(
"Elapsed time (Jpp) [us] " <<
setw(8) << chrono::duration_cast<chrono::microseconds>(t1 - t0).count() <<
endl);
88
90
91 C.mul(B);
92
95
96 NOTICE(
"A x A^-1 = I ? " << C.isIdentity(precision) <<
endl);
97
98 if (!C.isIdentity(precision)) {
100 }
101
102 ASSERT(C.isIdentity(precision));
103 }
106 }
107
108 try {
109
111
112 for (
size_t row = 0;
row != A.size(); ++
row) {
113 for (
size_t col = 0;
col != A.size(); ++
col) {
115 }
116 }
117
118 const chrono::steady_clock::time_point t0 = chrono::steady_clock::now();
119
121 B.InvertFast();
122 }
123
124 const chrono::steady_clock::time_point t1 = chrono::steady_clock::now();
125
126 NOTICE(
"Elapsed time (ROOT) [us] " <<
setw(8) << chrono::duration_cast<chrono::microseconds>(t1 - t0).count() <<
endl);
127 }
130 }
131
132 try {
133
135
136 B.invert();
137
139
140 for (int i = 0; i != N; ++i) {
141 X[i] =
gRandom->Uniform(xmin,xmax);
142 }
143
145
146 for (int i = 0; i != N; ++i) {
147 for (
int j = 0;
j != N; ++
j) {
148 Y[i] += B(i,j) * X[
j];
149 }
150 }
151
153
154 C.solve(X);
155
156 for (int i = 0; i != N; ++i) {
157
159
160 ASSERT(fabs(X[i] - Y[i]) <= precision);
161 }
162 }
165 }
166
167 try {
168
170
171 B.invert();
172
173 const double big = 1.0e5;
174
175 for (int i = 0; i != N; ++i) {
176
178
179 const chrono::steady_clock::time_point t0 = chrono::steady_clock::now();
180
182
183 const chrono::steady_clock::time_point t1 = chrono::steady_clock::now();
184
185 NOTICE(
"Elapsed time [us] " <<
setw(8) << chrono::duration_cast<chrono::microseconds>(t1 - t0).count() <<
endl);
186 NOTICE(
"Pivot " <<
setw(2) << i <<
'+' <<
big <<
' ' << (
JMatrixNS(A).mul(B).isIdentity(precision) ?
"okay" :
"error") <<
endl);
187
189
191
193 }
194 }
197 }
198
199 {
200 A.reset();
201
202 for (int i = 0; i != N; ++i) {
203 for (
int j = 0;
j != N; ++
j) {
204 ASSERT(A(i,j) == 0,
"Test reset (" << i <<
"," << j <<
")");
205 }
206 }
207 }
208
209 return 0;
210}
#define DEBUG(A)
Message macros.
#define ASSERT(A,...)
Assert macro.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Template definition of a multi-dimensional oscillation probability interpolation table.
Utility class to parse command line options.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Auxiliary data structure for floating point format specification.