aGrUM  0.16.0
scheduleCombination_tpl.h
Go to the documentation of this file.
1 
29 #ifndef DOXYGEN_SHOULD_SKIP_THIS
30 
31 # include <agrum/agrum.h>
32 
33 namespace gum {
34 
36  template < typename GUM_SCALAR >
39  GUM_CONSTRUCTOR(ScheduleCombination);
40  }
41 
43  template < typename GUM_SCALAR >
45  const ScheduleCombination< GUM_SCALAR >& from) {
47  GUM_CONS_CPY(ScheduleCombination);
48  }
49 
51  template < typename GUM_SCALAR >
54  GUM_DESTRUCTOR(ScheduleCombination);
55  }
56 
57  // adds to a given schedule the operations necessary to perform a combination
58  template < typename GUM_SCALAR >
59  ScheduleMultiDim< GUM_SCALAR > ScheduleCombination< GUM_SCALAR >::combine(
60  const Set< const MultiDimImplementation< GUM_SCALAR >* >& set,
61  Schedule< GUM_SCALAR >& schedule) {
62  // first wrap the multidimimplementations into ScheduleMultiDims
63  Set< const ScheduleMultiDim< GUM_SCALAR >* > sched_set;
64 
65  for (const auto pot : set)
66  sched_set.insert(new ScheduleMultiDim< GUM_SCALAR >(*pot));
67 
68  // perform the combination
69  const ScheduleMultiDim< GUM_SCALAR >& res = combine(sched_set, schedule);
70 
71  // deallocate the wrappers we just constructed
72  for (const auto sched : sched_set)
73  delete sched;
74 
75  return res;
76  }
77 
78  // adds to a given schedule the operations necessary to perform a combination
79  template < typename GUM_SCALAR >
80  template < template < typename > class TABLE >
81  ScheduleMultiDim< GUM_SCALAR > ScheduleCombination< GUM_SCALAR >::combine(
82  const Set< const TABLE< GUM_SCALAR >* >& set,
83  Schedule< GUM_SCALAR >& schedule) {
84  // first wrap the TABLES into ScheduleMultiDims
85  Set< const ScheduleMultiDim< GUM_SCALAR >* > sched_set;
86 
87  for (const auto tab : set)
88  sched_set.insert(new ScheduleMultiDim< GUM_SCALAR >(*tab->content()));
89 
90  // perform the combination
91  const ScheduleMultiDim< GUM_SCALAR >& res = combine(sched_set, schedule);
92 
93  // deallocate the wrappers we just constructed
94  for (const auto sched : sched_set)
95  delete sched;
96 
97  return res;
98  }
99 
102  template < typename GUM_SCALAR >
104  const Set< const MultiDimImplementation< GUM_SCALAR >* >& set,
105  const Schedule< GUM_SCALAR >& schedule) {
106  // first wrap the multidimimplementations into ScheduleMultiDims
107  Set< const ScheduleMultiDim< GUM_SCALAR >* > sched_set;
108 
109  for (const auto pot : set)
110  sched_set.insert(new ScheduleMultiDim< GUM_SCALAR >(*pot));
111 
112  // perform the combination
113  float res = nbOperations(sched_set, schedule);
114 
115  // deallocate the wrappers we just constructed
116  for (const auto sched : sched_set)
117  delete sched;
118 
119  return res;
120  }
121 
124  template < typename GUM_SCALAR >
125  template < template < typename > class TABLE >
127  const Set< const TABLE< GUM_SCALAR >* >& set,
128  const Schedule< GUM_SCALAR >& schedule) {
129  // first wrap the TABLES into ScheduleMultiDims
130  Set< const ScheduleMultiDim< GUM_SCALAR >* > sched_set;
131 
132  for (const auto tab : set)
133  sched_set.insert(new ScheduleMultiDim< GUM_SCALAR >(*tab->content()));
134 
135  // perform the combination
136  float res = nbOperations(sched_set, schedule);
137 
138  // deallocate the wrappers we just constructed
139  for (const auto sched : sched_set)
140  delete sched;
141 
142  return res;
143  }
144 
146  template < typename GUM_SCALAR >
147  std::pair< long, long > ScheduleCombination< GUM_SCALAR >::memoryUsage(
148  const Set< const MultiDimImplementation< GUM_SCALAR >* >& set,
149  const Schedule< GUM_SCALAR >& schedule) {
150  // first wrap the multidimimplementations into ScheduleMultiDims
151  Set< const ScheduleMultiDim< GUM_SCALAR >* > sched_set;
152 
153  for (const auto pot : set)
154  sched_set.insert(new ScheduleMultiDim< GUM_SCALAR >(*pot));
155 
156  // compute the memory consumption of the combination
157  std::pair< long, long > res = memoryUsage(sched_set, schedule);
158 
159  // deallocate the wrappers we just constructed
160  for (const auto sched : sched_set)
161  delete sched;
162 
163  return res;
164  }
165 
168  template < typename GUM_SCALAR >
169  template < template < typename > class TABLE >
170  std::pair< long, long > ScheduleCombination< GUM_SCALAR >::memoryUsage(
171  const Set< const TABLE< GUM_SCALAR >* >& set,
172  const Schedule< GUM_SCALAR >& schedule) {
173  // first wrap the TABLES into ScheduleMultiDims
174  Set< const ScheduleMultiDim< GUM_SCALAR >* > sched_set;
175 
176  for (const auto tab : set)
177  sched_set.insert(new ScheduleMultiDim< GUM_SCALAR >(*tab->content()));
178 
179  // compute the memory consumption of the combination
180  std::pair< long, long > res = memoryUsage(sched_set, schedule);
181 
182  // deallocate the wrappers we just constructed
183  for (const auto sched : sched_set)
184  delete sched;
185 
186  return res;
187  }
188 
189 } /* namespace gum */
190 
191 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
virtual float nbOperations(const Set< const ScheduleMultiDim< GUM_SCALAR > * > &set, const Schedule< GUM_SCALAR > &schedule)=0
returns a rough estimate of the number of operations that will be performed to compute the combinatio...
ScheduleCombination()
default constructor
virtual std::pair< long, long > memoryUsage(const Set< const ScheduleMultiDim< GUM_SCALAR > * > &set, const Schedule< GUM_SCALAR > &schedule)=0
returns the memory consumption used during the combination
virtual ScheduleMultiDim< GUM_SCALAR > combine(const Set< const ScheduleMultiDim< GUM_SCALAR > * > &set, Schedule< GUM_SCALAR > &schedule)=0
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
virtual ~ScheduleCombination()
destructor