49#ifndef DOXYGEN_SHOULD_SKIP_THIS
60 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
64 TABLE_RES (*combine)(
const TABLE1&,
const TABLE2&),
65 const bool is_result_persistent) :
67 _arg1_(&table1), _arg2_(&table2), _combine_(combine) {
69 Sequence< const DiscreteVariable* > vars = table1.variablesSequence();
70 const Sequence< const DiscreteVariable* >& vars2 = table2.variablesSequence();
71 for (
const auto var: vars2) {
72 if (!vars.exists(var)) { vars.insert(var); }
77 _result_ =
new ScheduleMultiDim< TABLE_RES >(vars, Idx(0));
80 _args_ << _arg1_ << _arg2_;
81 _results_ << _result_;
84 GUM_CONSTRUCTOR(ScheduleBinaryCombination);
88 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
89 ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::ScheduleBinaryCombination(
90 const ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >& from) :
91 ScheduleOperator(from), _arg1_(from._arg1_), _arg2_(from._arg2_), _combine_(from._combine_) {
93 _result_ = from._result_->clone();
96 _args_ << _arg1_ << _arg2_;
97 _results_ << _result_;
100 GUM_CONS_CPY(ScheduleBinaryCombination);
104 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
105 ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::ScheduleBinaryCombination(
106 ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >&& from) :
107 ScheduleOperator(
std::move(from)), _arg1_(from._arg1_), _arg2_(from._arg2_),
108 _result_(from._result_), _combine_(from._combine_) {
110 from.makeResultsPersistent(
true);
111 from._result_ =
nullptr;
114 _args_ = std::move(from._args_);
115 _results_ << _result_;
118 GUM_CONS_MOV(ScheduleBinaryCombination);
122 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
123 INLINE ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >*
124 ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::clone()
const {
125 return new ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >(*
this);
129 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
130 ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::~ScheduleBinaryCombination() {
132 if (!this->hasPersistentResults()) {
delete _result_; }
135 GUM_DESTRUCTOR(ScheduleBinaryCombination);
139 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
140 ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >&
141 ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::operator=(
142 const ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >& from) {
145 *_result_ = *(from._result_);
146 ScheduleOperator::operator=(from);
148 _arg1_ = from._arg1_;
149 _arg2_ = from._arg2_;
150 _args_ = from._args_;
151 _combine_ = from._combine_;
157 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
158 ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >&
159 ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::operator=(
160 ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >&& from) {
162 if (!this->hasPersistentResults())
delete _result_;
163 _result_ = from._result_;
164 ScheduleOperator::operator=(std::move(from));
166 _arg1_ = from._arg1_;
167 _arg2_ = from._arg2_;
168 _args_ = std::move(from._args_);
169 _combine_ = from._combine_;
171 from.makeResultsPersistent(
true);
172 from._result_ =
nullptr;
178 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
179 INLINE
bool ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::operator==(
180 const ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >& op)
const {
181 return (_combine_ == op._combine_) && (*_arg1_ == *op._arg1_) && (*_arg2_ == *op._arg2_);
185 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
186 bool ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::operator==(
187 const ScheduleOperator& op)
const {
188 if (ScheduleOperator::operator!=(op))
return false;
191 const ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >& real_op
192 =
dynamic_cast< const ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >&
>(op);
193 return ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::operator==(real_op);
194 }
catch (std::bad_cast&) {
return false; }
198 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
199 INLINE
bool ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::operator!=(
200 const ScheduleOperator& op)
const {
201 return !ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::operator==(op);
205 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
206 INLINE
bool ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::operator!=(
207 const ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >& op)
const {
208 return !ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::operator==(op);
212 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
213 INLINE
bool ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::hasSameArguments(
214 const ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >& op)
const {
215 return (_arg1_->hasSameVariables(*op._arg1_) && _arg2_->hasSameVariables(*op._arg2_)
216 && _arg1_->hasSameContent(*op._arg1_) && _arg2_->hasSameContent(*op._arg2_));
220 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
221 bool ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::hasSameArguments(
222 const ScheduleOperator& op)
const {
224 const ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >& real_op
225 =
dynamic_cast< const ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >&
>(op);
226 return ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::hasSameArguments(real_op);
227 }
catch (std::bad_cast&) {
return false; }
231 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
232 INLINE
bool ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::hasSimilarArguments(
233 const ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >& op)
const {
234 return (_arg1_->hasSameVariables(*op._arg1_) && _arg2_->hasSameVariables(*op._arg2_));
238 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
239 bool ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::hasSimilarArguments(
240 const ScheduleOperator& op)
const {
242 const ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >& real_op
243 =
dynamic_cast< const ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >&
>(op);
244 return ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::hasSimilarArguments(real_op);
245 }
catch (std::bad_cast&) {
return false; }
249 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
250 bool ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::isSameOperator(
251 const ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >& op)
const {
252 return _combine_ == op._combine_;
256 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
257 bool ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::isSameOperator(
258 const ScheduleOperator& op)
const {
260 const ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >& real_op
261 =
dynamic_cast< const ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >&
>(op);
262 return ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::isSameOperator(real_op);
263 }
catch (std::bad_cast&) {
return false; }
267 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
268 INLINE
const ScheduleMultiDim< TABLE1 >&
269 ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::arg1()
const {
274 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
275 INLINE
const ScheduleMultiDim< TABLE2 >&
276 ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::arg2()
const {
281 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
282 INLINE
const Sequence< const IScheduleMultiDim* >&
283 ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::args()
const {
288 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
289 INLINE
const ScheduleMultiDim< TABLE_RES >&
290 ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::result()
const {
295 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
296 INLINE
const Sequence< const IScheduleMultiDim* >&
297 ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::results()
const {
302 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
303 void ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::updateArgs(
304 const Sequence< const IScheduleMultiDim* >& new_args) {
307 if (new_args.size() != Size(2)) {
309 "Method ScheduleBinaryCombination::updateArgs expects 2 new "
310 <<
"arguments, but " << new_args.size() <<
" were passed.");
312 const ScheduleMultiDim< TABLE1 >* arg1;
313 const ScheduleMultiDim< TABLE2 >* arg2;
315 arg1 =
dynamic_cast< const ScheduleMultiDim< TABLE1 >*
>(new_args[0]);
316 }
catch (std::bad_cast&) {
318 "The type of the first argument passed to "
319 <<
"ScheduleBinaryCombination::updateArgs does not match what "
320 <<
"the ScheduleOperator expects");
323 arg2 =
dynamic_cast< const ScheduleMultiDim< TABLE2 >*
>(new_args[1]);
324 }
catch (std::bad_cast&) {
326 "The type of the second argument passed to "
327 <<
"ScheduleBinaryCombination::updateArgs does not match what "
328 <<
"the ScheduleOperator expects");
334 _args_ = {_arg1_, _arg2_};
337 _result_->makeAbstract();
341 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
342 INLINE
bool ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::isExecuted()
const {
343 return !_result_->isAbstract();
347 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
348 void ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::execute() {
349 if (_result_->isAbstract()) {
351 const TABLE1& t1 = _arg1_->multiDim();
352 const TABLE2& t2 = _arg2_->multiDim();
355 TABLE_RES res = _combine_(t1, t2);
356 _result_->setMultiDim(std::move(res));
361 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
362 void ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::undo() {
363 _result_->makeAbstract();
368 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
369 double ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::nbOperations()
const {
370 return double(_result_->domainSize());
374 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
375 INLINE std::pair< double, double >
376 ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::memoryUsage()
const {
378 =
double(_result_->domainSize()) * _result_->sizeOfContent() +
sizeof(TABLE_RES);
379 return {domsize, domsize};
383 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
384 std::string ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::toString()
const {
385 return _result_->toString() +
" = combine ( " + _arg1_->toString() +
" , " + _arg2_->toString()
390 template <
typename TABLE1,
typename TABLE2,
typename TABLE_RES >
391 void ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >::setCombinationFunction(
392 TABLE_RES (*combine)(
const TABLE1&,
const TABLE2&)) {
394 _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