51#ifndef DOXYGEN_SHOULD_SKIP_THIS
62 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
66 TABLE_RES (*combine)(
const TABLE1&,
const TABLE2&),
67 const bool is_result_persistent) :
69 _arg1_(&table1), _arg2_(&table2), _combine_(combine) {
71 Sequence< const DiscreteVariable* > vars = table1.variablesSequence();
72 const Sequence< const DiscreteVariable* >& vars2 = table2.variablesSequence();
73 for (
const auto var: vars2) {
74 if (!vars.exists(var)) { vars.insert(var); }
79 _result_ =
new ScheduleMultiDim< TABLE_RES >(vars, Idx(0));
82 _args_ << _arg1_ << _arg2_;
83 _results_ << _result_;
86 GUM_CONSTRUCTOR(ScheduleBinaryCombination);
90 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
91 ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::ScheduleBinaryCombination(
92 const ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >& from) :
93 ScheduleOperator(from), _arg1_(from._arg1_), _arg2_(from._arg2_), _combine_(from._combine_) {
95 _result_ = from._result_->clone();
98 _args_ << _arg1_ << _arg2_;
99 _results_ << _result_;
102 GUM_CONS_CPY(ScheduleBinaryCombination);
106 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
107 ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::ScheduleBinaryCombination(
108 ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >&& from) :
109 ScheduleOperator(
std::move(from)), _arg1_(from._arg1_), _arg2_(from._arg2_),
110 _result_(from._result_), _combine_(from._combine_) {
112 from.makeResultsPersistent(
true);
113 from._result_ =
nullptr;
116 _args_ = std::move(from._args_);
117 _results_ << _result_;
120 GUM_CONS_MOV(ScheduleBinaryCombination);
124 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
125 ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >*
126 ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::clone()
const {
127 return new ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >(*
this);
131 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
132 ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::~ScheduleBinaryCombination() {
134 if (!this->hasPersistentResults()) {
delete _result_; }
137 GUM_DESTRUCTOR(ScheduleBinaryCombination);
141 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
142 ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >&
143 ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::operator=(
144 const ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >& from) {
147 *_result_ = *(from._result_);
148 ScheduleOperator::operator=(from);
150 _arg1_ = from._arg1_;
151 _arg2_ = from._arg2_;
152 _args_ = from._args_;
153 _combine_ = from._combine_;
159 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
160 ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >&
161 ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::operator=(
162 ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >&& from) {
164 if (!this->hasPersistentResults())
delete _result_;
165 _result_ = from._result_;
166 ScheduleOperator::operator=(std::move(from));
168 _arg1_ = from._arg1_;
169 _arg2_ = from._arg2_;
170 _args_ = std::move(from._args_);
171 _combine_ = from._combine_;
173 from.makeResultsPersistent(
true);
174 from._result_ =
nullptr;
180 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
181 bool ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::operator==(
182 const ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >& op)
const {
183 return (_combine_ == op._combine_) && (*_arg1_ == *op._arg1_) && (*_arg2_ == *op._arg2_);
187 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
188 bool ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::operator==(
189 const ScheduleOperator& op)
const {
190 if (ScheduleOperator::operator!=(op))
return false;
193 const ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >& real_op
194 =
dynamic_cast< const ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >&
>(op);
195 return ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::operator==(real_op);
196 }
catch (std::bad_cast&) {
return false; }
200 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
201 bool ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::operator!=(
202 const ScheduleOperator& op)
const {
203 return !ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::operator==(op);
207 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
208 bool ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::operator!=(
209 const ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >& op)
const {
210 return !ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::operator==(op);
214 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
215 bool ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::hasSameArguments(
216 const ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >& op)
const {
217 return (_arg1_->hasSameVariables(*op._arg1_) && _arg2_->hasSameVariables(*op._arg2_)
218 && _arg1_->hasSameContent(*op._arg1_) && _arg2_->hasSameContent(*op._arg2_));
222 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
223 bool ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::hasSameArguments(
224 const ScheduleOperator& op)
const {
226 const ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >& real_op
227 =
dynamic_cast< const ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >&
>(op);
228 return ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::hasSameArguments(real_op);
229 }
catch (std::bad_cast&) {
return false; }
233 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
234 bool ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::hasSimilarArguments(
235 const ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >& op)
const {
236 return (_arg1_->hasSameVariables(*op._arg1_) && _arg2_->hasSameVariables(*op._arg2_));
240 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
241 bool ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::hasSimilarArguments(
242 const ScheduleOperator& op)
const {
244 const ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >& real_op
245 =
dynamic_cast< const ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >&
>(op);
246 return ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::hasSimilarArguments(real_op);
247 }
catch (std::bad_cast&) {
return false; }
251 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
252 bool ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::isSameOperator(
253 const ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >& op)
const {
254 return _combine_ == op._combine_;
258 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
259 bool ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::isSameOperator(
260 const ScheduleOperator& op)
const {
262 const ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >& real_op
263 =
dynamic_cast< const ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >&
>(op);
264 return ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::isSameOperator(real_op);
265 }
catch (std::bad_cast&) {
return false; }
269 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
270 const ScheduleMultiDim< TABLE1 >&
271 ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::arg1()
const {
276 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
277 const ScheduleMultiDim< TABLE2 >&
278 ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::arg2()
const {
283 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
284 const Sequence< const IScheduleMultiDim* >&
285 ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::args()
const {
290 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
291 const ScheduleMultiDim< TABLE_RES >&
292 ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::result()
const {
297 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
298 const Sequence< const IScheduleMultiDim* >&
299 ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::results()
const {
304 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
305 void ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::updateArgs(
306 const Sequence< const IScheduleMultiDim* >& new_args) {
309 if (new_args.size() != Size(2)) {
311 "Method ScheduleBinaryCombination::updateArgs expects 2 new "
312 <<
"arguments, but " << new_args.size() <<
" were passed.");
314 const ScheduleMultiDim< TABLE1 >* arg1;
315 const ScheduleMultiDim< TABLE2 >* arg2;
317 arg1 =
dynamic_cast< const ScheduleMultiDim< TABLE1 >*
>(new_args[0]);
318 }
catch (std::bad_cast&) {
320 "The type of the first argument passed to "
321 <<
"ScheduleBinaryCombination::updateArgs does not match what "
322 <<
"the ScheduleOperator expects");
325 arg2 =
dynamic_cast< const ScheduleMultiDim< TABLE2 >*
>(new_args[1]);
326 }
catch (std::bad_cast&) {
328 "The type of the second argument passed to "
329 <<
"ScheduleBinaryCombination::updateArgs does not match what "
330 <<
"the ScheduleOperator expects");
336 _args_ = {_arg1_, _arg2_};
339 _result_->makeAbstract();
343 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
344 bool ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::isExecuted()
const {
345 return !_result_->isAbstract();
349 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
350 void ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::execute() {
351 if (_result_->isAbstract()) {
353 const TABLE1& t1 = _arg1_->multiDim();
354 const TABLE2& t2 = _arg2_->multiDim();
357 TABLE_RES res = _combine_(t1, t2);
358 _result_->setMultiDim(std::move(res));
363 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
364 void ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::undo() {
365 _result_->makeAbstract();
370 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
371 double ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::nbOperations()
const {
372 return double(_result_->domainSize());
376 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
377 std::pair< double, double >
378 ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::memoryUsage()
const {
380 =
double(_result_->domainSize()) * _result_->sizeOfContent() +
sizeof(TABLE_RES);
381 return {domsize, domsize};
385 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
386 std::string ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::toString()
const {
387 return _result_->toString() +
" = combine ( " + _arg1_->toString() +
" , " + _arg2_->toString()
392 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
393 void ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::setCombinationFunction(
394 TABLE_RES (*combine)(
const TABLE1&,
const TABLE2&)) {
396 _result_->makeAbstract();
ScheduleBinaryCombination(const ScheduleMultiDim< TABLE1 > &table1, const ScheduleMultiDim< TABLE2 > &table2, TABLE_RES(*combine)(const TABLE1 &, const TABLE2 &), const bool is_result_persistent=false)
default constructor
the base class for "low-level" operators used to schedule inferences
Exception : problem with size.
Exception : wrong type for this operation.
#define GUM_ERROR(type, msg)
gum is the global namespace for all aGrUM entities
ScheduleOperatorType
the currently supported types of "low-level" operators
@ COMBINE_MULTIDIM
combine 2 ScheduleMultiDims
a binary Combination operator class used for scheduling inferences