aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
partialInstantiation4MultiDim.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 Headers for partial instantiation functions.
25  *
26  * @author Christophe GONZALES(@AMU) and Pierre-Henri WUILLEMIN(@LIP6)
27  */
28 
29 #ifndef GUM_PARTIAL_INSTANTIATION_4_MULTI_DIM_H
30 #define GUM_PARTIAL_INSTANTIATION_4_MULTI_DIM_H
31 
32 #include <agrum/tools/core/hashTable.h>
33 #include <agrum/tools/core/set.h>
34 #include <agrum/tools/variables/discreteVariable.h>
35 //#include <agrum/tools/multidim/implementations/multiDimImplementation.h>
36 //#include <agrum/tools/multidim/implementations/multiDimArray.h>
37 //#include <agrum/tools/multidim/implementations/multiDimDecorator.h>
38 
39 namespace gum {
40 
41  template < typename GUM_SCALAR >
42  class MultiDimImplementation;
43 
44  template < typename GUM_SCALAR >
45  class MultiDimArray;
46 
47  template < typename GUM_SCALAR >
48  class MultiDimDecorator;
49 
50  /**
51  * @brief A specialized function for instantiating variables in a
52  * multiDimArray.
53  *
54  * @warning In practice, do not use this function but rather
55  * operator/function partialInstantiation on multiDimDecorators. This
56  * operator will take care to select this function if it is appropriate for
57  * your instantiation.
58  *
59  * The function instantiates some variables in a multiDimArray. For instance,
60  * if table is a MultiDimArray defined over A,B,C,D and if inst_vars =
61  * {<A=a1>,<C=c2>}, then the function returns a table over B,D defined as
62  * table (a1,B,c2,D).
63  *
64  * @param table The table to instantiate.
65  * @param inst_vars The variables instantiation.
66  * @return Returns the partial instantiation of table as a new MultiDimArray.
67  */
68  template < typename GUM_SCALAR >
70  const MultiDimArray< GUM_SCALAR >* table,
71  const HashTable< const DiscreteVariable*, Idx >& inst_vars);
72 
73  /**
74  * @brief A specialized function for instantiating variables in a
75  * MultiDimImplementation.
76  *
77  * @warning In practice, do not use this function but rather
78  * operator/function partialInstantiation on multiDimDecorators. This
79  * operator will take care to select this function if it is appropriate for
80  * your instantiation.
81  *
82  * The function instantiates some variables in a multiDimArray. For instance,
83  * if table is a MultiDimArray defined over A,B,C,D and if inst_vars =
84  * {<A=a1>,<C=c2>}, then the function returns a table over B,D defined as
85  * table (a1,B,c2,D).
86  *
87  * @param table The table to instantiate.
88  * @param inst_vars The variables instantiation.
89  * @return Returns the partial instantiation of table as a new
90  * MultiDimImplementation.
91  */
92  template < typename GUM_SCALAR >
93  MultiDimImplementation< GUM_SCALAR >* partialInstantiationMultiDimArray(
94  const MultiDimImplementation< GUM_SCALAR >* table,
95  const HashTable< const DiscreteVariable*, Idx >& inst_vars);
96 
97  /**
98  * @brief A specialized function for instantiating variables in a
99  * MultiDimArray.
100  *
101  * @warning In practice, do not use this function but rather
102  * operator/function partialInstantiation on multiDimDecorators. This
103  * operator will take care to select this function if it is appropriate for
104  * your instantiation.
105  *
106  * The function instantiates some variables in a multiDimArray. For instance,
107  * if table is a MultiDimArray defined over A,B,C,D and if inst_vars =
108  * {<A=a1>,<C=c2>}, then the function returns a table over B,D defined as
109  * table (a1,B,c2,D).
110  *
111  * @param table The table to instantiate.
112  * @param inst_vars The variables instantiation.
113  * @return Returns the partial instantiation of table as a new
114  * MultiDimArray.
115  */
116  template < typename GUM_SCALAR >
118  const MultiDimArray< GUM_SCALAR* >* table,
119  const HashTable< const DiscreteVariable*, Idx >& inst_vars);
120 
121  /**
122  * @brief A specialized function for instantiating variables in a
123  * MultiDimArray.
124  *
125  * @warning In practice, do not use this function but rather
126  * operator/function partialInstantiation on multiDimDecorators. This
127  * operator will take care to select this function if it is appropriate for
128  * your instantiation.
129  *
130  * The function instantiates some variables in a multiDimArray. For instance,
131  * if table is a MultiDimArray defined over A,B,C,D and if inst_vars =
132  * {<A=a1>,<C=c2>}, then the function returns a table over B,D defined as
133  * table (a1,B,c2,D).
134  *
135  * @param table The table to instantiate.
136  * @param inst_vars The variables instantiation.
137  * @return Returns the partial instantiation of table as a new
138  * MultiDimImplementation.
139  */
140  template < typename GUM_SCALAR >
141  MultiDimImplementation< GUM_SCALAR* >*
143  const MultiDimImplementation< GUM_SCALAR* >* table,
144  const HashTable< const DiscreteVariable*, Idx >& inst_vars);
145 
146  /**
147  * @brief Instantiate variables in a MultiDimImplementation.
148  *
149  * @param table The table to instantiate.
150  * @param inst_vars The variables instantiation.
151  * @return Returns the partial instantiation of table as a new
152  * MultiDimImplementation.
153  */
154  template < typename GUM_SCALAR >
155  MultiDimImplementation< GUM_SCALAR >* partialInstantiation(
156  const MultiDimImplementation< GUM_SCALAR >& table,
157  const HashTable< const DiscreteVariable*, Idx >& inst_vars);
158 
159  /**
160  * @brief Instantiate variables in a MultiDimDecorator.
161  *
162  * @param table The table to instantiate.
163  * @param inst_vars The variables instantiation.
164  * @return Returns the partial instantiation of table as a new
165  * MultiDimImplementation.
166  */
167  template < typename GUM_SCALAR >
168  MultiDimImplementation< GUM_SCALAR >* partialInstantiation(
169  const MultiDimDecorator< GUM_SCALAR >& table,
170  const HashTable< const DiscreteVariable*, Idx >& inst_vars);
171 
172  // ==========================================================================
173  // DO NOT FORGET TO REGISTER YOUR PARTIAL INSTANTIATION FUNCTIONS AT THE END
174  // OF FILE partialInstantiation4MultiDim_tpl.h
175  // ==========================================================================
176 
177  /**
178  * @brief The function used to register all the instantiation operators on
179  * multidimImplementations over non-pointers types.
180  */
181  template < typename GUM_SCALAR >
183 
184  /**
185  * @brief The function used to register all the instantiations on
186  * multidimImplementations over pointers types.
187  */
188  template < typename GUM_SCALAR >
190 
191  /**
192  * @class PartialInstantiation4MultiDimInitialize
193  * @brief A class used to register instantiation functions over non-pointers
194  * types.
195  *
196  * This class is of course completely redundant with function
197  * partialInstantiation4MultiDimInit. Its aim is to enable specialization of
198  * function partialInstantiation4MultiDimInit for pointer types: C++ allows
199  * partial specialization of templated classes (e.g., create different
200  * implementations for C<T> and C<T*>) but it does not allows partial
201  * specialization for functions. Hence, by creating a class the primary
202  * purpose of which is to run function partialInstantiation4MultiDimInit, we
203  * allow this partial specialization. This is most effective to produce
204  * different codes for pointer types and non-pointer types.
205  *
206  * @tparam GUM_SCALAR The type of scalars stored in the multidimensional
207  * table.
208  */
209  template < typename GUM_SCALAR >
211  /**
212  * @brief Initialize the partial instantiation functions.
213  */
214  void init() { partialInstantiation4MultiDimInit< GUM_SCALAR >(); };
215  };
216 
217  /**
218  * @class PartialInstantiation4MultiDimInitialize
219  * @brief A class used to register instantiation functions over pointers
220  * types.
221  *
222  * This class is of course completely redundant with function
223  * pointerPartialInstantiation4MultiDimInit. Its aim is to enable different
224  * implementations of the instantiation functions for multidims depending in
225  * whether these multidim contain pointers or not. Actually, C++ allows
226  * partial specialization of templated classes (e.g., create different
227  * implementations for C<T> and C<T*>) but it does not allows partial
228  * specialization for functions. Hence, by creating a class the primary
229  * purpose of which is to run function partialInstantiation4MultiDimInit or
230  * pointerPartialInstantiation4MultiDimInit, we allow this partial
231  * specialization to obtain.
232  *
233  * @tparam GUM_SCALAR The type of scalars stored in the multidimensional
234  * table as pointer.
235  */
236  template < typename GUM_SCALAR >
238  /**
239  * @brief Initialize the partial instantiation functions.
240  */
241  void init() { pointerPartialInstantiation4MultiDimInit< GUM_SCALAR >(); };
242  };
243 
244 } /* namespace gum */
245 
246 // always include the templatized implementations
247 #include <agrum/tools/multidim/utils/partialInstantiation4MultiDim_tpl.h>
248 
249 #endif /* GUM_PARTIAL_INSTANTIATION_4_MULTI_DIM_H */
void init()
Initialize the partial instantiation functions.
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:669
void init()
Initialize the partial instantiation functions.
MultiDimArray< GUM_SCALAR *> * partialInstantiationMultiDimArray4Pointers(const MultiDimArray< GUM_SCALAR * > *table, const HashTable< const DiscreteVariable *, Idx > &inst_vars)
A specialized function for instantiating variables in a MultiDimArray.
void pointerPartialInstantiation4MultiDimInit()
The function used to register all the instantiations on multidimImplementations over pointers types...
MultiDimArray< GUM_SCALAR > * partialInstantiationMultiDimArray(const MultiDimArray< GUM_SCALAR > *table, const HashTable< const DiscreteVariable *, Idx > &inst_vars)
A specialized function for instantiating variables in a multiDimArray.
Multidimensional matrix stored as an array in memory.
Definition: multiDimArray.h:53
MultiDimImplementation< GUM_SCALAR > * partialInstantiation(const MultiDimImplementation< GUM_SCALAR > &table, const HashTable< const DiscreteVariable *, Idx > &inst_vars)
Instantiate variables in a MultiDimImplementation.
Decorator design pattern in order to separate implementations from multidimensional matrix concepts...
MultiDimImplementation< GUM_SCALAR > * partialInstantiationMultiDimArray(const MultiDimImplementation< GUM_SCALAR > *table, const HashTable< const DiscreteVariable *, Idx > &inst_vars)
A specialized function for instantiating variables in a MultiDimImplementation.
MultiDimImplementation< GUM_SCALAR > * partialInstantiation(const MultiDimDecorator< GUM_SCALAR > &table, const HashTable< const DiscreteVariable *, Idx > &inst_vars)
Instantiate variables in a MultiDimDecorator.
void partialInstantiation4MultiDimInit()
The function used to register all the instantiation operators on multidimImplementations over non-poi...
MultiDimImplementation< GUM_SCALAR *> * partialInstantiationMultiDimArray4Pointers(const MultiDimImplementation< GUM_SCALAR * > *table, const HashTable< const DiscreteVariable *, Idx > &inst_vars)
A specialized function for instantiating variables in a MultiDimArray.
A class used to register instantiation functions over non-pointers types.