StRoot  1
matrixTest.cc
1 /***************************************************************************
2  *
3  * \$Id: matrixTest.cc,v 1.2 1999/12/21 15:14:53 ullrich Exp \$
4  *
5  * Author: Brian Lasiuk, April 1998
6  ***************************************************************************
7  *
8  * Description:
9  *
10  ***************************************************************************
11  *
12  * \$Log: matrixTest.cc,v \$
13  * Revision 1.2 1999/12/21 15:14:53 ullrich
14  * Modified to cope with new compiler version on Sun (CC5.0).
15  *
16  * Revision 1.1 1999/02/17 12:44:00 ullrich
17  * New Revision
18  *
19  * Revision 1.1 1999/01/23 00:26:47 ullrich
20  * Initial Revision
21  *
22  **************************************************************************/
23 #include "StGlobals.hh"
24
25 #define MATRIX_BOUND_CHECK
26 #define WITH_ST_THREEVECTOR
27 #include "StMatrix.hh"
28
29 #define SYMMETRIC
30 #ifndef SYMMETRIC
31 # define ASYMMETRIC
32 #endif
33
34 #if !defined(ST_NO_NAMESPACES) && !defined(ST_NO_EXCEPTIONS)
35 using std::logic_error;
36 #endif
37
38 template <class X>
39 X hold1(X a, unsigned int r, unsigned int q)
40 {
41  return a*a;
42 }
43
44 // --------------------- MAIN -------------------------- //
45 int main()
46 {
47 #ifdef SYMMETRIC
48  StMatrix<StDouble> A(2,2,1);
49
50  A(1,1) = 2;
51  A(1,2) = 1;
52  A(2,1) = 0;
53  A(2,2) = 5;
54
55  cout << "A=" << A << endl;
56
57  StMatrix<StFloat> B(2,2);
58
59  B(1,1) = 0;
60  B(1,2) = 1;
61  B(2,1) = 1;
62  B(2,2) = 0;
63
64  cout << "-B=" << -B;
65
66  StMatrix<StFloat> C(A);
67
68  cout << "C=" << C;
69  cout << "A=" << C;
70
71  C+=C;
72  cout << "C+=C =>" << C << endl;
73
74  cout << "C " << C;
75
76  C = B+A;
77  cout << "C=B+A:" << C << endl;
78
79  unsigned int ierr;
80  cout << "B.inverse(ierr)" << B.inverse(ierr) << endl;
81
82  StMatrix<StDouble> IDENTITY(2,2,1);
83
84  C = B*B.inverse(ierr);
85
86  if(C == IDENTITY)
87  cout << "C=B*B.inverse(ierr) == IDENTITY" << endl;
88  else
89  cout << "oops.." << endl;
90
91  cout << "1st row of C" << endl;
92  cout << C.sub(1,1,1,2) << endl;
93
94  StMatrix<StDouble> K(3,3,1);
95  K(1,3) = 2;
96  K(2,1) = -2;
97  K(1,3) = -1;
98
99  cout << "K=" << K << endl;
100
101  StMatrix<double> X(3,3);
102  for(int ii=1; ii<=3; ii++)
103  for(int jj=1; jj<=3; jj++)
104  X(ii,jj) = 1;
105
106  StMatrix<float> Y(X);
107
108  cout << "X" << X << endl;
109
110  cout << "Y+X" << (Y+X) << endl;
111  cout << "Y*X" << (Y*X) << endl;
112
113 #ifdef ST_NO_TEMPLATE_DEF_ARGS
115 #else
116  StMatrix<> TT;
117 #endif
118  TT = K.apply(hold1);
119  cout << "square each element of K:=" << TT << endl;
120
121 #ifdef ST_NO_TEMPLATE_DEF_ARGS
122  StThreeVector<double> a(1,1,1);
123 #else
124  StThreeVector<> a(1,1,1);
125 #endif
126  cout << "StThreeVector a= " << a << endl;
127  cout << "a*K=" << a*K << endl;
128  cout << "K*a=" << K*a << endl;
129
130  cout << "Testing exception handling." << endl;
131  cout << "Note that depending on your platform" << endl;
132  cout << "the resulting actions might differ." << endl;
133  StMatrix<StDouble> Z(3,3,1);
134 #ifndef ST_NO_EXCEPTIONS
135  try {
136  Z = K*A;
137  }
138  catch(logic_error &e){
139  cout << "Caught exception: " << e.what() << endl;
140  }
141 #else
142  Z = K*A;
143 #endif
144
145 #endif // SYMMETRIC
146
147 #ifdef ASYMMETRIC
148  cout << "TESTING ANTI-SYMMETRIC MATRICES" << endl;
149  StMatrix<StDouble> A(2,3);
150
151  A(1,1) = 2;
152  A(1,2) = 1;
153  A(2,1) = 0;
154  A(2,2) = 5;
155
156  cout << "A=" << A << endl;
157
158  StMatrix<StFloat> B(3,2);
159
160  B(1,1) = 0;
161  B(1,2) = 1;
162  B(2,1) = 1;
163  B(2,2) = 0;
164
165  cout << "-B=" << -B;
166
167  StMatrix<StFloat> C(A);
168
169  cout << "C=" << C;
170
171  C+=C;
172  cout << "C+=C =>" << C << endl;
173
174  A*B;
175  cout << "A*B:" << (A*B) << endl;
176
177  cout << "B*A:" << (B*A) << endl;
178
179  unsigned int ierr;
180  cout << "B.inverse(ierr)" << B.inverse(ierr) << endl;
181
182  cout << "C=" << C << endl;
183  cout << "1st row of C" << endl;
184  cout << C.sub(1,1,1,3) << endl;
185
186
187 #ifdef ST_NO_TEMPLATE_DEF_ARGS
188  StMatrix<double> TT;
189 #else
190  StMatrix<> TT;
191 #endif
192  TT = A.apply(hold1);
193  cout << "square all elements in B:" << B << endl;
194 #endif
195  return(0);
196 }
197
198
Definition: T.h:18