farm-ng-core
reduce.h
Go to the documentation of this file.
1 
2 // Copyright (c) 2011, Hauke Strasdat
3 // Copyright (c) 2012, Steven Lovegrove
4 // Copyright (c) 2021, farm-ng, inc.
5 //
6 // Use of this source code is governed by an MIT-style
7 // license that can be found in the LICENSE file or at
8 // https://opensource.org/licenses/MIT.
9 
10 #pragma once
11 
12 #include "sophus/concepts/point.h"
13 
14 #include <Eigen/Core>
15 
16 #include <algorithm>
17 #include <utility>
18 #include <vector>
19 
20 namespace sophus {
21 namespace concepts {
22 
23 namespace details {
24 
25 template <class TScalar>
26 class Reduce {
27  public:
28  using Aggregate = TScalar;
29 
30  template <class TReduce, class TFunc>
31  static void implUnary(TScalar const& s, TReduce& reduce, TFunc const& f) {
32  f(s, reduce);
33  }
34 
35  template <class TReduce, class TFunc>
36  static void implBinary(
37  TScalar const& a, TScalar const& b, TReduce& reduce, TFunc const& f) {
38  f(a, b, reduce);
39  }
40 };
41 
42 template <::sophus::concepts::EigenDenseType TT>
43 class Reduce<TT> {
44  public:
45  template <class TReduce, class TFunc>
46  static void implUnary(TT const& v, TReduce& reduce, TFunc const& f) {
47  for (int r = 0; r < v.rows(); ++r) {
48  for (int c = 0; c < v.cols(); ++c) {
49  f(v(r, c), reduce);
50  }
51  }
52  }
53 
54  template <class TReduce, class TFunc>
55  static void implBinary(
56  TT const& a, TT const& b, TReduce& reduce, TFunc const& f) {
57  for (int r = 0; r < a.rows(); ++r) {
58  for (int c = 0; c < a.cols(); ++c) {
59  f(a(r, c), b(r, c), reduce);
60  }
61  }
62  }
63 };
64 
65 } // namespace details
66 
67 template <class TPoint, class TFunc, class TReduce>
68 void reduceArg(TPoint const& x, TReduce& reduce, TFunc&& func) {
69  details::Reduce<TPoint>::impl_unary(x, reduce, std::forward<TFunc>(func));
70 }
71 
72 template <class TPoint, class TFunc, class TReduce>
73 void reduceArg(
74  TPoint const& a, TPoint const& b, TReduce& reduce, TFunc&& func) {
75  details::Reduce<TPoint>::impl_binary(a, b, reduce, std::forward<TFunc>(func));
76 }
77 
78 template <class TPoint, class TFunc, class TReduce>
79 auto reduce(TPoint const& x, TReduce const& initial, TFunc&& func) -> TReduce {
80  TReduce reduce = initial;
81  details::Reduce<TPoint>::impl_unary(x, reduce, std::forward<TFunc>(func));
82  return reduce;
83 }
84 
85 template <class TPoint, class TFunc, class TReduce>
86 auto reduce(
87  TPoint const& a, TPoint const& b, TReduce const& initial, TFunc&& func)
88  -> TReduce {
89  TReduce reduce = initial;
90  details::Reduce<TPoint>::impl_binary(a, b, reduce, std::forward<TFunc>(func));
91  return reduce;
92 }
93 
94 } // namespace concepts
95 } // namespace sophus
point.h
sophus::concepts::details::Reduce
Definition: reduce.h:26
sophus
Image MutImage, owning images types.
Definition: num_diff.h:20
sophus::concepts::details::Reduce::Aggregate
TScalar Aggregate
Definition: reduce.h:28
sophus::concepts::details::Reduce< TT >::implBinary
static void implBinary(TT const &a, TT const &b, TReduce &reduce, TFunc const &f)
Definition: reduce.h:55
sophus::concepts::details::Reduce::implBinary
static void implBinary(TScalar const &a, TScalar const &b, TReduce &reduce, TFunc const &f)
Definition: reduce.h:36
sophus::concepts::reduce
auto reduce(TPoint const &x, TReduce const &initial, TFunc &&func) -> TReduce
Definition: reduce.h:79
sophus::concepts::details::Reduce< TT >::implUnary
static void implUnary(TT const &v, TReduce &reduce, TFunc const &f)
Definition: reduce.h:46
sophus::concepts::reduceArg
void reduceArg(TPoint const &x, TReduce &reduce, TFunc &&func)
Definition: reduce.h:68
core.event_service_recorder.func
func
Definition: event_service_recorder.py:420
sophus::concepts::details::Reduce::implUnary
static void implUnary(TScalar const &s, TReduce &reduce, TFunc const &f)
Definition: reduce.h:31