Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
polymesh
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
Container registry
Model registry
Operate
Environments
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
Zain Selman
polymesh
Commits
36c49b6d
Commit
36c49b6d
authored
5 years ago
by
Philip Trettner
Browse files
Options
Downloads
Patches
Plain Diff
added arbitrary random for smart ranges
parent
66ef0550
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/polymesh/impl/impl_ranges.hh
+19
-0
19 additions, 0 deletions
src/polymesh/impl/impl_ranges.hh
src/polymesh/ranges.hh
+6
-0
6 additions, 0 deletions
src/polymesh/ranges.hh
with
25 additions
and
0 deletions
src/polymesh/impl/impl_ranges.hh
+
19
−
0
View file @
36c49b6d
...
...
@@ -328,6 +328,25 @@ auto smart_range<this_t, ElementT>::aabb(FuncT&& f) const -> polymesh::minmax_t<
return
r
;
}
template
<
class
this_t
,
class
ElementT
>
template
<
class
Generator
,
class
FuncT
>
auto
smart_range
<
this_t
,
ElementT
>::
random
(
Generator
&
g
,
FuncT
&&
f
)
const
->
tmp
::
decayed_result_type_of
<
FuncT
,
ElementT
>
{
auto
it
=
static_cast
<
this_t
const
*>
(
this
)
->
begin
();
POLYMESH_ASSERT
(
it
.
is_valid
()
&&
"requires non-empty range"
);
auto
v
=
f
(
*
it
);
double
cnt
=
2
;
++
it
;
while
(
it
.
is_valid
())
{
if
(
double
(
g
())
*
cnt
<
double
(
g
.
max
()))
v
=
f
(
*
it
);
++
it
;
cnt
+=
1
;
}
return
v
;
}
template
<
class
this_t
,
class
ElementT
>
template
<
class
FuncT
>
auto
smart_range
<
this_t
,
ElementT
>::
minmax
(
FuncT
&&
f
)
const
->
polymesh
::
minmax_t
<
tmp
::
decayed_result_type_of
<
FuncT
,
ElementT
>>
...
...
This diff is collapsed.
Click to expand it.
src/polymesh/ranges.hh
+
6
−
0
View file @
36c49b6d
...
...
@@ -161,6 +161,11 @@ struct smart_range
template
<
class
PredT
>
auto
filter
(
PredT
&&
p
)
->
filtered_range
<
ElementT
,
this_t
&
,
PredT
>
;
/// returns a uniformly random sampled element from this range
/// complexity is O(n) (but does not allocate)
template
<
class
Generator
,
class
FuncT
=
tmp
::
identity
>
auto
random
(
Generator
&
g
,
FuncT
&&
f
=
{})
const
->
tmp
::
decayed_result_type_of
<
FuncT
,
ElementT
>
;
// TODO: (requires new ranges)
// - filter (or where?)
// - map
...
...
@@ -233,6 +238,7 @@ struct smart_collection : smart_range<smart_collection<mesh_ptr, tag, iterator>,
end_iterator
end
()
const
{
return
{};
}
/// returns a handle chosen uniformly at random
/// Complexity is usually O(1)
/// NOTE: when only valid handles are allowed, this will use rejection sampling
/// and thus get very slow if a lot of data is invalid
template
<
class
Generator
>
...
...
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