aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
operatorPattern4MultiDimFunctionGraph.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright (c) 2005-2021 by Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
4  * info_at_agrum_dot_org
5  *
6  * This library is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 
22 /**
23  * @file
24  * @brief the pattern used by all binary MultiDimFunctionGraphs operators
25  *
26  * @author Jean-Christophe MAGNAN
27  * @author Christophe GONZALES(@AMU) and Pierre-Henri WUILLEMIN(@LIP6)
28  */
29 
30 // check if we allowed these patterns to be used
31 #ifndef GUM_OPERATOR_PATTERN_ALLOWED
32 
33 // #warning To use operatorPattern4MultiDimFunctionGraph.h, you must define
34 // GUM_OPERATOR_PATTERN_ALLOWED
35 
36 #else
37 
38 # include <agrum/tools/core/functors.h>
39 
40 # include <agrum/tools/multidim/implementations/multiDimFunctionGraph.h>
41 # include <agrum/tools/multidim/implementations/multiDimImplementation.h>
42 # include <agrum/tools/multidim/utils/FunctionGraphUtilities/operators/multiDimFunctionGraphOperator.h>
43 
44 namespace gum {
45 
46  /**
47  * This specialized function combines two MultiDimFunctionGraphs. Any
48  * operation (addition, subtraction, multiplication, ...) must call this
49  * methods.
50  **/
51 
52 # ifdef GUM_MULTI_DIM_OPERATOR_NAME
53 # define GUM_MULTI_DIM_OPERATOR_TYPE GUM_SCALAR
54  template < typename GUM_SCALAR >
55  MultiDimFunctionGraph< GUM_SCALAR >*
56  GUM_MULTI_DIM_OPERATOR_NAME(const MultiDimFunctionGraph< GUM_SCALAR >* dg1,
57  const MultiDimFunctionGraph< GUM_SCALAR >* dg2)
58 # endif
59 
60  // clang-format off
61 
62 #ifdef GUM_MULTI_DIM_OPERATOR_IMPL2DECISION_GRAPH_NAME
63 #define GUM_MULTI_DIM_OPERATOR_TYPE GUM_SCALAR
64  template <typename GUM_SCALAR>
65  MultiDimImplementation<GUM_SCALAR>*
66  GUM_MULTI_DIM_OPERATOR_IMPL2DECISION_GRAPH_NAME(
67  const MultiDimImplementation<GUM_SCALAR>* tt1,
68  const MultiDimImplementation<GUM_SCALAR>* tt2 )
69 #endif
70 
71  // clang-format on
72 
73  {
74 
75 # ifdef GUM_MULTI_DIM_OPERATOR_IMPL2DECISION_GRAPH_NAME
76  const MultiDimFunctionGraph< GUM_SCALAR >* dg1
77  = reinterpret_cast< const MultiDimFunctionGraph< GUM_SCALAR >* >(tt1);
78  const MultiDimFunctionGraph< GUM_SCALAR >* dg2
79  = reinterpret_cast< const MultiDimFunctionGraph< GUM_SCALAR >* >(tt2);
80 # endif
81  MultiDimFunctionGraphOperator< GUM_MULTI_DIM_OPERATOR_TYPE, GUM_MULTI_DIM_OPERATOR > ope(dg1,
82  dg2);
83 
84  return ope.compute();
85  }
86 # undef GUM_MULTI_DIM_OPERATOR_TYPE
87 
88 } // End of namespace gum
89 #endif /* GUM_OPERATOR_PATTERN_ALLOWED */