aGrUM
0.20.2
a C++ library for (probabilistic) graphical models
scheduleDeleteMultiDim_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 MultiDim Delete operator class used for scheduling inferences
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
#
include
<
limits
>
32
33
// to ease ide parser
34
#
include
<
agrum
/
tools
/
graphicalModels
/
inference
/
scheduler
/
scheduleDeleteMultiDim
.
h
>
35
36
namespace
gum
{
37
38
/// default constructor
39
template
<
typename
GUM_SCALAR >
40
ScheduleDeleteMultiDim< GUM_SCALAR >::ScheduleDeleteMultiDim(
41
const
ScheduleMultiDim< GUM_SCALAR >& table) :
42
ScheduleOperation< GUM_SCALAR >(
43
ScheduleOperation< GUM_SCALAR >::Type::DELETE_MULTIDIM),
44
table__(table), args__(0) {
45
// for debugging purposes
46
GUM_CONSTRUCTOR(ScheduleDeleteMultiDim);
47
}
48
49
/// copy constructor
50
template
<
typename
GUM_SCALAR
>
51
ScheduleDeleteMultiDim
<
GUM_SCALAR
>::
ScheduleDeleteMultiDim
(
52
const
ScheduleDeleteMultiDim
<
GUM_SCALAR
>&
from
) :
53
ScheduleOperation
<
GUM_SCALAR
>(
from
),
54
table__
(
from
.
table__
),
args__
(0) {
55
// for debugging purposes
56
GUM_CONS_CPY
(
ScheduleDeleteMultiDim
);
57
}
58
59
/// virtual copy constructor: creates a clone of the operation
60
template
<
typename
GUM_SCALAR
>
61
ScheduleDeleteMultiDim
<
GUM_SCALAR
>*
62
ScheduleDeleteMultiDim
<
GUM_SCALAR
>::
newFactory
()
const
{
63
return
new
ScheduleDeleteMultiDim
<
GUM_SCALAR
>(*
this
);
64
}
65
66
/// destructor
67
template
<
typename
GUM_SCALAR
>
68
ScheduleDeleteMultiDim
<
GUM_SCALAR
>::~
ScheduleDeleteMultiDim
() {
69
// for debugging purposes
70
GUM_DESTRUCTOR
(
ScheduleDeleteMultiDim
);
71
72
if
(
args__
)
delete
args__
;
73
}
74
75
/// copy operator
76
template
<
typename
GUM_SCALAR
>
77
ScheduleDeleteMultiDim
<
GUM_SCALAR
>&
78
ScheduleDeleteMultiDim
<
GUM_SCALAR
>::
operator
=(
79
const
ScheduleDeleteMultiDim
<
GUM_SCALAR
>&
from
) {
80
// avoid self assignment
81
if
(&
from
!=
this
) {
82
ScheduleOperation
<
GUM_SCALAR
>::
operator
=(
from
);
83
table__
=
from
.
table__
;
84
85
if
(
args__
) {
86
args__
->
clear
();
87
args__
->
insert
(&
table__
);
88
}
89
}
90
91
return
*
this
;
92
}
93
94
/// operator ==
95
template
<
typename
GUM_SCALAR
>
96
bool
ScheduleDeleteMultiDim
<
GUM_SCALAR
>::
operator
==(
97
const
ScheduleOperation
<
GUM_SCALAR
>&
op
)
const
{
98
if
(
this
->
type
() !=
op
.
type
())
return
false
;
99
100
const
ScheduleDeleteMultiDim
<
GUM_SCALAR
>&
real_op
101
=
static_cast
<
const
ScheduleDeleteMultiDim
<
GUM_SCALAR
>& >(
op
);
102
return
table__
==
real_op
.
table__
;
103
}
104
105
/// operator !=
106
template
<
typename
GUM_SCALAR
>
107
bool
ScheduleDeleteMultiDim
<
GUM_SCALAR
>::
operator
!=(
108
const
ScheduleOperation
<
GUM_SCALAR
>&
op
)
const
{
109
if
(
this
->
type
() !=
op
.
type
())
return
true
;
110
111
const
ScheduleDeleteMultiDim
<
GUM_SCALAR
>&
real_op
112
=
static_cast
<
const
ScheduleDeleteMultiDim
<
GUM_SCALAR
>& >(
op
);
113
return
table__
!=
real_op
.
table__
;
114
}
115
116
/// executes the operation
117
template
<
typename
GUM_SCALAR
>
118
void
ScheduleDeleteMultiDim
<
GUM_SCALAR
>::
execute
() {
119
const
MultiDimImplementation
<
GUM_SCALAR
>&
multidim
=
table__
.
multiDim
();
120
ScheduleMultiDim
<
GUM_SCALAR
>::
multidim2id__
().
erase
(&
multidim
);
121
ScheduleMultiDim
<
GUM_SCALAR
>::
id2multidim__
().
erase
(
table__
.
id
());
122
delete
&
multidim
;
123
}
124
125
/** @brief returns an estimation of the number of elementary operations
126
* needed to perform the ScheduleOperation */
127
template
<
typename
GUM_SCALAR
>
128
INLINE
float
ScheduleDeleteMultiDim
<
GUM_SCALAR
>::
nbOperations
()
const
{
129
return
1.0f;
130
}
131
132
/// returns the memory consumption used during the operation
133
template
<
typename
GUM_SCALAR
>
134
INLINE
std
::
pair
<
long
,
long
>
135
ScheduleDeleteMultiDim
<
GUM_SCALAR
>::
memoryUsage
()
const
{
136
long
size_table
=
long
(
table__
.
domainSize
());
137
138
if
(
size_table
< 0) {
139
GUM_ERROR
(
OutOfBounds
,
"memory usage out of long int range"
);
140
}
141
142
return
std
::
pair
<
long
,
long
>(-
size_table
, -
size_table
);
143
}
144
145
/// returns the multidims to be deleted
146
template
<
typename
GUM_SCALAR
>
147
INLINE
const
Sequence
<
const
ScheduleMultiDim
<
GUM_SCALAR
>* >&
148
ScheduleDeleteMultiDim
<
GUM_SCALAR
>::
multiDimArgs
()
const
{
149
if
(!
args__
) {
150
args__
=
new
Sequence
<
const
ScheduleMultiDim
<
GUM_SCALAR
>* >;
151
args__
->
insert
(&
table__
);
152
}
153
154
return
*
args__
;
155
}
156
157
/// returns the set of multidims that should be the result of the operation
158
template
<
typename
GUM_SCALAR
>
159
INLINE
const
Sequence
<
const
ScheduleMultiDim
<
GUM_SCALAR
>* >&
160
ScheduleDeleteMultiDim
<
GUM_SCALAR
>::
multiDimResults
()
const
{
161
static
Sequence
<
const
ScheduleMultiDim
<
GUM_SCALAR
>* >
empty_seq
;
162
#
ifdef
GUM_DEBUG_MODE
163
// for debugging purposes, we should inform the aGrUM's debugger that
164
// the static sequence used here will be removed at the end of the
165
// program's execution.
166
static
bool
first_time
=
true
;
167
168
if
(
first_time
) {
169
first_time
=
false
;
170
__debug__
::
inc_deletion__
(
"Sequence"
,
171
__FILE__
,
172
__LINE__
,
173
"destructor of"
,
174
(
void
*)&
empty_seq
);
175
__debug__
::
inc_deletion__
(
"SequenceImplementation"
,
176
__FILE__
,
177
__LINE__
,
178
"destructor of"
,
179
(
void
*)&
empty_seq
);
180
__debug__
::
inc_deletion__
(
"HashTable"
,
181
__FILE__
,
182
__LINE__
,
183
"destructor of"
,
184
(
void
*)&
empty_seq
);
185
__debug__
::
inc_deletion__
(
"SequenceIteratorSafe"
,
186
__FILE__
,
187
__LINE__
,
188
"destructor of"
,
189
(
void
*)&
empty_seq
);
190
__debug__
::
inc_deletion__
(
"SequenceIteratorSafe"
,
191
__FILE__
,
192
__LINE__
,
193
"destructor of"
,
194
(
void
*)&
empty_seq
);
195
}
196
197
#
endif
/* GUM_DEBUG_MODE */
198
return
empty_seq
;
199
}
200
201
/// displays the content of the operation
202
template
<
typename
GUM_SCALAR
>
203
std
::
string
ScheduleDeleteMultiDim
<
GUM_SCALAR
>::
toString
()
const
{
204
return
"delete ( "
+
table__
.
toString
() +
" )"
;
205
}
206
207
}
// namespace gum
208
209
#
endif
/* DOXYGEN_SHOULD_SKIP_THIS */
gum::Set::emplace
INLINE void emplace(Args &&... args)
Definition:
set_tpl.h:669