aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
scheduleProjectionBasic_tpl.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright (c) 2005-2021 by 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(
42  const Set< const DiscreteVariable* >&)) :
44  proj_(proj) {
45  /// for debugging purposes
47  }
48 
49  /// copy constructor
50  template < typename GUM_SCALAR >
54  proj_(from.proj_) {
55  /// for debugging purposes
57  }
58 
59  /// destructor
60  template < typename GUM_SCALAR >
62  /// for debugging purposes
64  }
65 
66  /// virtual constructor
67  template < typename GUM_SCALAR >
69  return new ScheduleProjectionBasic< GUM_SCALAR >(*this);
70  }
71 
72  /// creates and returns the projection of the table over a subset of its vars
73  template < typename GUM_SCALAR >
76  const Set< const DiscreteVariable* >& del_vars,
78  // create the projection that will be performed later on
81 
82  return proj.result();
83  }
84 
85  /// creates and returns the projection of the table over a subset of its vars
86  template < typename GUM_SCALAR >
89  const Set< const DiscreteVariable* >& del_vars,
92  }
93 
94  /// creates and returns the projection of the table over a subset of its vars
95  template < typename GUM_SCALAR >
96  template < template < typename > class TABLE >
99  const Set< const DiscreteVariable* >& del_vars,
102  }
103 
104  /// changes the function used for projecting tables
105  template < typename GUM_SCALAR >
108  const Set< const DiscreteVariable* >&)) {
109  proj_ = proj;
110  }
111 
112  /// returns the projection function currently used by the projector
113  template < typename GUM_SCALAR >
117  const Set< const DiscreteVariable* >&) {
118  return proj_;
119  }
120 
121  /** @brief returns a rough estimate of the number of operations that will be
122  * performed to compute the projection */
123  template < typename GUM_SCALAR >
126  const Set< const DiscreteVariable* >& del_vars,
127  const Schedule< GUM_SCALAR >& schedule) {
129 
130  float res = 1.0f;
131 
132  for (const auto var: vars)
133  res *= var->domainSize();
134 
135  return res;
136  }
137 
138  /** @brief returns a rough estimate of the number of operations that will be
139  * performed to compute the projection */
140  template < typename GUM_SCALAR >
143  const Set< const DiscreteVariable* >& del_vars,
144  const Schedule< GUM_SCALAR >& schedule) {
146  }
147 
148  /** @brief returns a rough estimate of the number of operations that will be
149  * performed to compute the projection */
150  template < typename GUM_SCALAR >
151  template < template < typename > class TABLE >
153  const TABLE< GUM_SCALAR >& table,
154  const Set< const DiscreteVariable* >& del_vars,
155  const Schedule< GUM_SCALAR >& schedule) {
157  }
158 
159  /// returns the memory consumption used during the projection
160  template < typename GUM_SCALAR >
163  const Set< const DiscreteVariable* >& del_vars,
164  const Schedule< GUM_SCALAR >& schedule) {
166  long res = 1;
167 
168  for (const auto var: vars)
169  if (!del_vars.contains(var)) {
170  if (std::numeric_limits< long >::max() / (long)var->domainSize() < res) {
171  GUM_ERROR(OutOfBounds, "memory usage out of long int range")
172  }
173 
174  res *= long(var->domainSize());
175  }
176 
177  return std::pair< long, long >(res, res);
178  }
179 
180  /// returns the memory consumption used during the projection
181  template < typename GUM_SCALAR >
184  const Set< const DiscreteVariable* >& del_vars,
185  const Schedule< GUM_SCALAR >& schedule) {
187  }
188 
189  /// returns the memory consumption used during the projection
190  template < typename GUM_SCALAR >
191  template < template < typename > class TABLE >
193  const TABLE< GUM_SCALAR >& table,
194  const Set< const DiscreteVariable* >& del_vars,
195  const Schedule< GUM_SCALAR >& schedule) {
197  }
198 
199 } /* namespace gum */
200 
201 #endif /* DOXYGEN_SHOULD_SKIP_THIS */
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643