1 #define ENABLE_TEMPORARIES
23 #ifdef TEST_ALL_MATRIX_SIZES
27 #define NITER 1 // number of iterations
30 #define NLOOP_MIN 100;
35 #include "CLHEP/Matrix/SymMatrix.h"
36 #include "CLHEP/Matrix/Matrix.h"
37 #include "CLHEP/Matrix/Vector.h"
59 #define NLISTSIZE 64 // size of matrix/vector lists
80 template<
unsigned int ND1,
unsigned int ND2 >
99 std::cout <<
"************************************************\n";
100 std::cout <<
" SMatrix operations test " << first <<
" x " << second << std::endl;
101 std::cout <<
"************************************************\n";
104 double t_veq, t_meq, t_vad, t_mad, t_dot, t_mv, t_gmv, t_mm, t_prd, t_inv, t_vsc, t_msc, t_ama, t_tra;
105 double totTime1, totTime2;
117 for (
int k = 0; k <
npass; k++) {
140 std::cout <<
"pass " << k << std::endl;
142 std::cout <<
" A = " << A[0] << std::endl;
143 std::cout <<
" B = " << B[0] << std::endl;
144 std::cout <<
" C = " << C[0] << std::endl;
145 std::cout <<
" D = " << D[0] << std::endl;
146 std::cout <<
" v = " << v[0] << std::endl;
147 std::cout <<
" p = " << p[0] << std::endl;
179 std::cout <<
" C6 = " << C5 << std::endl;
180 std::cout <<
" v5 = " << v5 << std::endl;
197 std::cout <<
"Total Time = " << totTime1 <<
" (s) " <<
" cpu " << totTime2 <<
" (s) " << std::endl;
198 std::cerr <<
"SMatrix: r1[0] = " << r1[0] <<
" r2[0] = " << r2[0] << std::endl;
199 std::cerr <<
"SMatrix: r1[N] = " << r1[NLIST-1] <<
" r2[N] = " << r2[NLIST-1] << std::endl;
200 std::cerr <<
"sum of results = " << gResultSum << std::endl;
208 template<
unsigned int ND1,
unsigned int ND2>
223 std::cout <<
"************************************************\n";
224 std::cout <<
" SMatrixSym operations test " << first <<
" x " << first << std::endl;
225 std::cout <<
"************************************************\n";
228 double t_meq, t_mad, t_mv, t_gmv, t_mm, t_prd, t_inv, t_msc, t_ama = 0;
229 double totTime1, totTime2;
238 for (
int k = 0; k <
npass; k++) {
258 std::cout <<
"pass " << k << std::endl;
260 std::cout <<
" A = " << A[0] << std::endl;
261 std::cout <<
" B = " << B[0] << std::endl;
262 std::cout <<
" C = " << C[0] << std::endl;
263 std::cout <<
" v = " << v[0] << std::endl;
285 std::cout <<
"output matrices" << std::endl;
287 std::cout <<
" C1 = " << C1 << std::endl;
288 std::cout <<
" C3 = " << C3 << std::endl;
289 std::cout <<
" C4 = " << C4 << std::endl;
290 std::cout <<
" C5 = " << C5 << std::endl;
304 std::cout <<
"Total Time = " << totTime1 <<
" (s) - cpu " << totTime2 <<
" (s) " << std::endl;
305 std::cerr <<
"SMatrixSym: r1[0] = " << r1[0] << std::endl;
306 std::cerr <<
"SMatrixSym: r1[N] = " << r1[NLIST-1] << std::endl;
307 std::cerr <<
"sum of results = " << gResultSum << std::endl;
317 template<
unsigned int ND1,
unsigned int ND2>
335 std::cout <<
"************************************************\n";
336 std::cout <<
" TMatrix operations test " << first <<
" x " << second << std::endl;
337 std::cout <<
"************************************************\n";
339 double t_veq, t_meq, t_vad, t_mad, t_dot, t_mv, t_gmv, t_mm, t_prd, t_inv, t_vsc, t_msc, t_ama, t_tra = 0;
340 double totTime1, totTime2;
347 for (
int k = 0; k <
npass; k++) {
372 std::cout <<
"pass " << k << std::endl;
374 A.Print(); B.Print(); C.Print(); D.Print(); v.Print(); p.Print();
382 MnVector v2(ND1);
testGMV_T(A,v,v1,t_gmv,v2);
384 MnMatrix C0(ND1,ND1);
testMM_T(A,B,C,t_mm,C0);
386 MnMatrix C1(ND1,ND1);
testATBA_T(B,C0,t_ama,C1);
388 MnMatrix C2(ND1,ND1);
testInv_T(C1,t_inv,C2);
390 MnVector v3(ND1);
testVeq(v,t_veq,v3);
391 MnVector v4(ND1);
testVad_T(v2,v3,t_vad,v4);
393 MnMatrix C3(ND1,ND1);
testMeq(C,t_meq,C3);
394 MnMatrix C4(ND1,ND1);
testMad_T(C2,C3,t_mad,C4);
398 MnMatrix C6(ND1,ND1);
testMT_T(C5,t_tra,C6);
421 std::cout <<
"Total Time = " << totTime1 <<
" (s) - cpu " << totTime2 <<
" (s) " << std::endl;
422 std::cerr <<
"TMatrix: r1 = " << r1 <<
" r2 = " << r2 << std::endl;
433 template<
unsigned int ND1,
unsigned int ND2>
450 std::cout <<
"************************************************\n";
451 std::cout <<
" TMatrixSym operations test " << first <<
" x " << first << std::endl;
452 std::cout <<
"************************************************\n";
455 double t_meq, t_mad, t_mv, t_gmv, t_mm, t_prd, t_inv, t_msc, t_ama = 0;
456 double totTime1, totTime2;
463 for (
int k = 0; k <
npass; k++) {
486 std::cout <<
"pass " << k << std::endl;
488 A.Print(); B.Print(); C.Print(); v.Print();
499 MnSymMatrix C3(
N);
testMeq(C2,t_meq,C3);
506 std::cout <<
"output matrices" << std::endl;
508 C1.Print(); C3.Print(); C4.Print(); C5.Print();
520 std::cout <<
"Total Time = " << totTime1 <<
" (s) - cpu " << totTime2 <<
" (s) " << std::endl;
521 std::cerr <<
"TMatrixSym: r1 = " << r1 << std::endl;
527 #endif // end TEST_SYM
531 template<
unsigned int ND1,
unsigned int ND2>
532 int test_hepmatrix_op() {
537 typedef HepMatrix MnMatrix;
538 typedef HepVector MnVector;
546 std::cout <<
"************************************************\n";
547 std::cout <<
" HepMatrix operations test " << first <<
" x " << second << std::endl;
548 std::cout <<
"************************************************\n";
550 double t_veq, t_meq, t_vad, t_mad, t_dot, t_mv, t_gmv, t_mm, t_prd, t_inv, t_vsc, t_msc, t_ama, t_tra = 0;
553 double totTime1, totTime2;
559 for (
int k = 0; k <
npass; k++) {
583 std::cout <<
"pass " << k << std::endl;
585 std::cout <<
" A = " <<
A << std::endl;
586 std::cout <<
" B = " <<
B << std::endl;
587 std::cout <<
" C = " <<
C << std::endl;
588 std::cout <<
" D = " << D << std::endl;
589 std::cout <<
" v = " <<
v << std::endl;
590 std::cout <<
" p = " << p << std::endl;
601 MnMatrix C2(ND1,ND1);
testInv_C(C1,t_inv,C2);
603 MnVector v3(ND1);
testVeq(
v,t_veq,v3);
604 MnVector v4(ND1);
testVad(v2,v3,t_vad,v4);
605 MnVector v5(ND1);
testVscale(v4,2.0,t_vsc,v5);
607 MnMatrix C4(ND1,ND1);
testMad_C(C2,C3,t_mad,C4);
611 MnMatrix C6(ND1,ND1);
testMT_C(C5,t_tra,C6);
619 std::cout <<
" C6 = " << C6 << std::endl;
620 std::cout <<
" v5 = " << v5 << std::endl;
633 std::cout <<
"Total Time = " << totTime1 <<
" (s) - cpu " << totTime2 <<
" (s) " << std::endl;
634 std::cerr <<
"HepMatrix: r1 = " << r1 <<
" r2 = " << r2 << std::endl;
641 template<
unsigned int ND1,
unsigned int ND2>
642 int test_hepmatrix_sym_op() {
647 typedef HepSymMatrix MnSymMatrix;
648 typedef HepMatrix MnMatrix;
649 typedef HepVector MnVector;
656 std::cout <<
"************************************************\n";
657 std::cout <<
" HepMatrixSym operations test " << first <<
" x " << first << std::endl;
658 std::cout <<
"************************************************\n";
661 double t_meq, t_mad, t_mv, t_gmv, t_mm, t_prd, t_inv, t_msc, t_ama = 0;
663 double totTime1, totTime2;
669 for (
int k = 0; k <
npass; k++) {
691 std::cout <<
"pass " << k << std::endl;
710 std::cout <<
"output matrices" << std::endl;
722 std::cout <<
"Total Time = " << totTime1 <<
" (s) - cpu " << totTime2 <<
" (s) " << std::endl;
723 std::cerr <<
"HepMatrixSym: r1 = " << r1 << std::endl;
732 #if defined(HAVE_CLHEP) && defined (TEST_SYM)
736 TEST_TYPE=0; test_smatrix_op<N,N>(); \
737 TEST_TYPE=1; test_tmatrix_op<N,N>(); \
738 TEST_TYPE=2; test_hepmatrix_op<N,N>(); \
739 TEST_TYPE=3; test_smatrix_sym_op<N,N>(); \
740 TEST_TYPE=4; test_tmatrix_sym_op<N,N>(); \
741 TEST_TYPE=5; test_hepmatrix_sym_op<N,N>();
742 #elif !defined(HAVE_CLHEP) && !defined(USE_TMATRIX) && defined (TEST_SYM)
746 TEST_TYPE=0; test_smatrix_op<N,N>(); \
747 TEST_TYPE=1; test_smatrix_sym_op<N,N>();
748 #elif !defined(HAVE_CLHEP) && defined(USE_TMATRIX) && defined (TEST_SYM)
752 TEST_TYPE=0; test_smatrix_op<N,N>(); \
753 TEST_TYPE=1; test_tmatrix_op<N,N>(); \
754 TEST_TYPE=2; test_smatrix_sym_op<N,N>(); \
755 TEST_TYPE=3; test_tmatrix_sym_op<N,N>();
756 #elif defined(HAVE_CLHEP) && !defined (TEST_SYM)
760 TEST_TYPE=0; test_smatrix_op<N,N>(); \
761 TEST_TYPE=1; test_tmatrix_op<N,N>(); \
762 TEST_TYPE=2; test_hepmatrix_op<N,N>();
766 TEST_TYPE=0; test_smatrix_op<N,N>(); \
767 TEST_TYPE=1; test_tmatrix_op<N,N>();
775 std::vector< std::map<std::string, TH1D *> > testTimeResults(
NTYPES);
776 std::vector< std::string > typeNames(
NTYPES);
778 void ROOT::Math::test::reportTime(std::string s,
double time) {
780 std::map<std::string, TH1D * > & result = testTimeResults[
TEST_TYPE];
782 std::map<std::string, TH1D * >::iterator pos = result.find(s);
784 if ( pos != result.end() ) {
790 std::string name = typeNames[
TEST_TYPE] +
"_" + s;
791 h =
new TProfile(name.c_str(), name.c_str(),100,0.5,100.5);
796 if (s.find(
"dot") != std::string::npos ||
797 s.find(
"V=V") != std::string::npos ||
798 s.find(
"V+V") != std::string::npos ) scale = 10;
799 h->
Fill(
double(MATRIX_SIZE),time/
double(NLOOP*
NITER*scale) );
811 std::cout <<
" making vector/matrix lists of size = " << NLIST << std::endl;
825 int main(
int argc ,
char *argv[] ) {
828 std::string fname =
"testOperations";
830 std::string platf(argv[1]);
831 fname = fname +
"_" + platf;
833 fname = fname +
".root";
839 typeNames[0] =
"SMatrix";
840 typeNames[1] =
"TMatrix";
841 #if !defined(HAVE_CLHEP) && defined (TEST_SYM)
842 typeNames[2] =
"SMatrix_sym";
843 typeNames[3] =
"TMatrix_sym";
844 #elif defined(HAVE_CLHEP) && defined (TEST_SYM)
845 typeNames[2] =
"HepMatrix";
846 typeNames[3] =
"SMatrix_sym";
847 typeNames[4] =
"TMatrix_sym";
848 typeNames[5] =
"HepMatrix_sym";
849 #elif defined(HAVE_CLHEP) && !defined (TEST_SYM)
850 typeNames[2] =
"HepMatrix";
855 #ifndef TEST_ALL_MATRIX_SIZES
void testATBA_C2(const A &a, const B &b, double &time, C &result)
int test_tmatrix_sym_op()
void testVeq(const V &v, double &time, V &result)
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
void testATBA_T(const A &a, const B &b, double &time, C &result)
Random number generator class based on M.
Double_t RealTime()
Stop the stopwatch (if it is running) and return the realtime (in seconds) passed between the start a...
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
void testMM(const A &a, const B &b, const C &c, double &time, C &result)
void testMV_T(const M &mat, const V &v, double &time, V &result)
A ROOT file is a suite of consecutive data records (TKey instances) with a well defined format...
void testVscale(const V &v1, double a, double &time, V &result)
void testATBA_T2(const A &a, const B &b, double &time, C &result)
void fillRandomVec(TRandom &r, V &v, unsigned int len, unsigned int start=0, double offset=1)
void fillRandomSym(TRandom &r, M &m, unsigned int first, unsigned int start=0, double offset=1)
Double_t CpuTime()
Stop the stopwatch (if it is running) and return the cputime (in seconds) passed between the start an...
void testMscale(const M &m1, double a, double &time, M &result)
double testDot_S(const V &v1, const V &v2, double &time)
void Stop()
Stop the stopwatch.
SMatrix: a generic fixed size D1 x D2 Matrix class.
void testMM_T(const A &a, const B &b, const C &c, double &time, C &result)
void testInv_T(const M &m, double &time, M &result)
void testMeq(const M &m, double &time, M &result)
void testMad(const M &m1, const M &m2, double &time, M &result)
double testInnerProd_C(const M &a, const V &v, double &time)
void testInv_S(const M &m, double &time, M &result)
void testMscale_T(const M &m1, double a, double &time, M &result)
virtual Int_t Write(const char *name=0, Int_t opt=0, Int_t bufsiz=0)
Write memory objects to this file.
VECTOR_NAMESPACE::double_v double_v
unsigned int r1[N_CITIES]
void testMT_S(const A &a, double &time, C &result)
void testMM_C(const A &a, const B &b, const C &c, double &time, C &result)
double testInnerProd_S(const M &a, const V &v, double &time)
R__EXTERN Int_t gMatrixCheck
1-D histogram with a double per channel (see TH1 documentation)}
double testDot_T(const V &v1, const V &v2, double &time)
void testMeq_C(const M &m, double &time, M &result)
void testATBA_C(const A &a, const B &b, double &time, C &result)
void fillRandomMat(TRandom &r, M &m, unsigned int first, unsigned int second, unsigned int start=0, double offset=1)
int test_smatrix_sym_op()
void testInv_C(const M &a, double &time, M &result)
void testMT_C(const A &a, double &time, C &result)
void testInvChol_S(const M *m, double &time, M *result)
void testGMV_T(const M &mat, const V &v1, const V &v2, double &time, V &result)
void testATBA_S(const A &a, const B &b, double &time, C &result)
void testGMV(const M &mat, const V &v1, const V &v2, double &time, V &result)
void testVad(const V &v1, const V &v2, double &time, V &result)
void testInvFast_S(const M *m, double &time, M *result)
void testVscale_T(const V &v1, double a, double &time, V &result)
double testInnerProd_T(const M &a, const V &v, double &time)
void testMad_C(const M &m1, const M &m2, double &time, M &result)
void testMT_T(const A &a, double &time, C &result)
void testMad_T(const M &m1, const M &m2, double &time, M &result)
double testDot_C(const V &v1, const V &v2, double &time)
void testMV(const M &mat, const V &v, double &time, V &result)
void testVad_T(const V &v1, const V &v2, double &time, V &result)
void testMscale_C(const M &m1, double a, double &time, M &result)
void testATBA_S2(const A &a, const B &b, double &time, C &result)
unsigned int r2[N_CITIES]
virtual void Close(Option_t *option="")
Close a file.
SVector: a generic fixed size Vector class.
int main(int argc, char *argv[])