IAP GITLAB
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
corsika
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
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Antonio Augusto Alves Junior
corsika
Commits
7bdc076a
Commit
7bdc076a
authored
6 years ago
by
Maximilian Reininghaus
Browse files
Options
Downloads
Patches
Plain Diff
uniform real distribution with units
parent
c12607d1
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Framework/Random/CMakeLists.txt
+1
-0
1 addition, 0 deletions
Framework/Random/CMakeLists.txt
Framework/Random/UniformRealDistribution.h
+32
-0
32 additions, 0 deletions
Framework/Random/UniformRealDistribution.h
Framework/Random/testRandom.cc
+47
-1
47 additions, 1 deletion
Framework/Random/testRandom.cc
with
80 additions
and
1 deletion
Framework/Random/CMakeLists.txt
+
1
−
0
View file @
7bdc076a
...
@@ -7,6 +7,7 @@ set (
...
@@ -7,6 +7,7 @@ set (
set
(
set
(
CORSIKArandom_HEADERS
CORSIKArandom_HEADERS
RNGManager.h
RNGManager.h
UniformRealDistribution.h
)
)
set
(
set
(
...
...
This diff is collapsed.
Click to expand it.
Framework/Random/UniformRealDistribution.h
0 → 100644
+
32
−
0
View file @
7bdc076a
#ifndef _include_random_distributions_h
#define _include_random_distributions_h
#include
<corsika/units/PhysicalUnits.h>
#include
<random>
namespace
corsika
::
random
{
template
<
class
TQuantity
>
class
UniformRealDistribution
{
using
RealType
=
typename
TQuantity
::
value_type
;
std
::
uniform_real_distribution
<
RealType
>
dist
{
RealType
(
0.
),
RealType
(
1.
)};
TQuantity
const
a
,
b
;
public
:
UniformRealDistribution
(
TQuantity
b
)
:
a
{
TQuantity
(
phys
::
units
::
detail
::
magnitude_tag
,
0
)}
,
b
(
b
)
{}
UniformRealDistribution
(
TQuantity
a
,
TQuantity
b
)
:
a
(
a
)
,
b
(
b
)
{}
template
<
class
Generator
>
TQuantity
operator
()(
Generator
&
g
)
{
return
a
+
dist
(
g
)
*
(
b
-
a
);
}
};
}
// namespace corsika::random
#endif
This diff is collapsed.
Click to expand it.
Framework/Random/testRandom.cc
+
47
−
1
View file @
7bdc076a
/**
/**
* (c) Copyright 2018 CORSIKA Project, corsika-project@lists.kit.edu
* (c) Copyright 2018 CORSIKA Project, corsika-project@lists.kit.edu
*
*
...
@@ -14,7 +13,11 @@
...
@@ -14,7 +13,11 @@
#include
<catch2/catch.hpp>
#include
<catch2/catch.hpp>
#include
<corsika/random/RNGManager.h>
#include
<corsika/random/RNGManager.h>
#include
<corsika/random/UniformRealDistribution.h>
#include
<corsika/units/PhysicalUnits.h>
#include
<iostream>
#include
<iostream>
#include
<limits>
#include
<random>
using
namespace
corsika
::
random
;
using
namespace
corsika
::
random
;
...
@@ -37,3 +40,46 @@ SCENARIO("random-number streams can be registered and retrieved") {
...
@@ -37,3 +40,46 @@ SCENARIO("random-number streams can be registered and retrieved") {
}
}
}
}
}
}
TEST_CASE
(
"UniformRealDistribution"
)
{
using
namespace
corsika
::
units
::
si
;
std
::
mt19937
rng
;
corsika
::
random
::
UniformRealDistribution
<
LengthType
>
dist
(
1
_m
,
2
_m
);
SECTION
(
"range"
)
{
corsika
::
random
::
UniformRealDistribution
<
LengthType
>
dist
(
1
_m
,
2
_m
);
LengthType
min
=
+
1
_m
*
std
::
numeric_limits
<
typename
LengthType
::
value_type
>::
infinity
();
LengthType
max
=
-
1
_m
*
std
::
numeric_limits
<
typename
LengthType
::
value_type
>::
infinity
();
for
(
int
i
{
0
};
i
<
1'000'000
;
++
i
)
{
LengthType
x
=
dist
(
rng
);
min
=
std
::
min
(
min
,
x
);
max
=
std
::
max
(
max
,
x
);
}
CHECK
(
min
/
1
_m
==
Approx
(
1.
));
CHECK
(
max
/
2
_m
==
Approx
(
1.
));
}
SECTION
(
"range"
)
{
corsika
::
random
::
UniformRealDistribution
<
LengthType
>
dist
(
18
_cm
);
LengthType
min
=
+
1
_m
*
std
::
numeric_limits
<
typename
LengthType
::
value_type
>::
infinity
();
LengthType
max
=
-
1
_m
*
std
::
numeric_limits
<
typename
LengthType
::
value_type
>::
infinity
();
for
(
int
i
{
0
};
i
<
1'000'000
;
++
i
)
{
LengthType
x
=
dist
(
rng
);
min
=
std
::
min
(
min
,
x
);
max
=
std
::
max
(
max
,
x
);
}
CHECK
(
min
/
1
_m
==
Approx
(
0.
).
margin
(
1e-3
));
CHECK
(
max
/
18
_cm
==
Approx
(
1.
));
}
}
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