Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
BornAgain
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mlz
BornAgain
Commits
c2a67a84
Commit
c2a67a84
authored
2 years ago
by
Wuttke, Joachim
Browse files
Options
Downloads
Patches
Plain Diff
meanRelativeDifference: throw if data fields are empty or contain only zeroes
parent
ab87f87b
No related branches found
No related tags found
1 merge request
!1223
meanRelativeDifference now detects empty data fields
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Device/Histo/DiffUtil.cpp
+21
-5
21 additions, 5 deletions
Device/Histo/DiffUtil.cpp
with
21 additions
and
5 deletions
Device/Histo/DiffUtil.cpp
+
21
−
5
View file @
c2a67a84
...
...
@@ -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
();
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment