Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:28:40

0001 #ifndef RecoTracker_PixelTrackFitting_test_test_common_h
0002 #define RecoTracker_PixelTrackFitting_test_test_common_h
0003 
0004 #include <algorithm>
0005 #include <cassert>
0006 #include <random>
0007 
0008 template <class C>
0009 __host__ __device__ void printIt(C* m) {
0010 #ifdef TEST_DEBUG
0011   printf("\nMatrix %dx%d\n", (int)m->rows(), (int)m->cols());
0012   for (u_int r = 0; r < m->rows(); ++r) {
0013     for (u_int c = 0; c < m->cols(); ++c) {
0014       printf("Matrix(%d,%d) = %f\n", r, c, (*m)(r, c));
0015     }
0016   }
0017 #endif
0018 }
0019 
0020 template <class C1, class C2>
0021 bool isEqualFuzzy(C1 a, C2 b, double epsilon = 1e-6) {
0022   for (unsigned int i = 0; i < a.rows(); ++i) {
0023     for (unsigned int j = 0; j < a.cols(); ++j) {
0024       assert(std::abs(a(i, j) - b(i, j)) < std::min(std::abs(a(i, j)), std::abs(b(i, j))) * epsilon);
0025     }
0026   }
0027   return true;
0028 }
0029 
0030 bool isEqualFuzzy(double a, double b, double epsilon = 1e-6) {
0031   return std::abs(a - b) < std::min(std::abs(a), std::abs(b)) * epsilon;
0032 }
0033 
0034 template <typename T>
0035 void fillMatrix(T& t) {
0036   std::random_device rd;
0037   std::mt19937 gen(rd());
0038   std::uniform_real_distribution<> dis(0.0, 2.0);
0039   for (int row = 0; row < t.rows(); ++row) {
0040     for (int col = 0; col < t.cols(); ++col) {
0041       t(row, col) = dis(gen);
0042     }
0043   }
0044   return;
0045 }
0046 
0047 #endif