aGrUM  0.14.2
scheduleProjectionBasic_tpl.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Pierre-Henri WUILLEMIN et Christophe GONZALES *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
28 #ifndef DOXYGEN_SHOULD_SKIP_THIS
29 
30 # include <agrum/agrum.h>
32 # include <limits>
33 
34 namespace gum {
35 
37  template < typename GUM_SCALAR >
39  MultiDimImplementation< GUM_SCALAR >* (*proj)(
40  const MultiDimImplementation< GUM_SCALAR >&,
41  const Set< const DiscreteVariable* >&)) :
42  ScheduleProjection< GUM_SCALAR >(),
43  _proj(proj) {
45  GUM_CONSTRUCTOR(ScheduleProjectionBasic);
46  }
47 
49  template < typename GUM_SCALAR >
51  const ScheduleProjectionBasic< GUM_SCALAR >& from) :
52  ScheduleProjection< GUM_SCALAR >(from),
53  _proj(from._proj) {
55  GUM_CONS_CPY(ScheduleProjectionBasic);
56  }
57 
59  template < typename GUM_SCALAR >
62  GUM_DESTRUCTOR(ScheduleProjectionBasic);
63  }
64 
66  template < typename GUM_SCALAR >
67  ScheduleProjectionBasic< GUM_SCALAR >*
69  return new ScheduleProjectionBasic< GUM_SCALAR >(*this);
70  }
71 
73  template < typename GUM_SCALAR >
74  ScheduleMultiDim< GUM_SCALAR > ScheduleProjectionBasic< GUM_SCALAR >::project(
75  const ScheduleMultiDim< GUM_SCALAR >& table,
76  const Set< const DiscreteVariable* >& del_vars,
77  Schedule< GUM_SCALAR >& schedule) {
78  // create the projection that will be performed later on
79  ScheduleProject< GUM_SCALAR > proj(table, del_vars, _proj);
80  schedule.insert(proj);
81 
82  return proj.result();
83  }
84 
86  template < typename GUM_SCALAR >
87  INLINE ScheduleMultiDim< GUM_SCALAR >
89  const MultiDimImplementation< GUM_SCALAR >& table,
90  const Set< const DiscreteVariable* >& del_vars,
91  Schedule< GUM_SCALAR >& schedule) {
92  return ScheduleProjection< GUM_SCALAR >::project(table, del_vars, schedule);
93  }
94 
96  template < typename GUM_SCALAR >
97  template < template < typename > class TABLE >
98  INLINE ScheduleMultiDim< GUM_SCALAR >
100  const TABLE< GUM_SCALAR >& table,
101  const Set< const DiscreteVariable* >& del_vars,
102  Schedule< GUM_SCALAR >& schedule) {
103  return ScheduleProjection< GUM_SCALAR >::project(table, del_vars, schedule);
104  }
105 
107  template < typename GUM_SCALAR >
109  MultiDimImplementation< GUM_SCALAR >* (*proj)(
110  const MultiDimImplementation< GUM_SCALAR >&,
111  const Set< const DiscreteVariable* >&)) {
112  _proj = proj;
113  }
114 
116  template < typename GUM_SCALAR >
117  INLINE MultiDimImplementation< GUM_SCALAR >* (
119  const MultiDimImplementation< GUM_SCALAR >&,
120  const Set< const DiscreteVariable* >&) {
121  return _proj;
122  }
123 
126  template < typename GUM_SCALAR >
128  const ScheduleMultiDim< GUM_SCALAR >& table,
129  const Set< const DiscreteVariable* >& del_vars,
130  const Schedule< GUM_SCALAR >& schedule) {
131  const Sequence< const DiscreteVariable* >& vars = table.variablesSequence();
132 
133  float res = 1.0f;
134 
135  for (const auto var : vars)
136  res *= var->domainSize();
137 
138  return res;
139  }
140 
143  template < typename GUM_SCALAR >
145  const MultiDimImplementation< GUM_SCALAR >& table,
146  const Set< const DiscreteVariable* >& del_vars,
147  const Schedule< GUM_SCALAR >& schedule) {
149  table, del_vars, schedule);
150  }
151 
154  template < typename GUM_SCALAR >
155  template < template < typename > class TABLE >
157  const TABLE< GUM_SCALAR >& table,
158  const Set< const DiscreteVariable* >& del_vars,
159  const Schedule< GUM_SCALAR >& schedule) {
161  table, del_vars, schedule);
162  }
163 
165  template < typename GUM_SCALAR >
167  const ScheduleMultiDim< GUM_SCALAR >& table,
168  const Set< const DiscreteVariable* >& del_vars,
169  const Schedule< GUM_SCALAR >& schedule) {
170  const Sequence< const DiscreteVariable* >& vars = table.variablesSequence();
171  long res = 1;
172 
173  for (const auto var : vars)
174  if (!del_vars.contains(var)) {
175  if (std::numeric_limits< long >::max() / (long)var->domainSize() < res) {
176  GUM_ERROR(OutOfBounds, "memory usage out of long int range");
177  }
178 
179  res *= long(var->domainSize());
180  }
181 
182  return std::pair< long, long >(res, res);
183  }
184 
186  template < typename GUM_SCALAR >
187  INLINE std::pair< long, long >
189  const MultiDimImplementation< GUM_SCALAR >& table,
190  const Set< const DiscreteVariable* >& del_vars,
191  const Schedule< GUM_SCALAR >& schedule) {
193  table, del_vars, schedule);
194  }
195 
197  template < typename GUM_SCALAR >
198  template < template < typename > class TABLE >
199  INLINE std::pair< long, long >
201  const TABLE< GUM_SCALAR >& table,
202  const Set< const DiscreteVariable* >& del_vars,
203  const Schedule< GUM_SCALAR >& schedule) {
205  table, del_vars, schedule);
206  }
207 
208 } /* namespace gum */
209 
210 #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
gum is the global namespace for all aGrUM entities
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
a Projection operator class used for scheduling inferences
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:52