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