Skip to content
Snippets Groups Projects
Commit c2a67a84 authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

meanRelativeDifference: throw if data fields are empty or contain only zeroes

parent ab87f87b
No related branches found
No related tags found
1 merge request!1223meanRelativeDifference now detects empty data fields
......@@ -50,13 +50,29 @@ Datafield* DiffUtil::relativeDifferenceField(const Datafield& dat, const Datafie
double DiffUtil::meanRelativeDifference(const SimulationResult& dat, const SimulationResult& ref)
{
if (dat.size() != ref.size())
throw std::runtime_error("Error in DiffUtil::meanRelativeDifference: "
"different number of elements");
throw std::runtime_error("Invalid call to meanRelativeDifference: "
"different number of elements in dat and ref datasets");
if (dat.empty())
return 0.0;
double sum_of_diff = 0.0;
for (size_t i = 0; i < dat.size(); ++i)
throw std::runtime_error("Invalid call to meanRelativeDifference: "
"empty dat and ref datasets");
double sum_of_diff = 0.;
double sum_of_fdat = 0.;
double sum_of_fref = 0.;
for (size_t i = 0; i < dat.size(); ++i) {
sum_of_diff += Numeric::relativeDifference(dat[i], ref[i]);
sum_of_fdat += fabs(dat[i]);
sum_of_fref += fabs(ref[i]);
}
if (sum_of_fdat == 0 && sum_of_fref)
throw std::runtime_error("Invalid call to meanRelativeDifference: "
"dat and ref only contain zeroes");
if (sum_of_fdat == 0)
throw std::runtime_error("Invalid call to meanRelativeDifference: "
"dat only contains zeroes");
if (sum_of_fref == 0)
throw std::runtime_error("Invalid call to meanRelativeDifference: "
"ref only contains zeroes");
return sum_of_diff / dat.size();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment