aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
sum.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6)
4  * {prenom.nom}_at_lip6.fr
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 sum aggregator
25  *
26  * @author Gaspard DUCAMP
27  */
28 
29 #ifndef GUM_SUM_AGGREGATOR_H
30 #define GUM_SUM_AGGREGATOR_H
31 
32 #include <agrum/tools/multidim/aggregators/multiDimAggregator.h>
33 
34 namespace gum {
35 
36  namespace aggregator {
37  // =========================================================================
38  // === GUM_SUM_AGGREGATOR ===
39  // =========================================================================
40 
41  /**
42  * @class Sum
43  * @headerfile sum.h <agrum/multidim/aggregators/sum.h>
44  * @ingroup multidim_agg_group
45  *
46  * @brief Sum aggregator
47  *
48  * @see MultiDimAggregator for more details of implementations
49  */
50  template < typename GUM_SCALAR >
51  class Sum: public MultiDimAggregator< GUM_SCALAR > {
52  public:
53  Sum();
54  Sum(const Sum< GUM_SCALAR >& from);
55  virtual ~Sum();
56 
57  /**
58  * This method creates a clone of this object, without its content
59  * (including variable), you must use this method if you want to ensure
60  * that the generated object has the same type than the object containing
61  * the called newFactory()
62  *
63  * For example :
64  * @code
65  * MultiDimArray<double> y;
66  * MultiDimContainer<double>* x = y.newFactory();
67  * @endcode
68  *
69  * Then x is a MultiDimArray<double>*
70  *
71  * @warning you must desallocate by yourself the memory
72  * @return an empty clone of this object with the same type
73  */
74  virtual MultiDimContainer< GUM_SCALAR >* newFactory() const;
75 
76  virtual std::string aggregatorName() const;
77 
78  protected:
79  virtual Idx neutralElt_() const;
80  virtual Idx fold_(const DiscreteVariable& v, Idx i1, Idx i2, bool& stop_iteration) const;
81 
82  private:
84  };
85 
86 
87 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
88  extern template class Sum< double >;
89 #endif
90 
91 
92  } // namespace aggregator
93 } // namespace gum
94 
95 #include <agrum/tools/multidim/aggregators/sum_tpl.h>
96 
97 #endif // GUM_SUM_AGGREGATOR_H
Sum aggregator.
Definition: sum.h:51
virtual MultiDimContainer< GUM_SCALAR > * newFactory() const
This method creates a clone of this object, without its content (including variable), you must use this method if you want to ensure that the generated object has the same type than the object containing the called newFactory()
Definition: sum_tpl.h:76
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
virtual std::string aggregatorName() const
Definition: sum_tpl.h:71
Sum(const Sum< GUM_SCALAR > &from)
Definition: sum_tpl.h:41
virtual Idx neutralElt_() const
neutralElt_() is the result value for the first application of fold_
Definition: sum_tpl.h:52
virtual ~Sum()
Definition: sum_tpl.h:47
INLINE std::ostream & operator<<(std::ostream &s, const MultiDimAggregator< GUM_SCALAR > &ag)
For friendly displaying the content of the array.
virtual Idx fold_(const DiscreteVariable &v, Idx i1, Idx i2, bool &stop_iteration) const
fold_ is applied on value i1 for variable v. the actual result for precedent applications is i2...
Definition: sum_tpl.h:57