aGrUM  0.16.0
scheduleProjectionBasic_tpl.h
Go to the documentation of this file.
1 
31 #ifndef DOXYGEN_SHOULD_SKIP_THIS
32 
33 # include <agrum/agrum.h>
35 # include <limits>
36 
37 namespace gum {
38 
40  template < typename GUM_SCALAR >
42  MultiDimImplementation< GUM_SCALAR >* (*proj)(
43  const MultiDimImplementation< GUM_SCALAR >&,
44  const Set< const DiscreteVariable* >&)) :
45  ScheduleProjection< GUM_SCALAR >(),
46  _proj(proj) {
48  GUM_CONSTRUCTOR(ScheduleProjectionBasic);
49  }
50 
52  template < typename GUM_SCALAR >
54  const ScheduleProjectionBasic< GUM_SCALAR >& from) :
55  ScheduleProjection< GUM_SCALAR >(from),
56  _proj(from._proj) {
58  GUM_CONS_CPY(ScheduleProjectionBasic);
59  }
60 
62  template < typename GUM_SCALAR >
65  GUM_DESTRUCTOR(ScheduleProjectionBasic);
66  }
67 
69  template < typename GUM_SCALAR >
70  ScheduleProjectionBasic< GUM_SCALAR >*
72  return new ScheduleProjectionBasic< GUM_SCALAR >(*this);
73  }
74 
76  template < typename GUM_SCALAR >
77  ScheduleMultiDim< GUM_SCALAR > ScheduleProjectionBasic< GUM_SCALAR >::project(
78  const ScheduleMultiDim< GUM_SCALAR >& table,
79  const Set< const DiscreteVariable* >& del_vars,
80  Schedule< GUM_SCALAR >& schedule) {
81  // create the projection that will be performed later on
82  ScheduleProject< GUM_SCALAR > proj(table, del_vars, _proj);
83  schedule.insert(proj);
84 
85  return proj.result();
86  }
87 
89  template < typename GUM_SCALAR >
90  INLINE ScheduleMultiDim< GUM_SCALAR >
92  const MultiDimImplementation< GUM_SCALAR >& table,
93  const Set< const DiscreteVariable* >& del_vars,
94  Schedule< GUM_SCALAR >& schedule) {
95  return ScheduleProjection< GUM_SCALAR >::project(table, del_vars, schedule);
96  }
97 
99  template < typename GUM_SCALAR >
100  template < template < typename > class TABLE >
101  INLINE ScheduleMultiDim< GUM_SCALAR >
103  const TABLE< GUM_SCALAR >& table,
104  const Set< const DiscreteVariable* >& del_vars,
105  Schedule< GUM_SCALAR >& schedule) {
106  return ScheduleProjection< GUM_SCALAR >::project(table, del_vars, schedule);
107  }
108 
110  template < typename GUM_SCALAR >
112  MultiDimImplementation< GUM_SCALAR >* (*proj)(
113  const MultiDimImplementation< GUM_SCALAR >&,
114  const Set< const DiscreteVariable* >&)) {
115  _proj = proj;
116  }
117 
119  template < typename GUM_SCALAR >
120  INLINE MultiDimImplementation< GUM_SCALAR >* (
122  const MultiDimImplementation< GUM_SCALAR >&,
123  const Set< const DiscreteVariable* >&) {
124  return _proj;
125  }
126 
129  template < typename GUM_SCALAR >
131  const ScheduleMultiDim< GUM_SCALAR >& table,
132  const Set< const DiscreteVariable* >& del_vars,
133  const Schedule< GUM_SCALAR >& schedule) {
134  const Sequence< const DiscreteVariable* >& vars = table.variablesSequence();
135 
136  float res = 1.0f;
137 
138  for (const auto var : vars)
139  res *= var->domainSize();
140 
141  return res;
142  }
143 
146  template < typename GUM_SCALAR >
148  const MultiDimImplementation< GUM_SCALAR >& table,
149  const Set< const DiscreteVariable* >& del_vars,
150  const Schedule< GUM_SCALAR >& schedule) {
152  table, del_vars, schedule);
153  }
154 
157  template < typename GUM_SCALAR >
158  template < template < typename > class TABLE >
160  const TABLE< GUM_SCALAR >& table,
161  const Set< const DiscreteVariable* >& del_vars,
162  const Schedule< GUM_SCALAR >& schedule) {
164  table, del_vars, schedule);
165  }
166 
168  template < typename GUM_SCALAR >
170  const ScheduleMultiDim< GUM_SCALAR >& table,
171  const Set< const DiscreteVariable* >& del_vars,
172  const Schedule< GUM_SCALAR >& schedule) {
173  const Sequence< const DiscreteVariable* >& vars = table.variablesSequence();
174  long res = 1;
175 
176  for (const auto var : vars)
177  if (!del_vars.contains(var)) {
178  if (std::numeric_limits< long >::max() / (long)var->domainSize() < res) {
179  GUM_ERROR(OutOfBounds, "memory usage out of long int range");
180  }
181 
182  res *= long(var->domainSize());
183  }
184 
185  return std::pair< long, long >(res, res);
186  }
187 
189  template < typename GUM_SCALAR >
190  INLINE std::pair< long, long >
192  const MultiDimImplementation< GUM_SCALAR >& table,
193  const Set< const DiscreteVariable* >& del_vars,
194  const Schedule< GUM_SCALAR >& schedule) {
196  table, del_vars, schedule);
197  }
198 
200  template < typename GUM_SCALAR >
201  template < template < typename > class TABLE >
202  INLINE std::pair< long, long >
204  const TABLE< GUM_SCALAR >& table,
205  const Set< const DiscreteVariable* >& del_vars,
206  const Schedule< GUM_SCALAR >& schedule) {
208  table, del_vars, schedule);
209  }
210 
211 } /* namespace gum */
212 
213 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
MultiDimImplementation< GUM_SCALAR > *(* _proj)(const MultiDimImplementation< GUM_SCALAR > &, const Set< const DiscreteVariable * > &)
the projection function actually used
ScheduleProjection()
default constructor
virtual float nbOperations(const ScheduleMultiDim< GUM_SCALAR > &table, const Set< const DiscreteVariable * > &del_vars, const Schedule< GUM_SCALAR > &schedule)
returns a rough estimate of the number of operations that will be performed to compute the projection...
ScheduleProjectionBasic(MultiDimImplementation< GUM_SCALAR > *(*proj)(const MultiDimImplementation< GUM_SCALAR > &, const Set< const DiscreteVariable * > &))
default constructor
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Definition: agrum.h:25
virtual ~ScheduleProjectionBasic()
destructor
void setProjectFunction(MultiDimImplementation< GUM_SCALAR > *(*proj)(const MultiDimImplementation< GUM_SCALAR > &, const Set< const DiscreteVariable * > &))
changes the function used for projecting tables
virtual float nbOperations(const ScheduleMultiDim< GUM_SCALAR > &table, const Set< const DiscreteVariable * > &del_vars, const Schedule< GUM_SCALAR > &schedule)=0
returns a rough estimate of the number of operations that will be performed to compute the projection...
ScheduleMultiDim< GUM_SCALAR > project(const ScheduleMultiDim< GUM_SCALAR > &table, const Set< const DiscreteVariable * > &del_vars, Schedule< GUM_SCALAR > &schedule)
creates and returns the projection of the table over a subset of its vars
MultiDimImplementation< GUM_SCALAR > *(*)(const MultiDimImplementation< GUM_SCALAR > &, const Set< const DiscreteVariable *> &) projectFunction()
returns the projection function currently used by the projector
virtual std::pair< long, long > memoryUsage(const ScheduleMultiDim< GUM_SCALAR > &table, const Set< const DiscreteVariable * > &del_vars, const Schedule< GUM_SCALAR > &schedule)=0
returns the memory consumption used during the projection
virtual ScheduleMultiDim< GUM_SCALAR > project(const ScheduleMultiDim< GUM_SCALAR > &table, const Set< const DiscreteVariable * > &del_vars, Schedule< GUM_SCALAR > &schedule)=0
creates and returns the projection of the table over a subset of its vars
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
virtual std::pair< long, long > memoryUsage(const ScheduleMultiDim< GUM_SCALAR > &table, const Set< const DiscreteVariable * > &del_vars, const Schedule< GUM_SCALAR > &schedule)
returns the memory consumption used during the projection
virtual ScheduleProjectionBasic< GUM_SCALAR > * newFactory() const
virtual constructor
#define GUM_ERROR(type, msg)
Definition: exceptions.h:55