aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
partialInstantiation4MultiDim.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 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 >
69  MultiDimArray< GUM_SCALAR >*
70  partialInstantiationMultiDimArray(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 >*
94  partialInstantiationMultiDimArray(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* >* partialInstantiationMultiDimArray4Pointers(
142  const MultiDimImplementation< GUM_SCALAR* >* table,
143  const HashTable< const DiscreteVariable*, Idx >& inst_vars);
144 
145  /**
146  * @brief Instantiate variables in a MultiDimImplementation.
147  *
148  * @param table The table to instantiate.
149  * @param inst_vars The variables instantiation.
150  * @return Returns the partial instantiation of table as a new
151  * MultiDimImplementation.
152  */
153  template < typename GUM_SCALAR >
154  MultiDimImplementation< GUM_SCALAR >*
155  partialInstantiation(const MultiDimImplementation< GUM_SCALAR >& table,
156  const HashTable< const DiscreteVariable*, Idx >& inst_vars);
157 
158  /**
159  * @brief Instantiate variables in a MultiDimDecorator.
160  *
161  * @param table The table to instantiate.
162  * @param inst_vars The variables instantiation.
163  * @return Returns the partial instantiation of table as a new
164  * MultiDimImplementation.
165  */
166  template < typename GUM_SCALAR >
167  MultiDimImplementation< GUM_SCALAR >*
168  partialInstantiation(const MultiDimDecorator< GUM_SCALAR >& table,
169  const HashTable< const DiscreteVariable*, Idx >& inst_vars);
170 
171  // ==========================================================================
172  // DO NOT FORGET TO REGISTER YOUR PARTIAL INSTANTIATION FUNCTIONS AT THE END
173  // OF FILE partialInstantiation4MultiDim_tpl.h
174  // ==========================================================================
175 
176  /**
177  * @brief The function used to register all the instantiation operators on
178  * multidimImplementations over non-pointers types.
179  */
180  template < typename GUM_SCALAR >
182 
183  /**
184  * @brief The function used to register all the instantiations on
185  * multidimImplementations over pointers types.
186  */
187  template < typename GUM_SCALAR >
189 
190  /**
191  * @class PartialInstantiation4MultiDimInitialize
192  * @brief A class used to register instantiation functions over non-pointers
193  * types.
194  *
195  * This class is of course completely redundant with function
196  * partialInstantiation4MultiDimInit. Its aim is to enable specialization of
197  * function partialInstantiation4MultiDimInit for pointer types: C++ allows
198  * partial specialization of templated classes (e.g., create different
199  * implementations for C<T> and C<T*>) but it does not allows partial
200  * specialization for functions. Hence, by creating a class the primary
201  * purpose of which is to run function partialInstantiation4MultiDimInit, we
202  * allow this partial specialization. This is most effective to produce
203  * different codes for pointer types and non-pointer types.
204  *
205  * @tparam GUM_SCALAR The type of scalars stored in the multidimensional
206  * table.
207  */
208  template < typename GUM_SCALAR >
210  /**
211  * @brief Initialize the partial instantiation functions.
212  */
213  void init() { partialInstantiation4MultiDimInit< GUM_SCALAR >(); };
214  };
215 
216  /**
217  * @class PartialInstantiation4MultiDimInitialize
218  * @brief A class used to register instantiation functions over pointers
219  * types.
220  *
221  * This class is of course completely redundant with function
222  * pointerPartialInstantiation4MultiDimInit. Its aim is to enable different
223  * implementations of the instantiation functions for multidims depending in
224  * whether these multidim contain pointers or not. Actually, C++ allows
225  * partial specialization of templated classes (e.g., create different
226  * implementations for C<T> and C<T*>) but it does not allows partial
227  * specialization for functions. Hence, by creating a class the primary
228  * purpose of which is to run function partialInstantiation4MultiDimInit or
229  * pointerPartialInstantiation4MultiDimInit, we allow this partial
230  * specialization to obtain.
231  *
232  * @tparam GUM_SCALAR The type of scalars stored in the multidimensional
233  * table as pointer.
234  */
235  template < typename GUM_SCALAR >
237  /**
238  * @brief Initialize the partial instantiation functions.
239  */
240  void init() { pointerPartialInstantiation4MultiDimInit< GUM_SCALAR >(); };
241  };
242 
243 } /* namespace gum */
244 
245 // always include the templatized implementations
246 #include <agrum/tools/multidim/utils/partialInstantiation4MultiDim_tpl.h>
247 
248 #endif /* GUM_PARTIAL_INSTANTIATION_4_MULTI_DIM_H */
void init()
Initialize the partial instantiation functions.
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
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.