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
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
Philip Trettner
typed-geometry
Commits
25b20d15
Commit
25b20d15
authored
4 years ago
by
Julius Nehring-Wirxel
Browse files
Options
Downloads
Patches
Plain Diff
Add `max_index` and `min_index`
parent
e76242f6
Branches
Branches containing commit
No related tags found
1 merge request
!102
Add `max_index` and `min_index`
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/typed-geometry/functions/basic/statistics.hh
+61
-2
61 additions, 2 deletions
src/typed-geometry/functions/basic/statistics.hh
with
61 additions
and
2 deletions
src/typed-geometry/functions/basic/statistics.hh
+
61
−
2
View file @
25b20d15
...
...
@@ -10,6 +10,8 @@
*
* - min_element
* - max_element
* - max_index
* - min_index
* - average (same as arithmetic_mean)
* - mean (same as arithmetic_mean)
* - arithmetic_mean
...
...
@@ -39,11 +41,11 @@ template <class T = void, class RangeT, class TransformF, class ReduceF>
using
U
=
std
::
decay_t
<
decltype
(
f
(
t
(
R
(
*
it
)),
t
(
R
(
*
it
))))
>
;
auto
const
e
=
tg
::
end
(
values
);
U
r
=
t
(
R
(
*
it
));
it
++
;
++
it
;
while
(
it
!=
e
)
{
r
=
f
(
r
,
t
(
R
(
*
it
)));
it
++
;
++
it
;
}
return
r
;
}
...
...
@@ -111,6 +113,63 @@ template <class RangeT, class TransformT = identity_fun>
return
detail
::
fold_right
(
values
,
transform
,
[](
auto
&&
a
,
auto
&&
b
)
{
return
max
(
a
,
b
);
});
}
/// returns the index of the max element
template
<
class
RangeT
,
class
TransformT
=
identity_fun
>
[[
nodiscard
]]
constexpr
size_t
max_index
(
RangeT
const
&
values
,
TransformT
&&
transform
=
{})
{
TG_CONTRACT
(
tg
::
begin
(
values
)
!=
tg
::
end
(
values
)
&&
"values must not be empty"
);
size_t
curr_idx
=
0
;
auto
it
=
tg
::
begin
(
values
);
auto
const
end
=
tg
::
end
(
values
);
auto
max_v
=
transform
(
*
it
);
size_t
max_idx
=
curr_idx
;
++
it
;
++
curr_idx
;
while
(
it
!=
end
)
{
auto
v
=
transform
(
*
it
);
if
(
v
>
max_v
)
{
max_v
=
v
;
max_idx
=
curr_idx
;
}
++
it
;
++
curr_idx
;
}
return
max_idx
;
}
/// returns the index of the min element
template
<
class
RangeT
,
class
TransformT
=
identity_fun
>
[[
nodiscard
]]
constexpr
size_t
min_index
(
RangeT
const
&
values
,
TransformT
&&
transform
=
{})
{
TG_CONTRACT
(
tg
::
begin
(
values
)
!=
tg
::
end
(
values
)
&&
"values must not be empty"
);
size_t
curr_idx
=
0
;
auto
it
=
tg
::
begin
(
values
);
auto
const
end
=
tg
::
end
(
values
);
auto
min_v
=
transform
(
*
it
);
size_t
min_idx
=
curr_idx
;
++
it
;
++
curr_idx
;
while
(
it
!=
end
)
{
auto
v
=
transform
(
*
it
);
if
(
v
<
min_v
)
{
min_v
=
v
;
min_idx
=
curr_idx
;
}
++
it
;
++
curr_idx
;
}
return
min_idx
;
}
template
<
class
T
=
void
,
class
RangeT
=
void
,
class
TransformT
=
identity_fun
>
[[
nodiscard
]]
constexpr
auto
sum
(
RangeT
const
&
values
,
TransformT
&&
transform
=
{})
{
...
...
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