aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
completeProjections4MultiDim.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 Efficient functionals for projecting multidim tables over all their
25  * variables
26  *
27  * @author Christophe GONZALES(@AMU) and Pierre-Henri WUILLEMIN(@LIP6)
28  */
29 
30 #ifndef GUM_COMPLETE_PROJECTIONS_4_MULTI_DIM_H
31 #define GUM_COMPLETE_PROJECTIONS_4_MULTI_DIM_H
32 
33 #include <agrum/tools/multidim/implementations/multiDimArray.h>
34 #include <agrum/tools/multidim/implementations/multiDimImplementation.h>
35 #include <agrum/tools/multidim/instantiation.h>
36 
37 namespace gum {
38 
39  // ==========================================================================
40  /// @name Project Max Operators
41  // ==========================================================================
42  /// @{
43 
44  /**
45  * @brief A specialized function for projecting a multiDimArray using a Max
46  * operator.
47  * @ingroup multidim_op_group
48  *
49  * The function projects a table over all its variables and, thus, returns
50  * the max value stored in the table.
51  *
52  * @param table a pointer on the multidim table to be projected
53  *
54  * @param instantiation if instantiation is different from 0, then the
55  * projection function stores in the instantation the values of the variables
56  * that led to the max (hence, the argmax).
57  *
58  * @return the max value stored in the multiDimArray
59  *
60  * @warning In practice, do not use this function but rather
61  * operator/function projectMax on MultiDimImplementation. This operator will
62  * take care to select this function if it is appropriate for your
63  * projection.
64  */
65  template < typename GUM_SCALAR >
66  GUM_SCALAR projectMaxMultiDimArray(const MultiDimArray< GUM_SCALAR >* table,
67  Instantiation* instantiation = 0);
68 
69  /**
70  * @brief A specialized function for projecting a multiDimArray using a Max
71  * operator.
72  * @ingroup multidim_op_group
73  *
74  * The function projects a table over all its variables and, thus, returns
75  * the max value stored in the table.
76  *
77  * @param table a pointer on the multidim table to be projected
78  *
79  * @param instantiation if instantiation is different from 0, then the
80  * projection function stores in the instantation the values of the variables
81  * that led to the max (hence, the argmax).
82  *
83  * @return the max value stored in the multiDimArray
84  *
85  * @warning In practice, do not use this function but rather
86  * operator/function projectMax on MultiDimImplementation. This operator will
87  * take care to select this function if it is appropriate for your
88  * projection.
89  */
90  template < typename GUM_SCALAR >
91  GUM_SCALAR projectMaxMultiDimArray(const MultiDimImplementation< GUM_SCALAR >* table,
92  Instantiation* instantiation = 0);
93 
94  /**
95  * @brief A specialized function for projecting a multiDimArray using a Max
96  * operator.
97  * @ingroup multidim_op_group
98  *
99  * The function projects a table over all its variables and, thus, returns
100  * the max value stored in the table.
101  *
102  * @param table a pointer on the multidim table to be projected
103  *
104  * @param instantiation if instantiation is different from 0, then the
105  * projection function stores in the instantation the values of the variables
106  * that led to the max (hence, the argmax).
107  *
108  * @return the max value stored in the multiDimArray
109  *
110  * @warning In practice, do not use this function but rather
111  * operator/function projectMax on MultiDimImplementation. This operator will
112  * take care to select this function if it is appropriate for your
113  * projection.
114  */
115  template < typename GUM_SCALAR >
116  GUM_SCALAR* projectMaxMultiDimArray4Pointers(const MultiDimArray< GUM_SCALAR* >* table,
117  Instantiation* instantiation = 0);
118 
119  /**
120  * @brief A specialized function for projecting a multiDimArray using a Max
121  * operator.
122  * @ingroup multidim_op_group
123  *
124  * The function projects a table over all its variables and, thus, returns
125  * the max value stored in the table.
126  *
127  * @param table a pointer on the multidim table to be projected
128  *
129  * @param instantiation if instantiation is different from 0, then the
130  * projection function stores in the instantation the values of the variables
131  * that led to the max (hence, the argmax).
132  *
133  * @return the max value stored in the multiDimArray
134  *
135  * @warning In practice, do not use this function but rather
136  * operator/function projectMax on MultiDimImplementation. This operator will
137  * take care to select this function if it is appropriate for your
138  * projection.
139  */
140  template < typename GUM_SCALAR >
141  GUM_SCALAR* projectMaxMultiDimArray4Pointers(const MultiDimImplementation< GUM_SCALAR* >* table,
142  Instantiation* instantiation = 0);
143 
144  /// @}
145  // ==========================================================================
146  /// @name Project Min Operators
147  // ==========================================================================
148  /// @{
149 
150  /**
151  * @brief A specialized function for projecting a multiDimArray using a Min
152  * operator.
153  * @ingroup multidim_op_group
154  *
155  * The function projects a table over all its variables and, thus, returns
156  * the min value stored in the table
157  *
158  * @return the min value stored in the multiDimArray
159  *
160  * @param table a pointer on the multidim table to be projected
161  *
162  * @param instantiation if instantiation is different from 0, then the
163  * projection function stores in the instantation the values of the variables
164  * that led to the min (hence, the argmin).
165  *
166  * @warning In practice, do not use this function but rather
167  * operator/function projectMin on MultiDimImplementation. This operator will
168  * take care to select this function if it is appropriate for your
169  * projection.
170  */
171  template < typename GUM_SCALAR >
172  GUM_SCALAR projectMinMultiDimArray(const MultiDimArray< GUM_SCALAR >* table,
173  Instantiation* instantiation = 0);
174 
175  /**
176  * @brief A specialized function for projecting a multiDimArray using a Min
177  * operator.
178  * @ingroup multidim_op_group
179  *
180  * The function projects a table over all its variables and, thus, returns
181  * the min value stored in the table
182  *
183  * @return the min value stored in the multiDimArray
184  *
185  * @param table a pointer on the multidim table to be projected
186  *
187  * @param instantiation if instantiation is different from 0, then the
188  * projection function stores in the instantation the values of the variables
189  * that led to the min (hence, the argmin).
190  *
191  * @warning In practice, do not use this function but rather
192  * operator/function projectMin on MultiDimImplementation. This operator will
193  * take care to select this function if it is appropriate for your
194  * projection.
195  */
196  template < typename GUM_SCALAR >
197  GUM_SCALAR projectMinMultiDimArray(const MultiDimImplementation< GUM_SCALAR >* table,
198  Instantiation* instantiation = 0);
199 
200  /**
201  * @brief A specialized function for projecting a multiDimArray using a Min
202  * operator.
203  * @ingroup multidim_op_group
204  *
205  * The function projects a table over all its variables and, thus, returns
206  * the min value stored in the table
207  *
208  * @return the min value stored in the multiDimArray
209  *
210  * @param table a pointer on the multidim table to be projected
211  *
212  * @param instantiation if instantiation is different from 0, then the
213  * projection function stores in the instantation the values of the variables
214  * that led to the min (hence, the argmin).
215  *
216  * @warning In practice, do not use this function but rather
217  * operator/function projectMin on MultiDimImplementation. This operator will
218  * take care to select this function if it is appropriate for your
219  * projection.
220  */
221  template < typename GUM_SCALAR >
222  GUM_SCALAR* projectMinMultiDimArray4Pointers(const MultiDimArray< GUM_SCALAR* >* table,
223  Instantiation* instantiation = 0);
224 
225  /**
226  * @brief A specialized function for projecting a multiDimArray using a Min
227  * operator.
228  * @ingroup multidim_op_group
229  *
230  * The function projects a table over all its variables and, thus, returns
231  * the min value stored in the table
232  *
233  * @return the min value stored in the multiDimArray
234  *
235  * @param table a pointer on the multidim table to be projected
236  *
237  * @param instantiation if instantiation is different from 0, then the
238  * projection function stores in the instantation the values of the variables
239  * that led to the min (hence, the argmin).
240  *
241  * @warning In practice, do not use this function but rather
242  * operator/function projectMin on MultiDimImplementation. This operator will
243  * take care to select this function if it is appropriate for your
244  * projection.
245  */
246  template < typename GUM_SCALAR >
247  GUM_SCALAR* projectMinMultiDimArray4Pointers(const MultiDimImplementation< GUM_SCALAR* >* table,
248  Instantiation* instantiation = 0);
249 
250  /// @}
251  // ==========================================================================
252  /// @name Project Sum Operators
253  // ==========================================================================
254  /// @{
255 
256  /**
257  * @brief a specialized function for projecting a multiDimArray using a Sum
258  * operator
259  * @ingroup multidim_op_group
260  *
261  * The function projects a table over all its variables and, thus, returns
262  * the sum of the values stored in the table
263  *
264  * @return the sum of the values stored in the multiDimArray
265  *
266  * @param table a pointer on the multidim table to be projected
267  *
268  * @param instantiation It shall always be 0 else instantiation is updated
269  * with a meaningless value. In addition, setting instantiation to a value
270  * different than 0 will induce more computations and thus will slow down the
271  * projection.
272  *
273  * @warning In practice, do not use this function but rather
274  * operator/function projectSum on MultiDimImplementation. This operator will
275  * take care to select this function if it is appropriate for your
276  * projection.
277  */
278  template < typename GUM_SCALAR >
279  GUM_SCALAR projectSumMultiDimArray(const MultiDimArray< GUM_SCALAR >* table,
280  Instantiation* instantiation = 0);
281 
282  /**
283  * @brief a specialized function for projecting a multiDimArray using a Sum
284  * operator
285  * @ingroup multidim_op_group
286  *
287  * The function projects a table over all its variables and, thus, returns
288  * the sum of the values stored in the table
289  *
290  * @return the sum of the values stored in the multiDimArray
291  *
292  * @param table a pointer on the multidim table to be projected
293  *
294  * @param instantiation It shall always be 0 else instantiation is updated
295  * with a meaningless value. In addition, setting instantiation to a value
296  * different than 0 will induce more computations and thus will slow down the
297  * projection.
298  *
299  * @warning In practice, do not use this function but rather
300  * operator/function projectSum on MultiDimImplementation. This operator will
301  * take care to select this function if it is appropriate for your
302  * projection.
303  */
304  template < typename GUM_SCALAR >
305  GUM_SCALAR projectSumMultiDimArray(const MultiDimImplementation< GUM_SCALAR >* table,
306  Instantiation* instantiation = 0);
307 
308  /**
309  * @brief a specialized function for projecting a multiDimArray using a Sum
310  * operator
311  * @ingroup multidim_op_group
312  *
313  * The function projects a table over all its variables and, thus, returns
314  * the sum of the values stored in the table
315  *
316  * @return the sum of the values stored in the multiDimArray
317  *
318  * @param table a pointer on the multidim table to be projected
319  *
320  * @param instantiation It shall always be 0 else instantiation is updated
321  * with a meaningless value. In addition, setting instantiation to a value
322  * different than 0 will induce more computations and thus will slow down the
323  * projection.
324  *
325  * @warning In practice, do not use this function but rather
326  * operator/function projectSum on MultiDimImplementation. This operator will
327  * take care to select this function if it is appropriate for your
328  * projection.
329  */
330  template < typename GUM_SCALAR >
331  GUM_SCALAR* projectSumMultiDimArray4Pointers(const MultiDimArray< GUM_SCALAR* >* table,
332  Instantiation* instantiation = 0);
333 
334  /**
335  * @brief a specialized function for projecting a multiDimArray using a Sum
336  * operator
337  * @ingroup multidim_op_group
338  *
339  * The function projects a table over all its variables and, thus, returns
340  * the sum of the values stored in the table
341  *
342  * @return the sum of the values stored in the multiDimArray
343  *
344  * @param table a pointer on the multidim table to be projected
345  *
346  * @param instantiation It shall always be 0 else instantiation is updated
347  * with a meaningless value. In addition, setting instantiation to a value
348  * different than 0 will induce more computations and thus will slow down the
349  * projection.
350  *
351  * @warning In practice, do not use this function but rather
352  * operator/function projectSum on MultiDimImplementation. This operator will
353  * take care to select this function if it is appropriate for your
354  * projection.
355  */
356  template < typename GUM_SCALAR >
357  GUM_SCALAR* projectSumMultiDimArray4Pointers(const MultiDimImplementation< GUM_SCALAR* >* table,
358  Instantiation* instantiation = 0);
359 
360  /// @}
361  // ==========================================================================
362  /// @name Project Multiply Operators
363  // ==========================================================================
364  /// @{
365 
366  /**
367  * @brief a function for projecting a multiDimArray using a Product operator
368  * @ingroup multidim_op_group
369  *
370  * The function projects a table over all its variables and, thus, returns
371  * the product of the values stored in the table
372  *
373  * @return the product of the values stored in the multiDimArray
374  *
375  * @param table a pointer on the multidim table to be projected
376  *
377  * @param instantiation It shall always be 0 else instantiation is updated
378  * with a meaningless value. In addition, setting instantiation to a value
379  * different than 0 will induce more computations and thus will slow down the
380  * projection.
381  *
382  * @warning In practice, do not use this function but rather
383  * operator/function projectProduct on MultiDimImplementation. This operator
384  * will take care to select this function if it is appropriate for your
385  * projection.
386  */
387  template < typename GUM_SCALAR >
388  GUM_SCALAR projectProductMultiDimArray(const MultiDimArray< GUM_SCALAR >* table,
389  Instantiation* instantiation = 0);
390 
391  /**
392  * @brief a function for projecting a multiDimArray using a Product operator
393  * @ingroup multidim_op_group
394  *
395  * The function projects a table over all its variables and, thus, returns
396  * the product of the values stored in the table
397  *
398  * @return the product of the values stored in the multiDimArray
399  *
400  * @param table a pointer on the multidim table to be projected
401  *
402  * @param instantiation It shall always be 0 else instantiation is updated
403  * with a meaningless value. In addition, setting instantiation to a value
404  * different than 0 will induce more computations and thus will slow down the
405  * projection.
406  *
407  * @warning In practice, do not use this function but rather
408  * operator/function projectProduct on MultiDimImplementation. This operator
409  * will take care to select this function if it is appropriate for your
410  * projection.
411  */
412  template < typename GUM_SCALAR >
413  GUM_SCALAR projectProductMultiDimArray(const MultiDimImplementation< GUM_SCALAR >* table,
414  Instantiation* instantiation = 0);
415 
416  /**
417  * @brief a function for projecting a multiDimArray using a Product operator
418  * @ingroup multidim_op_group
419  *
420  * The function projects a table over all its variables and, thus, returns
421  * the product of the values stored in the table
422  *
423  * @return the product of the values stored in the multiDimArray
424  *
425  * @param table a pointer on the multidim table to be projected
426  *
427  * @param instantiation It shall always be 0 else instantiation is updated
428  * with a meaningless value. In addition, setting instantiation to a value
429  * different than 0 will induce more computations and thus will slow down the
430  * projection.
431  *
432  * @warning In practice, do not use this function but rather
433  * operator/function projectProduct on MultiDimImplementation. This operator
434  * will take care to select this function if it is appropriate for your
435  * projection.
436  */
437  template < typename GUM_SCALAR >
438  GUM_SCALAR* projectProductMultiDimArray4Pointers(const MultiDimArray< GUM_SCALAR* >* table,
439  Instantiation* instantiation = 0);
440 
441  /**
442  * @brief a function for projecting a multiDimArray using a Product operator
443  * @ingroup multidim_op_group
444  *
445  * The function projects a table over all its variables and, thus, returns
446  * the product of the values stored in the table
447  *
448  * @return the product of the values stored in the multiDimArray
449  *
450  * @param table a pointer on the multidim table to be projected
451  *
452  * @param instantiation It shall always be 0 else instantiation is updated
453  * with a meaningless value. In addition, setting instantiation to a value
454  * different than 0 will induce more computations and thus will slow down the
455  * projection.
456  *
457  * @warning In practice, do not use this function but rather
458  * operator/function projectProduct on MultiDimImplementation. This operator
459  * will take care to select this function if it is appropriate for your
460  * projection.
461  */
462  template < typename GUM_SCALAR >
463  GUM_SCALAR*
464  projectProductMultiDimArray4Pointers(const MultiDimImplementation< GUM_SCALAR* >* table,
465  Instantiation* instantiation = 0);
466 
467  /// @}
468 
469  /// the function to be used to project a MultiDimImplementation using a Max
470  template < typename GUM_SCALAR >
471  GUM_SCALAR projectMax(const MultiDimImplementation< GUM_SCALAR >& table,
472  Instantiation* instantiation = 0);
473 
474  /// the function to be used to project a MultiDimImplementation using a Min
475  template < typename GUM_SCALAR >
476  GUM_SCALAR projectMin(const MultiDimImplementation< GUM_SCALAR >& table,
477  Instantiation* instantiation = 0);
478 
479  /// the function to be used to project a MultiDimImplementation using a sum
480  template < typename GUM_SCALAR >
481  GUM_SCALAR projectSum(const MultiDimImplementation< GUM_SCALAR >& table,
482  Instantiation* instantiation = 0);
483 
484  /// the function to be used to project a MultiDimImplementation using a
485  /// Product
486  template < typename GUM_SCALAR >
487  GUM_SCALAR projectProduct(const MultiDimImplementation< GUM_SCALAR >& table,
488  Instantiation* instantiation = 0);
489 
490  // ==========================================================================
491  // DO NOT FORGET TO REGISTER YOUR PROJECTION FUNCTIONS AT THE END OF FILE
492  // completeProjections4MultiDim_tpl.h
493  // ==========================================================================
494 
495  /**
496  * @brief the function used to register all the complete projection operators
497  * on multidimImplementations over non-pointers types.
498  * @ingroup multidim_op_group
499  */
500  template < typename GUM_SCALAR >
502 
503  /**
504  * @brief The function used to register all the complete projections on
505  * multidimImplementations over pointers types.
506  * @ingroup multidim_op_group
507  */
508  template < typename GUM_SCALAR >
510 
511  /**
512  * @brief a class used to register complete projections over non-pointers
513  * types
514  * @ingroup multidim_op_group
515  *
516  * This class is of course completely redundant with function
517  * completeProjections4MultiDimInit. Its aim is to enable specialization of
518  * function completeProjections4MultiDimInit for pointer types: C++ allows
519  * partial specialization of templated classes (e.g., create different
520  * implementations for C<T> and C<T*>) but it does not allows partial
521  * specialization for functions. Hence, by creating a class the primary
522  * purpose of which is to run function completeProjections4MultiDimInit, we
523  * allow this partial specialization. This is most effective to produce
524  * different codes for pointer types and non-pointer types.
525  */
526  template < typename GUM_SCALAR >
528  void init() { completeProjections4MultiDimInit< GUM_SCALAR >(); };
529  };
530 
531  /**
532  * @brief a class used to register complete projections over pointers types
533  * @ingroup multidim_op_group
534  *
535  * This class is of course completely redundant with function
536  * pointerCompleteProjections4MultiDimInit. Its aim is to enable different
537  * implementations of the projections for multidims depending in whether
538  * these multidim contain pointers or not. Actually, C++ allows partial
539  * specialization of templated classes (e.g., create different
540  * implementations for C<T> and C<T*>) but it does not allows partial
541  * specialization for functions. Hence, by creating a class the primary
542  * purpose of which is to run function completeProjections4MultiDimInit or
543  * pointerCompleteProjections4MultiDimInit, we allow this partial
544  * specialization to obtain.
545  * */
546  template < typename GUM_SCALAR >
548  void init() { pointerCompleteProjections4MultiDimInit< GUM_SCALAR >(); };
549  };
550 
551 } /* namespace gum */
552 
553 // always include the templatized implementations
554 #include <agrum/tools/multidim/utils/operators/completeProjections4MultiDim_tpl.h>
555 
556 #endif /* GUM_COMPLETE_PROJECTIONS_4_MULTI_DIM_H */
GUM_SCALAR projectProduct(const MultiDimImplementation< GUM_SCALAR > &table, Instantiation *instantiation=0)
the function to be used to project a MultiDimImplementation using a Product
GUM_SCALAR projectSumMultiDimArray(const MultiDimImplementation< GUM_SCALAR > *table, Instantiation *instantiation=0)
a specialized function for projecting a multiDimArray using a Sum operatorThe function projects a tab...
GUM_SCALAR projectProductMultiDimArray(const MultiDimImplementation< GUM_SCALAR > *table, Instantiation *instantiation=0)
a function for projecting a multiDimArray using a Product operatorThe function projects a table over ...
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
GUM_SCALAR * projectMaxMultiDimArray4Pointers(const MultiDimImplementation< GUM_SCALAR * > *table, Instantiation *instantiation=0)
A specialized function for projecting a multiDimArray using a Max operator.
GUM_SCALAR * projectMinMultiDimArray4Pointers(const MultiDimImplementation< GUM_SCALAR * > *table, Instantiation *instantiation=0)
A specialized function for projecting a multiDimArray using a Min operator.
GUM_SCALAR projectMaxMultiDimArray(const MultiDimImplementation< GUM_SCALAR > *table, Instantiation *instantiation=0)
A specialized function for projecting a multiDimArray using a Max operator.
void completeProjections4MultiDimInit()
the function used to register all the complete projection operators on multidimImplementations over n...
GUM_SCALAR * projectSumMultiDimArray4Pointers(const MultiDimImplementation< GUM_SCALAR * > *table, Instantiation *instantiation=0)
a specialized function for projecting a multiDimArray using a Sum operatorThe function projects a tab...
GUM_SCALAR projectSum(const MultiDimImplementation< GUM_SCALAR > &table, Instantiation *instantiation=0)
the function to be used to project a MultiDimImplementation using a sum
void pointerCompleteProjections4MultiDimInit()
The function used to register all the complete projections on multidimImplementations over pointers t...
GUM_SCALAR projectMinMultiDimArray(const MultiDimImplementation< GUM_SCALAR > *table, Instantiation *instantiation=0)
A specialized function for projecting a multiDimArray using a Min operator.
GUM_SCALAR projectMin(const MultiDimImplementation< GUM_SCALAR > &table, Instantiation *instantiation=0)
the function to be used to project a MultiDimImplementation using a Min
GUM_SCALAR projectMax(const MultiDimImplementation< GUM_SCALAR > &table, Instantiation *instantiation=0)
the function to be used to project a MultiDimImplementation using a Max
GUM_SCALAR * projectProductMultiDimArray4Pointers(const MultiDimImplementation< GUM_SCALAR * > *table, Instantiation *instantiation=0)
a function for projecting a multiDimArray using a Product operatorThe function projects a table over ...
a class used to register complete projections over non-pointers typesThis class is of course complete...