aGrUM
0.20.2
a C++ library for (probabilistic) graphical models
scheduleProjectionBasic_tpl.h
Go to the documentation of this file.
1
/**
2
*
3
* Copyright 2005-2020 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 project efficiently a ScheduleMultiDim over a
24
*subset
25
* of its variables
26
*
27
* @author Christophe GONZALES(@AMU) and Pierre-Henri WUILLEMIN(@LIP6)
28
*/
29
30
#
ifndef
DOXYGEN_SHOULD_SKIP_THIS
31
32
#
include
<
agrum
/
agrum
.
h
>
33
#
include
<
agrum
/
tools
/
graphicalModels
/
inference
/
scheduler
/
scheduleProject
.
h
>
34
#
include
<
limits
>
35
36
namespace
gum
{
37
38
/// default constructor
39
template
<
typename
GUM_SCALAR >
40
ScheduleProjectionBasic< GUM_SCALAR >::ScheduleProjectionBasic(
41
MultiDimImplementation
<
GUM_SCALAR
>* (*
proj
)(
42
const
MultiDimImplementation
<
GUM_SCALAR
>&,
43
const
Set
<
const
DiscreteVariable
* >&)) :
44
ScheduleProjection
<
GUM_SCALAR
>(),
45
proj_
(
proj
) {
46
/// for debugging purposes
47
GUM_CONSTRUCTOR
(
ScheduleProjectionBasic
);
48
}
49
50
/// copy constructor
51
template
<
typename
GUM_SCALAR
>
52
ScheduleProjectionBasic
<
GUM_SCALAR
>::
ScheduleProjectionBasic
(
53
const
ScheduleProjectionBasic
<
GUM_SCALAR
>&
from
) :
54
ScheduleProjection
<
GUM_SCALAR
>(
from
),
55
proj_
(
from
.
proj_
) {
56
/// for debugging purposes
57
GUM_CONS_CPY
(
ScheduleProjectionBasic
);
58
}
59
60
/// destructor
61
template
<
typename
GUM_SCALAR
>
62
ScheduleProjectionBasic
<
GUM_SCALAR
>::~
ScheduleProjectionBasic
() {
63
/// for debugging purposes
64
GUM_DESTRUCTOR
(
ScheduleProjectionBasic
);
65
}
66
67
/// virtual constructor
68
template
<
typename
GUM_SCALAR
>
69
ScheduleProjectionBasic
<
GUM_SCALAR
>*
70
ScheduleProjectionBasic
<
GUM_SCALAR
>::
newFactory
()
const
{
71
return
new
ScheduleProjectionBasic
<
GUM_SCALAR
>(*
this
);
72
}
73
74
/// creates and returns the projection of the table over a subset of its vars
75
template
<
typename
GUM_SCALAR
>
76
ScheduleMultiDim
<
GUM_SCALAR
>
ScheduleProjectionBasic
<
GUM_SCALAR
>::
project
(
77
const
ScheduleMultiDim
<
GUM_SCALAR
>&
table
,
78
const
Set
<
const
DiscreteVariable
* >&
del_vars
,
79
Schedule
<
GUM_SCALAR
>&
schedule
) {
80
// create the projection that will be performed later on
81
ScheduleProject
<
GUM_SCALAR
>
proj
(
table
,
del_vars
,
proj_
);
82
schedule
.
insert
(
proj
);
83
84
return
proj
.
result
();
85
}
86
87
/// creates and returns the projection of the table over a subset of its vars
88
template
<
typename
GUM_SCALAR
>
89
INLINE
ScheduleMultiDim
<
GUM_SCALAR
>
90
ScheduleProjectionBasic
<
GUM_SCALAR
>::
project
(
91
const
MultiDimImplementation
<
GUM_SCALAR
>&
table
,
92
const
Set
<
const
DiscreteVariable
* >&
del_vars
,
93
Schedule
<
GUM_SCALAR
>&
schedule
) {
94
return
ScheduleProjection
<
GUM_SCALAR
>::
project
(
table
,
del_vars
,
schedule
);
95
}
96
97
/// creates and returns the projection of the table over a subset of its vars
98
template
<
typename
GUM_SCALAR
>
99
template
<
template
<
typename
>
class
TABLE
>
100
INLINE
ScheduleMultiDim
<
GUM_SCALAR
>
101
ScheduleProjectionBasic
<
GUM_SCALAR
>::
project
(
102
const
TABLE
<
GUM_SCALAR
>&
table
,
103
const
Set
<
const
DiscreteVariable
* >&
del_vars
,
104
Schedule
<
GUM_SCALAR
>&
schedule
) {
105
return
ScheduleProjection
<
GUM_SCALAR
>::
project
(
table
,
del_vars
,
schedule
);
106
}
107
108
/// changes the function used for projecting tables
109
template
<
typename
GUM_SCALAR
>
110
void
ScheduleProjectionBasic
<
GUM_SCALAR
>::
setProjectFunction
(
111
MultiDimImplementation
<
GUM_SCALAR
>* (*
proj
)(
112
const
MultiDimImplementation
<
GUM_SCALAR
>&,
113
const
Set
<
const
DiscreteVariable
* >&)) {
114
proj_
=
proj
;
115
}
116
117
/// returns the projection function currently used by the projector
118
template
<
typename
GUM_SCALAR
>
119
INLINE
MultiDimImplementation
<
GUM_SCALAR
>* (
120
*
ScheduleProjectionBasic
<
GUM_SCALAR
>::
projectFunction
())(
121
const
MultiDimImplementation
<
GUM_SCALAR
>&,
122
const
Set
<
const
DiscreteVariable
* >&) {
123
return
proj_
;
124
}
125
126
/** @brief returns a rough estimate of the number of operations that will be
127
* performed to compute the projection */
128
template
<
typename
GUM_SCALAR
>
129
float
ScheduleProjectionBasic
<
GUM_SCALAR
>::
nbOperations
(
130
const
ScheduleMultiDim
<
GUM_SCALAR
>&
table
,
131
const
Set
<
const
DiscreteVariable
* >&
del_vars
,
132
const
Schedule
<
GUM_SCALAR
>&
schedule
) {
133
const
Sequence
<
const
DiscreteVariable
* >&
vars
=
table
.
variablesSequence
();
134
135
float
res
= 1.0f;
136
137
for
(
const
auto
var
:
vars
)
138
res
*=
var
->
domainSize
();
139
140
return
res
;
141
}
142
143
/** @brief returns a rough estimate of the number of operations that will be
144
* performed to compute the projection */
145
template
<
typename
GUM_SCALAR
>
146
INLINE
float
ScheduleProjectionBasic
<
GUM_SCALAR
>::
nbOperations
(
147
const
MultiDimImplementation
<
GUM_SCALAR
>&
table
,
148
const
Set
<
const
DiscreteVariable
* >&
del_vars
,
149
const
Schedule
<
GUM_SCALAR
>&
schedule
) {
150
return
ScheduleProjection
<
GUM_SCALAR
>::
nbOperations
(
table
,
151
del_vars
,
152
schedule
);
153
}
154
155
/** @brief returns a rough estimate of the number of operations that will be
156
* performed to compute the projection */
157
template
<
typename
GUM_SCALAR
>
158
template
<
template
<
typename
>
class
TABLE
>
159
INLINE
float
ScheduleProjectionBasic
<
GUM_SCALAR
>::
nbOperations
(
160
const
TABLE
<
GUM_SCALAR
>&
table
,
161
const
Set
<
const
DiscreteVariable
* >&
del_vars
,
162
const
Schedule
<
GUM_SCALAR
>&
schedule
) {
163
return
ScheduleProjection
<
GUM_SCALAR
>::
nbOperations
(
table
,
164
del_vars
,
165
schedule
);
166
}
167
168
/// returns the memory consumption used during the projection
169
template
<
typename
GUM_SCALAR
>
170
std
::
pair
<
long
,
long
>
ScheduleProjectionBasic
<
GUM_SCALAR
>::
memoryUsage
(
171
const
ScheduleMultiDim
<
GUM_SCALAR
>&
table
,
172
const
Set
<
const
DiscreteVariable
* >&
del_vars
,
173
const
Schedule
<
GUM_SCALAR
>&
schedule
) {
174
const
Sequence
<
const
DiscreteVariable
* >&
vars
=
table
.
variablesSequence
();
175
long
res
= 1;
176
177
for
(
const
auto
var
:
vars
)
178
if
(!
del_vars
.
contains
(
var
)) {
179
if
(
std
::
numeric_limits
<
long
>::
max
() / (
long
)
var
->
domainSize
() <
res
) {
180
GUM_ERROR
(
OutOfBounds
,
"memory usage out of long int range"
);
181
}
182
183
res
*=
long
(
var
->
domainSize
());
184
}
185
186
return
std
::
pair
<
long
,
long
>(
res
,
res
);
187
}
188
189
/// returns the memory consumption used during the projection
190
template
<
typename
GUM_SCALAR
>
191
INLINE
std
::
pair
<
long
,
long
>
192
ScheduleProjectionBasic
<
GUM_SCALAR
>::
memoryUsage
(
193
const
MultiDimImplementation
<
GUM_SCALAR
>&
table
,
194
const
Set
<
const
DiscreteVariable
* >&
del_vars
,
195
const
Schedule
<
GUM_SCALAR
>&
schedule
) {
196
return
ScheduleProjection
<
GUM_SCALAR
>::
memoryUsage
(
table
,
197
del_vars
,
198
schedule
);
199
}
200
201
/// returns the memory consumption used during the projection
202
template
<
typename
GUM_SCALAR
>
203
template
<
template
<
typename
>
class
TABLE
>
204
INLINE
std
::
pair
<
long
,
long
>
205
ScheduleProjectionBasic
<
GUM_SCALAR
>::
memoryUsage
(
206
const
TABLE
<
GUM_SCALAR
>&
table
,
207
const
Set
<
const
DiscreteVariable
* >&
del_vars
,
208
const
Schedule
<
GUM_SCALAR
>&
schedule
) {
209
return
ScheduleProjection
<
GUM_SCALAR
>::
memoryUsage
(
table
,
210
del_vars
,
211
schedule
);
212
}
213
214
}
/* namespace gum */
215
216
#
endif
/* DOXYGEN_SHOULD_SKIP_THIS */
gum::Set::emplace
INLINE void emplace(Args &&... args)
Definition:
set_tpl.h:669