aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
partialInstantiation4MultiDim_tpl.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 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 partialInstantiationMultiDimArray
52 #include <agrum/tools/multidim/utils/patterns/partialInstantiationPattern4MultiDimArray.h>
53 #undef GUM_MULTI_DIM_PARTIAL_INSTANTIATION_IMPL2ARRAY_NAME
54 
55 #define GUM_MULTI_DIM_PARTIAL_INSTANTIATION_POINTER_NAME partialInstantiationMultiDimArray4Pointers
56 #include <agrum/tools/multidim/utils/patterns/partialInstantiationPattern4MultiDimArray.h>
57 #undef GUM_MULTI_DIM_PARTIAL_INSTANTIATION_POINTER_NAME
58 
59 #define GUM_MULTI_DIM_PARTIAL_INSTANTIATION_POINTER_IMPL2ARRAY_NAME
60  partialInstantiationMultiDimArray4Pointers
61 #include <agrum/tools/multidim/utils/patterns/partialInstantiationPattern4MultiDimArray.h>
62 #undef GUM_MULTI_DIM_PARTIAL_INSTANTIATION_POINTER_IMPL2ARRAY_NAME
63 
64 /// default "basename" functions for instantiating MultiDimImplementations
65 
66 #define GUM_MULTI_DIM_PARTIAL_INSTANTIATION_NAME partialInstantiationMultiDimImplementation
67 #include <agrum/tools/multidim/utils/patterns/partialInstantiationPattern4BaseName.h>
68 #undef GUM_MULTI_DIM_PARTIAL_INSTANTIATION_NAME
69 
70 #define GUM_MULTI_DIM_PARTIAL_INSTANTIATION_POINTER_NAME
71  partialInstantiationMultiDimImplementation4Pointers
72 #include <agrum/tools/multidim/utils/patterns/partialInstantiationPattern4BaseName.h>
73 #undef GUM_MULTI_DIM_PARTIAL_INSTANTIATION_NAME
74 
75 // the operators that should be used to select appropriately the functions
76 // to partially instantiate multiDims
77 
78 /// the function to be used to partially instantiate a MultiDimImplementation
79 #define GUM_MULTI_DIM_PARTIAL_INSTANTIATION_NAME partialInstantiation
80 #include <agrum/tools/multidim/utils/patterns/partialInstantiationPattern4MultiDimImplementation.h>
81 #undef GUM_MULTI_DIM_PARTIAL_INSTANTIATION_NAME
82 
83 /// the function to be used to partially instantiate a MultiDimDecorator
84 GUM_MULTI_DIM_DECORATOR_PARTIAL_INST(partialInstantiation)
85 
86 //
87 // DO NOT FORGET TO REGISTER YOUR BINARY FUNCTIONS
88 //
89 
90 namespace gum {
91 
92  // the function used to register all the above functions
93  template < typename GUM_SCALAR >
95  static bool first_init = true;
96 
97  if (first_init) {
98  first_init = false;
99 
100  std::string MultiDimArrayString("MultiDimArray");
101  std::string MultiDimDecisionDiagramString("MultiDimDecisionDiagram");
102  std::string BaseNameString("MultiDimImplementation");
103 
104  // register base functions for multiDimArrays
105  registerPartialInstantiation< GUM_SCALAR >("i",
106  MultiDimArrayString,
107  &partialInstantiationMultiDimArray);
108 
109  // register default basename functions
110  registerPartialInstantiation< GUM_SCALAR >("i",
111  BaseNameString,
112  &partialInstantiationMultiDimImplementation);
113  }
114  }
115 
116  // the function used to register all the above functions
117  template < typename GUM_SCALAR >
119  static bool first_init = true;
120 
121  if (first_init) {
122  first_init = false;
123 
124  std::string MultiDimArrayString("MultiDimArray");
125  std::string BaseNameString("MultiDimImplementation");
126 
127  // register base functions for multiDimArrays
128  registerPartialInstantiation< GUM_SCALAR* >("i",
129  MultiDimArrayString,
130  &partialInstantiationMultiDimArray4Pointers);
131 
132  // register default basename functions
133  registerPartialInstantiation< GUM_SCALAR* >(
134  "i",
135  BaseNameString,
136  &partialInstantiationMultiDimImplementation4Pointers);
137  }
138  }
139 
140 } /* namespace gum */
141 
142 // remove permission to use operatorsPatterns
143 #undef GUM_PARTIAL_INSTANTIATION_PATTERN_ALLOWED
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
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)