OpenGM  2.3.x
Discrete Graphical Model Library
weightedoperations.hxx
Go to the documentation of this file.
1 #pragma once
2 #ifndef OPENGM_OPERATION_WEIGTED_OPERATIONS_HXX
3 #define OPENGM_OPERATION_WEIGTED_OPERATIONS_HXX
4 
6 
7 namespace opengm {
8 
9 struct WeightedOperations{
11  template<class OP, class T1, class T2>
12  static inline void weightedMean(const T2& in1, const T2& in2, const T1& w, T2& out)
13  {
14  OPENGM_ASSERT(&out != &in2);
15  out = in1;
16  OP::iop(in2,out);
17  OP::hop(w,out);
18  OP::op(in2,out);
19  // equivalent to
20  // out = in1*w + in2*(1-w) = (in1-in2)*w+in2
21  // out = in1^w * in2^(1-w) = (in1/in2)^w*in2
22  }
23 
25  template<class OP, class T1, class T2>
26  static inline void wop(const T2& in, const T1& w, T2& out)
27  {
28  T2 t = in;
29  OP::hop(w,t);
30  OP::op(t,out);
31  // equivalent to
32  // out = out + in*w
33  // out = out * in^w
34  }
35 
37  template<class OP, class T1, class T2>
38  static inline void iwop(const T2& in, const T1& w, T2& out)
39  {
40  T2 t = in;
41  T1 v = 1/w;
42  OP::hop(v,t);
43  OP::op(t,out);
44  // equivalent to
45  // out = out + in/w
46  // out = out * in^(1/w)
47  }
48 
50  template<class OP, class T1, class T2>
51  static inline void wiop(const T2& in, const T1& w, T2& out)
52  {
53  T2 t = in;
54  OP::hop(w,t);
55  OP::iop(t,out);
56  // equivalent to
57  // out = out - in*w
58  // out = out / in^(w)
59  }
60 
62  template<class OP, class T1, class T2>
63  static inline void iwiop(const T2& in, const T1& w, T2& out)
64  {
65  T2 t = in;
66  T1 v = 1/w;
67  OP::hop(v,t);
68  OP::iop(t,out);
69  // equivalent to
70  // out = out - in/w
71  // out = out / in^(1/w)
72  }
73 };
74 
75 } // namespace opengm
76 
78 
79 #endif // #ifndef OPENGM_OPERATION_WEIGTED_OPERATIONS_HXX
The OpenGM namespace.
Definition: config.hxx:43
#define OPENGM_ASSERT(expression)
Definition: opengm.hxx:77