aGrUM
0.21.0
a C++ library for (probabilistic) graphical models
scheduleCombination_tpl.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
/** @file
23
* @brief A generic class to combine efficiently several ScheduleMultiDims
24
*
25
* @author Christophe GONZALES(@AMU) and Pierre-Henri WUILLEMIN(@LIP6)
26
*/
27
28
#
ifndef
DOXYGEN_SHOULD_SKIP_THIS
29
30
#
include
<
agrum
/
agrum
.
h
>
31
32
namespace
gum
{
33
34
/// constructor
35
template
<
typename
GUM_SCALAR >
36
ScheduleCombination< GUM_SCALAR >::ScheduleCombination() {
37
/// for debugging purposes
38
GUM_CONSTRUCTOR(ScheduleCombination);
39
}
40
41
/// copy constructor
42
template
<
typename
GUM_SCALAR
>
43
ScheduleCombination
<
GUM_SCALAR
>::
ScheduleCombination
(
44
const
ScheduleCombination
<
GUM_SCALAR
>&
from
) {
45
/// for debugging purposes
46
GUM_CONS_CPY
(
ScheduleCombination
);
47
}
48
49
/// destructor
50
template
<
typename
GUM_SCALAR
>
51
ScheduleCombination
<
GUM_SCALAR
>::~
ScheduleCombination
() {
52
/// for debugging purposes
53
GUM_DESTRUCTOR
(
ScheduleCombination
);
54
}
55
56
// adds to a given schedule the operations necessary to perform a combination
57
template
<
typename
GUM_SCALAR
>
58
ScheduleMultiDim
<
GUM_SCALAR
>
ScheduleCombination
<
GUM_SCALAR
>::
combine
(
59
const
Set
<
const
MultiDimImplementation
<
GUM_SCALAR
>* >&
set
,
60
Schedule
<
GUM_SCALAR
>&
schedule
) {
61
// first wrap the multidimimplementations into ScheduleMultiDims
62
Set
<
const
ScheduleMultiDim
<
GUM_SCALAR
>* >
sched_set
;
63
64
for
(
const
auto
pot
:
set
)
65
sched_set
.
insert
(
new
ScheduleMultiDim
<
GUM_SCALAR
>(*
pot
));
66
67
// perform the combination
68
const
ScheduleMultiDim
<
GUM_SCALAR
>&
res
=
combine
(
sched_set
,
schedule
);
69
70
// deallocate the wrappers we just constructed
71
for
(
const
auto
sched
:
sched_set
)
72
delete
sched
;
73
74
return
res
;
75
}
76
77
// adds to a given schedule the operations necessary to perform a combination
78
template
<
typename
GUM_SCALAR
>
79
template
<
template
<
typename
>
class
TABLE
>
80
ScheduleMultiDim
<
GUM_SCALAR
>
81
ScheduleCombination
<
GUM_SCALAR
>::
combine
(
const
Set
<
const
TABLE
<
GUM_SCALAR
>* >&
set
,
82
Schedule
<
GUM_SCALAR
>&
schedule
) {
83
// first wrap the TABLES into ScheduleMultiDims
84
Set
<
const
ScheduleMultiDim
<
GUM_SCALAR
>* >
sched_set
;
85
86
for
(
const
auto
tab
:
set
)
87
sched_set
.
insert
(
new
ScheduleMultiDim
<
GUM_SCALAR
>(*
tab
->
content
()));
88
89
// perform the combination
90
const
ScheduleMultiDim
<
GUM_SCALAR
>&
res
=
combine
(
sched_set
,
schedule
);
91
92
// deallocate the wrappers we just constructed
93
for
(
const
auto
sched
:
sched_set
)
94
delete
sched
;
95
96
return
res
;
97
}
98
99
/** @brief returns a rough estimate of the number of operations that will be
100
* performed to compute the combination */
101
template
<
typename
GUM_SCALAR
>
102
float
ScheduleCombination
<
GUM_SCALAR
>::
nbOperations
(
103
const
Set
<
const
MultiDimImplementation
<
GUM_SCALAR
>* >&
set
,
104
const
Schedule
<
GUM_SCALAR
>&
schedule
) {
105
// first wrap the multidimimplementations into ScheduleMultiDims
106
Set
<
const
ScheduleMultiDim
<
GUM_SCALAR
>* >
sched_set
;
107
108
for
(
const
auto
pot
:
set
)
109
sched_set
.
insert
(
new
ScheduleMultiDim
<
GUM_SCALAR
>(*
pot
));
110
111
// perform the combination
112
float
res
=
nbOperations
(
sched_set
,
schedule
);
113
114
// deallocate the wrappers we just constructed
115
for
(
const
auto
sched
:
sched_set
)
116
delete
sched
;
117
118
return
res
;
119
}
120
121
/** @brief returns a rough estimate of the number of operations that will be
122
* performed to compute the combination */
123
template
<
typename
GUM_SCALAR
>
124
template
<
template
<
typename
>
class
TABLE
>
125
float
126
ScheduleCombination
<
GUM_SCALAR
>::
nbOperations
(
const
Set
<
const
TABLE
<
GUM_SCALAR
>* >&
set
,
127
const
Schedule
<
GUM_SCALAR
>&
schedule
) {
128
// first wrap the TABLES into ScheduleMultiDims
129
Set
<
const
ScheduleMultiDim
<
GUM_SCALAR
>* >
sched_set
;
130
131
for
(
const
auto
tab
:
set
)
132
sched_set
.
insert
(
new
ScheduleMultiDim
<
GUM_SCALAR
>(*
tab
->
content
()));
133
134
// perform the combination
135
float
res
=
nbOperations
(
sched_set
,
schedule
);
136
137
// deallocate the wrappers we just constructed
138
for
(
const
auto
sched
:
sched_set
)
139
delete
sched
;
140
141
return
res
;
142
}
143
144
/// returns the memory consumption used during the combination
145
template
<
typename
GUM_SCALAR
>
146
std
::
pair
<
long
,
long
>
ScheduleCombination
<
GUM_SCALAR
>::
memoryUsage
(
147
const
Set
<
const
MultiDimImplementation
<
GUM_SCALAR
>* >&
set
,
148
const
Schedule
<
GUM_SCALAR
>&
schedule
) {
149
// first wrap the multidimimplementations into ScheduleMultiDims
150
Set
<
const
ScheduleMultiDim
<
GUM_SCALAR
>* >
sched_set
;
151
152
for
(
const
auto
pot
:
set
)
153
sched_set
.
insert
(
new
ScheduleMultiDim
<
GUM_SCALAR
>(*
pot
));
154
155
// compute the memory consumption of the combination
156
std
::
pair
<
long
,
long
>
res
=
memoryUsage
(
sched_set
,
schedule
);
157
158
// deallocate the wrappers we just constructed
159
for
(
const
auto
sched
:
sched_set
)
160
delete
sched
;
161
162
return
res
;
163
}
164
165
/** @brief returns a rough estimate of the number of operations that will be
166
* performed to compute the combination */
167
template
<
typename
GUM_SCALAR
>
168
template
<
template
<
typename
>
class
TABLE
>
169
std
::
pair
<
long
,
long
>
170
ScheduleCombination
<
GUM_SCALAR
>::
memoryUsage
(
const
Set
<
const
TABLE
<
GUM_SCALAR
>* >&
set
,
171
const
Schedule
<
GUM_SCALAR
>&
schedule
) {
172
// first wrap the TABLES into ScheduleMultiDims
173
Set
<
const
ScheduleMultiDim
<
GUM_SCALAR
>* >
sched_set
;
174
175
for
(
const
auto
tab
:
set
)
176
sched_set
.
insert
(
new
ScheduleMultiDim
<
GUM_SCALAR
>(*
tab
->
content
()));
177
178
// compute the memory consumption of the combination
179
std
::
pair
<
long
,
long
>
res
=
memoryUsage
(
sched_set
,
schedule
);
180
181
// deallocate the wrappers we just constructed
182
for
(
const
auto
sched
:
sched_set
)
183
delete
sched
;
184
185
return
res
;
186
}
187
188
}
/* namespace gum */
189
190
#
endif
/* DOXYGEN_SHOULD_SKIP_THIS */
gum::Set::emplace
INLINE void emplace(Args &&... args)
Definition:
set_tpl.h:643