aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
multiDimProjection.h
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2025 by *
5 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
6 * - Christophe GONZALES(_at_AMU) *
7 * *
8 * The aGrUM/pyAgrum library is free software; you can redistribute it *
9 * and/or modify it under the terms of either : *
10 * *
11 * - the GNU Lesser General Public License as published by *
12 * the Free Software Foundation, either version 3 of the License, *
13 * or (at your option) any later version, *
14 * - the MIT license (MIT), *
15 * - or both in dual license, as here. *
16 * *
17 * (see https://agrum.gitlab.io/articles/dual-licenses-lgplv3mit.html) *
18 * *
19 * This aGrUM/pyAgrum library is distributed in the hope that it will be *
20 * useful, but WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, *
21 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES MERCHANTABILITY or FITNESS *
22 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
25 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR *
26 * OTHER DEALINGS IN THE SOFTWARE. *
27 * *
28 * See LICENCES for more details. *
29 * *
30 * SPDX-FileCopyrightText: Copyright 2005-2025 *
31 * - Pierre-Henri WUILLEMIN(_at_LIP6) *
32 * - Christophe GONZALES(_at_AMU) *
33 * SPDX-License-Identifier: LGPL-3.0-or-later OR MIT *
34 * *
35 * Contact : info_at_agrum_dot_org *
36 * homepage : http://agrum.gitlab.io *
37 * gitlab : https://gitlab.com/agrumery/agrum *
38 * *
39 ****************************************************************************/
40
41
46
47#ifndef GUM_MULTI_DIM_PROJECTION_H
48#define GUM_MULTI_DIM_PROJECTION_H
49
50#include <utility>
51
53
54namespace gum {
55
56 // clang-format off
106 // clang-format on
107
108 template < class TABLE >
109 class MultiDimProjection final {
110#ifndef DOXYGEN_SHOULD_SKIP_THIS
111 // class to get the types of the TABLE's values using metaprogramming
112 template < typename T >
113 struct TableType {
114 using value_type = T;
115 };
116
117 template < template < typename, typename... > class CONTAINER, typename T, typename... Args >
118 struct TableType< CONTAINER< T, Args... > > {
119 using value_type = T;
120 };
121#endif // DOXYGEN_SHOULD_SKIP_THIS
122
123 public:
125 using value_type = typename TableType< TABLE >::value_type;
126
127 // ========================================================================
129 // ========================================================================
131
133 MultiDimProjection(TABLE (*proj)(const TABLE&, const gum::VariableSet&));
134
137
140
148
150 // ========================================================================
152 // ========================================================================
154
166 TABLE* execute(const TABLE& table, const gum::VariableSet& del_vars) const;
167 void execute(TABLE& container, const TABLE& table, const gum::VariableSet& del_vars) const;
168
170
173 std::pair< ScheduleOperator*, const IScheduleMultiDim* >
175 const gum::VariableSet& del_vars,
176 const bool is_result_persistent = false) const;
177
179
191 const IScheduleMultiDim* table,
192 const gum::VariableSet& del_vars,
193 const bool is_result_persistent = false) const;
194
196 void setProjectionFunction(TABLE (*proj)(const TABLE&, const gum::VariableSet&));
197
199 TABLE (*projectionFunction())(const TABLE&, const gum::VariableSet&);
200
205 double nbOperations(const TABLE& table, const gum::VariableSet& del_vars) const;
206
212 const gum::VariableSet& del_vars) const;
213
226 std::pair< double, double > memoryUsage(const TABLE& table,
227 const gum::VariableSet& del_vars) const;
228
241 std::pair< double, double > memoryUsage(const Sequence< const DiscreteVariable* >& vars,
242 const gum::VariableSet& del_vars) const;
243
245
246 protected:
248 TABLE (*proj_)(const TABLE&, const gum::VariableSet&);
249
250 private:
253 };
254
255} /* namespace gum */
256
257// always include the template implementation
259
260#endif /* GUM_MULTI_DIM_PROJECTION_H */
The Table-agnostic base class of scheduleMultiDim.
TABLE(* proj_)(const TABLE &, const gum::VariableSet &)
The projection function actually used.
double nbOperations(const TABLE &table, const gum::VariableSet &del_vars) const
returns a rough estimate of the number of operations that will be performed to compute the projection...
std::pair< ScheduleOperator *, const IScheduleMultiDim * > operations(const IScheduleMultiDim *table, const gum::VariableSet &del_vars, const bool is_result_persistent=false) const
returns operation to perform as well as the result of the projection
void setProjectionFunction(TABLE(*proj)(const TABLE &, const gum::VariableSet &))
Changes the function used for projecting TABLES.
MultiDimProjection(const MultiDimProjection< TABLE > &)
Copy constructor.
virtual ~MultiDimProjection()
Destructor.
typename TableType< TABLE >::value_type value_type
the type of the values contained into TABLE
TABLE(*)(const TABLE &, const gum::VariableSet &) projectionFunction()
Returns the projection function currently used by the projector.
const IScheduleMultiDim * schedule(Schedule &schedule, const IScheduleMultiDim *table, const gum::VariableSet &del_vars, const bool is_result_persistent=false) const
add to a given schedule the set of operations needed to perform the projection
std::pair< double, double > memoryUsage(const TABLE &table, const gum::VariableSet &del_vars) const
Returns the memory consumption used during the projection.
MultiDimProjection(TABLE(*proj)(const TABLE &, const gum::VariableSet &))
Default constructor.
std::pair< double, double > memoryUsage(const Sequence< const DiscreteVariable * > &vars, const gum::VariableSet &del_vars) const
Returns the memory consumption used during the projection.
void execute(TABLE &container, const TABLE &table, const gum::VariableSet &del_vars) const
Returns the projection function currently used by the projector.
virtual MultiDimProjection< TABLE > * clone() const
virtual constructor
double nbOperations(const Sequence< const DiscreteVariable * > &vars, const gum::VariableSet &del_vars) const
returns a rough estimate of the number of operations that will be performed to compute the projection...
TABLE * execute(const TABLE &table, const gum::VariableSet &del_vars) const
Creates and returns the projection of the table over a subset of its vars.
MultiDimProjection< TABLE > & operator=(const MultiDimProjection< TABLE > &)
Forbid copy operators.
Class containing a schedule of operations to perform on multidims.
Definition schedule.h:80
The generic class for storing (ordered) sequences of objects.
Definition sequence.h:972
A generic interface to project efficiently a MultiDim table over a subset of its variables.
gum is the global namespace for all aGrUM entities
Definition agrum.h:46
Set< const DiscreteVariable * > VariableSet
Class containing a schedule of operations to perform on multidims.