aGrUM
0.20.3
a C++ library for (probabilistic) graphical models
sum_tpl.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
#
include
<
agrum
/
tools
/
multidim
/
aggregators
/
sum
.
h
>
30
31
namespace
gum
{
32
33
namespace
aggregator
{
34
template
<
typename
GUM_SCALAR >
35
INLINE Sum<
GUM_SCALAR
>::
Sum
() :
MultiDimAggregator
<
GUM_SCALAR
>() {
36
this
->
decomposable_
=
true
;
37
GUM_CONSTRUCTOR
(
Sum
);
38
}
39
40
template
<
typename
GUM_SCALAR
>
41
INLINE
Sum
<
GUM_SCALAR
>::
Sum
(
const
Sum
<
GUM_SCALAR
>&
from
) :
42
MultiDimAggregator
<
GUM_SCALAR
>(
from
) {
43
GUM_CONS_CPY
(
Sum
);
44
}
45
46
template
<
typename
GUM_SCALAR
>
47
INLINE
Sum
<
GUM_SCALAR
>::~
Sum
() {
48
GUM_DESTRUCTOR
(
Sum
);
49
}
50
51
template
<
typename
GUM_SCALAR
>
52
INLINE
Idx
Sum
<
GUM_SCALAR
>::
neutralElt_
()
const
{
53
return
(
Idx
)0;
54
}
55
56
template
<
typename
GUM_SCALAR
>
57
INLINE
Idx
Sum
<
GUM_SCALAR
>::
fold_
(
const
DiscreteVariable
&
v
,
58
Idx
i1
,
59
Idx
i2
,
60
bool
&
stop_iteration
)
const
{
61
GUM_SCALAR
max_val
62
=
this
->
variable
((
Idx
)0).
numerical
(
this
->
variable
((
Idx
)0).
domainSize
() - 1);
63
if
((
i1
+
i2
) >
max_val
) {
64
stop_iteration
=
true
;
65
return
(
Idx
)
max_val
;
66
}
67
return
i1
+
i2
;
68
}
69
70
template
<
typename
GUM_SCALAR
>
71
INLINE
std
::
string
Sum
<
GUM_SCALAR
>::
aggregatorName
()
const
{
72
return
"sum"
;
73
}
74
75
template
<
typename
GUM_SCALAR
>
76
INLINE
MultiDimContainer
<
GUM_SCALAR
>*
Sum
<
GUM_SCALAR
>::
newFactory
()
const
{
77
return
new
Sum
<
GUM_SCALAR
>;
78
}
79
80
}
// namespace aggregator
81
}
// namespace gum
gum::Set::emplace
INLINE void emplace(Args &&... args)
Definition:
set_tpl.h:643
gum::aggregator::operator<<
INLINE std::ostream & operator<<(std::ostream &s, const MultiDimAggregator< GUM_SCALAR > &ag)
For friendly displaying the content of the array.
Definition:
multiDimAggregator_tpl.h:135