Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
typed-geometry
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
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
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Gregor Kobsik
typed-geometry
Commits
cce3e0eb
Commit
cce3e0eb
authored
5 years ago
by
Philip Trettner
Browse files
Options
Downloads
Patches
Plain Diff
added conversion-based uniform API
parent
66b0a5ef
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/typed-geometry/functions/random/uniform.hh
+24
-1
24 additions, 1 deletion
src/typed-geometry/functions/random/uniform.hh
with
24 additions
and
1 deletion
src/typed-geometry/functions/random/uniform.hh
+
24
−
1
View file @
cce3e0eb
...
...
@@ -25,7 +25,8 @@
#include
"random.hh"
/*
* uniform(rng) - fair coin flip
* uniform<T>(rng) - uniform sample for T's where no parameter is needed
* uniform(rng) - returns an object that implicitly converts to T (and calls uniform<T>(rng))
* uniform(rng, a, b) - uniform between a..b (inclusive!)
* uniform(rng, obj) - uniform sample from obj
*
...
...
@@ -47,6 +48,22 @@ struct sampler
{
static_assert
(
sizeof
(
T
)
>=
0
,
"sampling of this type not supported without parameters"
);
};
// NOTE: this class should not be saved
template
<
class
Rng
>
struct
uniform_sampler
{
explicit
uniform_sampler
(
Rng
&
rng
)
:
rng
(
rng
)
{}
template
<
class
T
>
operator
T
()
&&
{
return
sampler
<
T
>::
uniform
(
rng
);
}
private
:
Rng
&
rng
;
};
}
template
<
class
T
,
class
Rng
>
...
...
@@ -55,6 +72,12 @@ template <class T, class Rng>
return
detail
::
sampler
<
T
>::
uniform
(
rng
);
}
template
<
class
Rng
>
[[
nodiscard
]]
constexpr
detail
::
uniform_sampler
<
Rng
>
uniform
(
Rng
&
rng
)
{
return
detail
::
uniform_sampler
<
Rng
>
{
rng
};
}
template
<
class
Rng
>
[[
nodiscard
]]
constexpr
f32
uniform
(
Rng
&
rng
,
f32
a
,
f32
b
)
{
...
...
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