#ifdef USE_VC //using namespace Vc; #include "Vc/Vc" #endif #include #include "Math/SVector.h" #include "Math/SMatrix.h" #include "TMatrixD.h" #include "TVectorD.h" #include "TRandom3.h" #include "matrix_util.h" #define TEST_SYM //#define HAVE_CLHEP #ifdef HAVE_CLHEP #include "CLHEP/Matrix/SymMatrix.h" #include "CLHEP/Matrix/Matrix.h" #include "CLHEP/Matrix/Vector.h" #endif // #include "SealUtil/SealTimer.h" // #include "SealUtil/SealHRRTChrono.h" // #include "SealUtil/TimingReport.h" #include #include #include double cpuTime() { struct tms usage; times(&usage); return ((double) usage.tms_utime) / sysconf(_SC_CLK_TCK); } double clockTime() { struct tms usage; return ((double) times(&usage)) / sysconf(_SC_CLK_TCK); } #ifndef NDIM1 #define NDIM1 5 #endif #ifndef NDIM2 #define NDIM2 5 #endif #define NITER 1 // number of iterations #define NLOOP 500000 // number of time the test is repeted #define NLISTSIZE 64 // size of matrix/vector lists using namespace ROOT::Math; #include "TestTimer.h" #ifdef USE_VC typedef Vc::double_v Stype; #else typedef double Stype; #endif #ifdef USE_VC const int NLIST = NLISTSIZE / Vc::double_v::Size; #else const int NLIST = NLISTSIZE; #endif int test_smatrix_kalman() { // need to write explicitly the dimensions typedef SMatrix MnMatrixNN; typedef SMatrix MnMatrixMM; typedef SMatrix MnMatrixNM; typedef SMatrix MnMatrixMN; typedef SMatrix MnSymMatrixNN; typedef SMatrix MnSymMatrixMM; typedef SVector MnVectorN; typedef SVector MnVectorM; int first = NDIM1; //Can change the size of the matrices int second = NDIM2; std::cout << "************************************************\n"; std::cout << " SMatrix kalman test " << first << " x " << second << std::endl; std::cout << "************************************************\n"; int npass = NITER; TRandom3 r(111); Stype x2sum = 0.0; Stype c2sum = 0.0; for (int ipass = 0; ipass < npass; ipass++) { MnMatrixNM H[NLIST]; MnMatrixMN K0[NLIST]; MnSymMatrixMM Cp[NLIST]; MnSymMatrixNN V[NLIST]; MnVectorN m[NLIST]; MnVectorM xp[NLIST]; // fill matrices with random data for (int j = 0; j < NLIST; j++) fillRandomMat(r,H[j],first,second); for (int j = 0; j < NLIST; j++) fillRandomMat(r,K0[j],second,first); for (int j = 0; j < NLIST; j++) fillRandomSym(r,Cp[j],second); for (int j = 0; j < NLIST; j++) fillRandomSym(r,V[j],first); for (int j = 0; j < NLIST; j++) fillRandomVec(r,m[j],first); for (int j = 0; j < NLIST; j++) fillRandomVec(r,xp[j],second); // MnSymMatrixMM I; // for(int i = 0; i < second; i++) // I(i,i) = 1; #ifdef DEBUG std::cout << "pass " << ipass << std::endl; if (k == 0) { std::cout << " K0 = " << K0[0] << std::endl; std::cout << " H = " << K0[0] << std::endl; std::cout << " Cp = " << Cp[0] << std::endl; std::cout << " V = " << V[0] << std::endl; std::cout << " m = " << m[0] << std::endl; std::cout << " xp = " << xp[0] << std::endl; } #endif { Stype x2 = 0.0,c2 = 0.0; test::Timer t("SMatrix Kalman "); MnVectorM x; MnMatrixMN tmp; MnSymMatrixNN Rinv; MnMatrixMN K; MnSymMatrixMM C; MnVectorN vtmp1; MnVectorN vtmp; for (int l = 0; l < NLOOP; l++) { // loop on the list of matrices for (int k = 0; k < NLIST; k++) { vtmp1 = H[k]*xp[k] -m[k]; //x = xp + K0 * (m- H * xp); x = xp[k] - K0[k] * vtmp1; tmp = Cp[k] * Transpose(H[k]); Rinv = V[k]; Rinv += H[k] * tmp; bool test = Rinv.InvertFast(); if(!test) { std::cout<<"inversion failed" <