aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
partialInstantiation4MultiDim_tpl.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright 2005-2020 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 Implementation for partial instantiation functions.
25  *
26  * @author Christophe GONZALES(@AMU) and Pierre-Henri WUILLEMIN(@LIP6)
27  */
28 
29 // allow partialInstantiationPatterns to be used
30 #define GUM_PARTIAL_INSTANTIATION_PATTERN_ALLOWED 1
31 
32 #include <agrum/tools/multidim/utils/partialInstantiationRegister4MultiDim.h>
33 
34 #define GUM_MULTI_DIM_DECORATOR_PARTIAL_INST(NAME)
35  namespace gum {
36  template < typename GUM_SCALAR >
37  MultiDimImplementation< GUM_SCALAR >*
38  NAME(const MultiDimDecorator< GUM_SCALAR >& table,
39  const HashTable< const DiscreteVariable*, Idx >& inst_vars) {
40  const MultiDimImplementation< GUM_SCALAR >* impl = table.content();
41  return NAME(*impl, inst_vars);
42  }
43  }
44 
45 /// a specialized partial instantiation function for multiDimArrays
46 
47 #define GUM_MULTI_DIM_PARTIAL_INSTANTIATION_NAME partialInstantiationMultiDimArray
48 #include <agrum/tools/multidim/utils/patterns/partialInstantiationPattern4MultiDimArray.h>
49 #undef GUM_MULTI_DIM_PARTIAL_INSTANTIATION_NAME
50 
51 #define GUM_MULTI_DIM_PARTIAL_INSTANTIATION_IMPL2ARRAY_NAME
52  partialInstantiationMultiDimArray
53 #include <agrum/tools/multidim/utils/patterns/partialInstantiationPattern4MultiDimArray.h>
54 #undef GUM_MULTI_DIM_PARTIAL_INSTANTIATION_IMPL2ARRAY_NAME
55 
56 #define GUM_MULTI_DIM_PARTIAL_INSTANTIATION_POINTER_NAME
57  partialInstantiationMultiDimArray4Pointers
58 #include <agrum/tools/multidim/utils/patterns/partialInstantiationPattern4MultiDimArray.h>
59 #undef GUM_MULTI_DIM_PARTIAL_INSTANTIATION_POINTER_NAME
60 
61 #define GUM_MULTI_DIM_PARTIAL_INSTANTIATION_POINTER_IMPL2ARRAY_NAME
62  partialInstantiationMultiDimArray4Pointers
63 #include <agrum/tools/multidim/utils/patterns/partialInstantiationPattern4MultiDimArray.h>
64 #undef GUM_MULTI_DIM_PARTIAL_INSTANTIATION_POINTER_IMPL2ARRAY_NAME
65 
66 /// default "basename" functions for instantiating MultiDimImplementations
67 
68 #define GUM_MULTI_DIM_PARTIAL_INSTANTIATION_NAME
69  partialInstantiationMultiDimImplementation
70 #include <agrum/tools/multidim/utils/patterns/partialInstantiationPattern4BaseName.h>
71 #undef GUM_MULTI_DIM_PARTIAL_INSTANTIATION_NAME
72 
73 #define GUM_MULTI_DIM_PARTIAL_INSTANTIATION_POINTER_NAME
74  partialInstantiationMultiDimImplementation4Pointers
75 #include <agrum/tools/multidim/utils/patterns/partialInstantiationPattern4BaseName.h>
76 #undef GUM_MULTI_DIM_PARTIAL_INSTANTIATION_NAME
77 
78 // the operators that should be used to select appropriately the functions
79 // to partially instantiate multiDims
80 
81 /// the function to be used to partially instantiate a MultiDimImplementation
82 #define GUM_MULTI_DIM_PARTIAL_INSTANTIATION_NAME partialInstantiation
83 #include <agrum/tools/multidim/utils/patterns/partialInstantiationPattern4MultiDimImplementation.h>
84 #undef GUM_MULTI_DIM_PARTIAL_INSTANTIATION_NAME
85 
86 /// the function to be used to partially instantiate a MultiDimDecorator
87 GUM_MULTI_DIM_DECORATOR_PARTIAL_INST(partialInstantiation)
88 
89 //
90 // DO NOT FORGET TO REGISTER YOUR BINARY FUNCTIONS
91 //
92 
93 namespace gum {
94 
95  // the function used to register all the above functions
96  template < typename GUM_SCALAR >
98  static bool first_init = true;
99 
100  if (first_init) {
101  first_init = false;
102 
103  std::string MultiDimArrayString("MultiDimArray");
104  std::string MultiDimDecisionDiagramString("MultiDimDecisionDiagram");
105  std::string BaseNameString("MultiDimImplementation");
106 
107  // register base functions for multiDimArrays
108  registerPartialInstantiation< GUM_SCALAR >(
109  "i",
110  MultiDimArrayString,
111  &partialInstantiationMultiDimArray);
112 
113  // register default basename functions
114  registerPartialInstantiation< GUM_SCALAR >(
115  "i",
116  BaseNameString,
117  &partialInstantiationMultiDimImplementation);
118  }
119  }
120 
121  // the function used to register all the above functions
122  template < typename GUM_SCALAR >
124  static bool first_init = true;
125 
126  if (first_init) {
127  first_init = false;
128 
129  std::string MultiDimArrayString("MultiDimArray");
130  std::string BaseNameString("MultiDimImplementation");
131 
132  // register base functions for multiDimArrays
133  registerPartialInstantiation< GUM_SCALAR* >(
134  "i",
135  MultiDimArrayString,
136  &partialInstantiationMultiDimArray4Pointers);
137 
138  // register default basename functions
139  registerPartialInstantiation< GUM_SCALAR* >(
140  "i",
141  BaseNameString,
142  &partialInstantiationMultiDimImplementation4Pointers);
143  }
144  }
145 
146 } /* namespace gum */
147 
148 // remove permission to use operatorsPatterns
149 #undef GUM_PARTIAL_INSTANTIATION_PATTERN_ALLOWED
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:669
void pointerPartialInstantiation4MultiDimInit()
The function used to register all the instantiations on multidimImplementations over pointers types...
void partialInstantiation4MultiDimInit()
The function used to register all the instantiation operators on multidimImplementations over non-poi...
#define GUM_MULTI_DIM_DECORATOR_PARTIAL_INST(NAME)