Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Actually fail if the test result is wrong
  • Loading branch information
xvallspl committed Jul 13, 2017
commit 8cbe96f3f7c6186a550656b8a339088aa2686f6d
32 changes: 23 additions & 9 deletions math/mathcore/test/fit/testBinnedFitExecPolicy.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
#include "TError.h"
#include "Math/MinimizerOptions.h"

int compareResult(double v1, double v2, std::string s = "", double tol = 0.01)
bool compareResult(double v1, double v2, std::string s = "", double tol = 0.01)
{
// compare v1 with reference v2
// // give 1% tolerance
if (std::abs(v1 - v2) < tol * std::abs(v2)) return 0;
if (std::abs(v1 - v2) < tol * std::abs(v2)) return true;
std::cerr << s << " Failed comparison of fit results \t chi2 = " << v1 << " it should be = " << v2 << std::endl;
return -1;
return false;
}

template <class T>
Expand Down Expand Up @@ -47,6 +47,7 @@ int main()
return -1;
}

int correctness = 0;
#ifdef R__USE_IMT
std::cout << "\n **FIT: Multithreaded Chi2 **\n\n";
f->SetParameters(1, 1000, 7.5, 1.5);
Expand All @@ -55,7 +56,9 @@ int main()
Error("testBinnedFitExecPolicy", "Multithreaded Chi2 Fit failed!");
return -1;
} else {
compareResult(r2->MinFcnValue(), r1->MinFcnValue(), "Mutithreaded Chi2 Fit: ");
correctness = compareResult(r2->MinFcnValue(), r1->MinFcnValue(), "Mutithreaded Chi2 Fit: ");
if(!correctness)
return 1;
}

std::cout << "\n **FIT: Multithreaded Binned Likelihood **\n\n";
Expand All @@ -65,7 +68,9 @@ int main()
Error("testBinnedFitExecPolicy", "Multithreaded Binned Likelihood Fit failed!");
return -1;
} else {
compareResult(rL2->MinFcnValue(), rL1->MinFcnValue(), "Mutithreaded Binned Likelihood Fit (PoissonLogL): ");
correctness = compareResult(rL2->MinFcnValue(), rL1->MinFcnValue(), "Mutithreaded Binned Likelihood Fit (PoissonLogL): ");
if(!correctness)
return 2;
}
#endif

Expand All @@ -79,7 +84,9 @@ int main()
Error("testBinnedFitExecPolicy", "Vectorized Chi2 Fit failed!");
return -1;
} else {
compareResult(r3->MinFcnValue(), r1->MinFcnValue(), "Vectorized Chi2 Fit: ");
correctness = compareResult(r3->MinFcnValue(), r1->MinFcnValue(), "Vectorized Chi2 Fit: ");
if(!correctness)
return 3;
}

std::cout << "\n **FIT: Vectorized Binned Likelihood **\n\n";
Expand All @@ -89,7 +96,9 @@ int main()
Error("testBinnedFitExecPolicy", "Vectorized Binned Likelihood Fit failed!");
return -1;
} else {
compareResult(rL3->MinFcnValue(), rL1->MinFcnValue(), "Vectorized Binned Likelihood Fit (PoissonLogL) Fit: ");
correctness = compareResult(rL3->MinFcnValue(), rL1->MinFcnValue(), "Vectorized Binned Likelihood Fit (PoissonLogL) Fit: ");
if(!correctness)
return 4;
}

#ifdef R__USE_IMT
Expand All @@ -99,7 +108,9 @@ int main()
Error("testBinnedFitExecPolicy", "Mutithreaded vectorized Chi2 Fit failed!");
return -1;
} else {
compareResult(r4->MinFcnValue(), r1->MinFcnValue(), "Mutithreaded vectorized Chi2 Fit: ");
correctness = compareResult(r4->MinFcnValue(), r1->MinFcnValue(), "Mutithreaded vectorized Chi2 Fit: ");
if(!correctness)
return 5;
}

std::cout << "\n **FIT: Multithreaded and vectorized Binned Likelihood **\n\n";
Expand All @@ -109,10 +120,13 @@ int main()
Error("testBinnedFitExecPolicy", "Multithreaded Binned Likelihood vectorized Fit failed!");
return -1;
} else {
compareResult(rL4->MinFcnValue(), rL1->MinFcnValue(),
correctness = compareResult(rL4->MinFcnValue(), rL1->MinFcnValue(),
"Mutithreaded vectorized Binned Likelihood Fit (PoissonLogL) Fit: ");
if(!correctness)
return 6;
}

#endif
#endif
return 0;
}
53 changes: 30 additions & 23 deletions math/mathcore/test/fit/testLogLExecPolicy.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

constexpr int paramSize = 6;

int compareResult(double v1, double v2, std::string s = "", double tol = 0.01)
bool compareResult(double v1, double v2, std::string s = "", double tol = 0.01)
{
// compare v1 with reference v2
// // give 1% tolerance
if (std::abs(v1 - v2) < tol * std::abs(v2)) return 0;
if (std::abs(v1 - v2) < tol * std::abs(v2)) return true;
std::cerr << s << " Failed comparison of fit results \t logl = " << v1 << " it should be = " << v2 << std::endl;
return -1;
return false;
}

//Functor for a Higgs Fit normalized with analytical integral
Expand Down Expand Up @@ -220,6 +220,7 @@ class TestVector {
int main()
{

bool correctness;
TestVector test(200000);

//Sequential
Expand All @@ -231,15 +232,17 @@ int main()
auto seq = test.GetFitter().Result().MinFcnValue();
#endif

// #ifdef R__USE_IMT
// //Multithreaded
// if (!test.testMTFit()) {
// Error("testLogLExecPolicy", "Multithreaded Fit failed!");
// return -1;
// }
// auto seqMT = test.GetFitter().Result().MinFcnValue();
// compareResult(seqMT, seq, "Mutithreaded LogL Fit: ");
// #endif
#ifdef R__USE_IMT
//Multithreaded
if (!test.testMTFit()) {
Error("testLogLExecPolicy", "Multithreaded Fit failed!");
return -1;
}
auto seqMT = test.GetFitter().Result().MinFcnValue();
correctness = compareResult(seqMT, seq, "Mutithreaded LogL Fit: ");
if(!correctness)
return 1;
#endif

#ifdef R__HAS_VECCORE
//Vectorized
Expand All @@ -248,17 +251,21 @@ int main()
return -1;
}
auto vec = test.GetFitter().Result().MinFcnValue();
compareResult(vec, seq, "vectorized LogL Fit: ");

// #ifdef R__USE_IMT
// //Multithreaded and vectorized
// if (!test.testMTFitVec()) {
// Error("testLogLExecPolicy", "Multithreaded + vectorized Fit failed!");
// return -1;
// }
// auto vecMT = test.GetFitter().Result().MinFcnValue();
// compareResult(vecMT, seq, "Mutithreaded + vectorized LogL Fit: ");
// #endif
correctness = compareResult(vec, seq, "vectorized LogL Fit: ");
if(!correctness)
return 2;

#ifdef R__USE_IMT
//Multithreaded and vectorized
if (!test.testMTFitVec()) {
Error("testLogLExecPolicy", "Multithreaded + vectorized Fit failed!");
return -1;
}
auto vecMT = test.GetFitter().Result().MinFcnValue();
correctness = compareResult(vecMT, seq, "Mutithreaded + vectorized LogL Fit: ");
if(!correctness)
return 3;
#endif
#endif

// //Multiprocessed
Expand Down