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
5bc83481
Commit
5bc83481
authored
1 year ago
by
Wuttke, Joachim
Browse files
Options
Downloads
Patches
Plain Diff
convolve: throw -> assert
parent
a83fb71b
No related branches found
No related tags found
1 merge request
!2019
in convolution context, throw -> assert
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Device/Resolution/ConvolutionDetectorResolution.cpp
+10
-32
10 additions, 32 deletions
Device/Resolution/ConvolutionDetectorResolution.cpp
with
10 additions
and
32 deletions
Device/Resolution/ConvolutionDetectorResolution.cpp
+
10
−
32
View file @
5bc83481
...
@@ -17,7 +17,6 @@
...
@@ -17,7 +17,6 @@
#include
"Base/Axis/Scale.h"
#include
"Base/Axis/Scale.h"
#include
"Base/Util/Assert.h"
#include
"Base/Util/Assert.h"
#include
"Device/Resolution/Convolve.h"
#include
"Device/Resolution/Convolve.h"
#include
<stdexcept>
ConvolutionDetectorResolution
::
ConvolutionDetectorResolution
(
cumulative_DF_1d
res_function_1d
)
ConvolutionDetectorResolution
::
ConvolutionDetectorResolution
(
cumulative_DF_1d
res_function_1d
)
:
m_rank
(
1
)
:
m_rank
(
1
)
...
@@ -56,23 +55,13 @@ std::vector<const INode*> ConvolutionDetectorResolution::nodeChildren() const
...
@@ -56,23 +55,13 @@ std::vector<const INode*> ConvolutionDetectorResolution::nodeChildren() const
void
ConvolutionDetectorResolution
::
applyDetectorResolution
(
Datafield
*
intensity_map
)
const
void
ConvolutionDetectorResolution
::
applyDetectorResolution
(
Datafield
*
intensity_map
)
const
{
{
if
(
intensity_map
->
rank
()
!=
m_rank
)
{
ASSERT
(
intensity_map
->
rank
()
==
m_rank
);
throw
std
::
runtime_error
(
if
(
m_rank
==
1
)
"ConvolutionDetectorResolution::applyDetectorResolution -> Error! "
"Intensity map must have same dimension as detector resolution function."
);
}
switch
(
m_rank
)
{
case
1
:
apply1dConvolution
(
intensity_map
);
apply1dConvolution
(
intensity_map
);
break
;
else
if
(
m_rank
==
2
)
case
2
:
apply2dConvolution
(
intensity_map
);
apply2dConvolution
(
intensity_map
);
break
;
else
default:
ASSERT_NEVER
;
throw
std
::
runtime_error
(
"ConvolutionDetectorResolution::applyDetectorResolution -> Error! "
"Class ConvolutionDetectorResolution must be initialized with dimension 1 or 2."
);
}
}
}
void
ConvolutionDetectorResolution
::
setResolutionFunction
(
const
IResolutionFunction2D
&
resFunc
)
void
ConvolutionDetectorResolution
::
setResolutionFunction
(
const
IResolutionFunction2D
&
resFunc
)
...
@@ -83,10 +72,8 @@ void ConvolutionDetectorResolution::setResolutionFunction(const IResolutionFunct
...
@@ -83,10 +72,8 @@ void ConvolutionDetectorResolution::setResolutionFunction(const IResolutionFunct
void
ConvolutionDetectorResolution
::
apply1dConvolution
(
Datafield
*
intensity_map
)
const
void
ConvolutionDetectorResolution
::
apply1dConvolution
(
Datafield
*
intensity_map
)
const
{
{
ASSERT
(
m_res_function_1d
==
nullptr
);
ASSERT
(
m_res_function_1d
==
nullptr
);
if
(
intensity_map
->
rank
()
!=
1
)
ASSERT
(
intensity_map
->
rank
()
==
1
);
throw
std
::
runtime_error
(
"ConvolutionDetectorResolution::apply1dConvolution -> Error! "
"Number of axes for intensity map does not correspond to the dimension of the map."
);
const
Scale
&
axis
=
intensity_map
->
axis
(
0
);
const
Scale
&
axis
=
intensity_map
->
axis
(
0
);
// Construct source vector from original intensity map
// Construct source vector from original intensity map
std
::
vector
<
double
>
source_vector
=
intensity_map
->
flatVector
();
std
::
vector
<
double
>
source_vector
=
intensity_map
->
flatVector
();
...
@@ -94,10 +81,7 @@ void ConvolutionDetectorResolution::apply1dConvolution(Datafield* intensity_map)
...
@@ -94,10 +81,7 @@ void ConvolutionDetectorResolution::apply1dConvolution(Datafield* intensity_map)
if
(
data_size
<
2
)
if
(
data_size
<
2
)
return
;
// No convolution for sets of zero or one element
return
;
// No convolution for sets of zero or one element
// Construct kernel vector from resolution function
// Construct kernel vector from resolution function
if
(
axis
.
size
()
!=
data_size
)
ASSERT
(
axis
.
size
()
==
data_size
);
throw
std
::
runtime_error
(
"ConvolutionDetectorResolution::apply1dConvolution -> Error! "
"Size of axis for intensity map does not correspond to size of data in the map."
);
double
step_size
=
double
step_size
=
std
::
abs
(
axis
.
binCenter
(
0
)
-
axis
.
binCenter
(
axis
.
size
()
-
1
))
/
(
data_size
-
1
);
std
::
abs
(
axis
.
binCenter
(
0
)
-
axis
.
binCenter
(
axis
.
size
()
-
1
))
/
(
data_size
-
1
);
double
mid_value
=
axis
.
binCenter
(
axis
.
size
()
/
2
);
// because Convolve expects zero at midpoint
double
mid_value
=
axis
.
binCenter
(
axis
.
size
()
/
2
);
// because Convolve expects zero at midpoint
...
@@ -117,10 +101,7 @@ void ConvolutionDetectorResolution::apply1dConvolution(Datafield* intensity_map)
...
@@ -117,10 +101,7 @@ void ConvolutionDetectorResolution::apply1dConvolution(Datafield* intensity_map)
void
ConvolutionDetectorResolution
::
apply2dConvolution
(
Datafield
*
intensity_map
)
const
void
ConvolutionDetectorResolution
::
apply2dConvolution
(
Datafield
*
intensity_map
)
const
{
{
ASSERT
(
m_res_function_2d
);
ASSERT
(
m_res_function_2d
);
if
(
intensity_map
->
rank
()
!=
2
)
ASSERT
(
intensity_map
->
rank
()
!=
2
);
throw
std
::
runtime_error
(
"ConvolutionDetectorResolution::apply2dConvolution -> Error! "
"Number of axes for intensity map does not correspond to the dimension of the map."
);
const
Scale
&
axis_1
=
intensity_map
->
axis
(
0
);
const
Scale
&
axis_1
=
intensity_map
->
axis
(
0
);
const
Scale
&
axis_2
=
intensity_map
->
axis
(
1
);
const
Scale
&
axis_2
=
intensity_map
->
axis
(
1
);
size_t
axis_size_1
=
axis_1
.
size
();
size_t
axis_size_1
=
axis_1
.
size
();
...
@@ -131,10 +112,7 @@ void ConvolutionDetectorResolution::apply2dConvolution(Datafield* intensity_map)
...
@@ -131,10 +112,7 @@ void ConvolutionDetectorResolution::apply2dConvolution(Datafield* intensity_map)
std
::
vector
<
double
>
raw_source_vector
=
intensity_map
->
flatVector
();
std
::
vector
<
double
>
raw_source_vector
=
intensity_map
->
flatVector
();
std
::
vector
<
std
::
vector
<
double
>>
source
;
std
::
vector
<
std
::
vector
<
double
>>
source
;
size_t
raw_data_size
=
raw_source_vector
.
size
();
size_t
raw_data_size
=
raw_source_vector
.
size
();
if
(
raw_data_size
!=
axis_size_1
*
axis_size_2
)
ASSERT
(
raw_data_size
==
axis_size_1
*
axis_size_2
);
throw
std
::
runtime_error
(
"ConvolutionDetectorResolution::apply2dConvolution -> Error! "
"Intensity map data size does not match the product of its axes' sizes"
);
for
(
auto
it
=
raw_source_vector
.
begin
();
it
!=
raw_source_vector
.
end
();
it
+=
axis_size_2
)
{
for
(
auto
it
=
raw_source_vector
.
begin
();
it
!=
raw_source_vector
.
end
();
it
+=
axis_size_2
)
{
std
::
vector
<
double
>
row_vector
(
it
,
it
+
axis_size_2
);
std
::
vector
<
double
>
row_vector
(
it
,
it
+
axis_size_2
);
source
.
push_back
(
row_vector
);
source
.
push_back
(
row_vector
);
...
...
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