aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
scheduleProjectionBasic_tpl.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright 2005-2020 Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
4  * info_at_agrum_dot_org
5  *
6  * This library is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 
22 /** @file
23  * @brief A generic class to project efficiently a ScheduleMultiDim over a
24  *subset
25  * of its variables
26  *
27  * @author Christophe GONZALES(@AMU) and Pierre-Henri WUILLEMIN(@LIP6)
28  */
29 
30 #ifndef DOXYGEN_SHOULD_SKIP_THIS
31 
32 # include <agrum/agrum.h>
33 # include <agrum/tools/graphicalModels/inference/scheduler/scheduleProject.h>
34 # include <limits>
35 
36 namespace gum {
37 
38  /// default constructor
39  template < typename GUM_SCALAR >
40  ScheduleProjectionBasic< GUM_SCALAR >::ScheduleProjectionBasic(
43  const Set< const DiscreteVariable* >&)) :
45  proj_(proj) {
46  /// for debugging purposes
48  }
49 
50  /// copy constructor
51  template < typename GUM_SCALAR >
55  proj_(from.proj_) {
56  /// for debugging purposes
58  }
59 
60  /// destructor
61  template < typename GUM_SCALAR >
63  /// for debugging purposes
65  }
66 
67  /// virtual constructor
68  template < typename GUM_SCALAR >
71  return new ScheduleProjectionBasic< GUM_SCALAR >(*this);
72  }
73 
74  /// creates and returns the projection of the table over a subset of its vars
75  template < typename GUM_SCALAR >
78  const Set< const DiscreteVariable* >& del_vars,
80  // create the projection that will be performed later on
83 
84  return proj.result();
85  }
86 
87  /// creates and returns the projection of the table over a subset of its vars
88  template < typename GUM_SCALAR >
92  const Set< const DiscreteVariable* >& del_vars,
95  }
96 
97  /// creates and returns the projection of the table over a subset of its vars
98  template < typename GUM_SCALAR >
99  template < template < typename > class TABLE >
102  const TABLE< GUM_SCALAR >& table,
103  const Set< const DiscreteVariable* >& del_vars,
106  }
107 
108  /// changes the function used for projecting tables
109  template < typename GUM_SCALAR >
113  const Set< const DiscreteVariable* >&)) {
114  proj_ = proj;
115  }
116 
117  /// returns the projection function currently used by the projector
118  template < typename GUM_SCALAR >
122  const Set< const DiscreteVariable* >&) {
123  return proj_;
124  }
125 
126  /** @brief returns a rough estimate of the number of operations that will be
127  * performed to compute the projection */
128  template < typename GUM_SCALAR >
131  const Set< const DiscreteVariable* >& del_vars,
132  const Schedule< GUM_SCALAR >& schedule) {
134 
135  float res = 1.0f;
136 
137  for (const auto var: vars)
138  res *= var->domainSize();
139 
140  return res;
141  }
142 
143  /** @brief returns a rough estimate of the number of operations that will be
144  * performed to compute the projection */
145  template < typename GUM_SCALAR >
148  const Set< const DiscreteVariable* >& del_vars,
149  const Schedule< GUM_SCALAR >& schedule) {
151  del_vars,
152  schedule);
153  }
154 
155  /** @brief returns a rough estimate of the number of operations that will be
156  * performed to compute the projection */
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  del_vars,
165  schedule);
166  }
167 
168  /// returns the memory consumption used during the projection
169  template < typename GUM_SCALAR >
172  const Set< const DiscreteVariable* >& del_vars,
173  const Schedule< GUM_SCALAR >& schedule) {
175  long res = 1;
176 
177  for (const auto var: vars)
178  if (!del_vars.contains(var)) {
179  if (std::numeric_limits< long >::max() / (long)var->domainSize() < res) {
180  GUM_ERROR(OutOfBounds, "memory usage out of long int range");
181  }
182 
183  res *= long(var->domainSize());
184  }
185 
186  return std::pair< long, long >(res, res);
187  }
188 
189  /// returns the memory consumption used during the projection
190  template < typename GUM_SCALAR >
191  INLINE std::pair< long, long >
194  const Set< const DiscreteVariable* >& del_vars,
195  const Schedule< GUM_SCALAR >& schedule) {
197  del_vars,
198  schedule);
199  }
200 
201  /// returns the memory consumption used during the projection
202  template < typename GUM_SCALAR >
203  template < template < typename > class TABLE >
204  INLINE std::pair< long, long >
206  const TABLE< GUM_SCALAR >& table,
207  const Set< const DiscreteVariable* >& del_vars,
208  const Schedule< GUM_SCALAR >& schedule) {
210  del_vars,
211  schedule);
212  }
213 
214 } /* namespace gum */
215 
216 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:669