aGrUM 3.1.1
a C++ library for (probabilistic) graphical models
schedule_tpl.h
Go to the documentation of this file.
1/****************************************************************************
2 * This file is part of the aGrUM/pyAgrum library. *
3 * *
4 * Copyright (c) 2005-2026 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-2026 *
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#pragma once
42
43
50#ifndef DOXYGEN_SHOULD_SKIP_THIS
51
52# include <agrum/agrum.h>
53
54namespace gum {
55
57 template < typename TABLE >
59 Schedule::insertTable(const TABLE& table, const bool copy, const Idx id) {
60 // if the schedule already contains the id, throw an error
61 if (_multidim2id_.existsSecond(id)) {
62 GUM_ERROR(DuplicateScheduleMultiDim,
63 "A table with Id " << id << " already exists in the schedule");
64 }
65
66 // allocate the new table within the schedule
67 ScheduleMultiDim< TABLE >* new_multidim = new ScheduleMultiDim< TABLE >(table, copy, id);
68
69 // keep track that this is a source multidim
70 _multidim2nodes_.insert(new_multidim, NodeSet());
71 _multidim_location_.insert(new_multidim, std::pair< ScheduleOperator*, Idx >(nullptr, Idx(0)));
72 _multidim2id_.insert(new_multidim, new_multidim->id());
73
74 // indicate that the schedule has been modified
76
77 return new_multidim;
78 }
79
81 template < typename TABLE1, typename TABLE2, typename TABLE_RES >
82 const ScheduleOperator&
84 const ScheduleMultiDim< TABLE2 >& table2,
85 TABLE_RES (*combine)(const TABLE1&, const TABLE2&),
86 const bool is_result_persistent) {
87 // note that the insertOperation will check that table1 and table2
88 // already belong to the schedule
89 return insertOperation(
90 ScheduleBinaryCombination< TABLE1, TABLE2, TABLE_RES >(table1, table2, combine, false),
91 is_result_persistent);
92 }
93
95 template < typename TABLE >
97 const gum::VariableSet& del_vars,
98 TABLE (*project)(const TABLE&,
99 const gum::VariableSet&),
100 const bool is_result_persistent) {
101 // note that the insertOperation will check that table already belongs
102 // to the schedule
103 return insertOperation(ScheduleProjection< TABLE >(table, del_vars, project, false),
104 is_result_persistent);
105 }
106
108 template < typename TABLE >
110 // note that the insertOperation will check that table already belongs
111 // to the schedule
112 return insertOperation(ScheduleDeletion< TABLE >(table), false);
113 }
114
116 template < typename TABLE, template < typename... > class CONTAINER >
118 CONTAINER< TABLE >& container) {
119 // note that the insertOperation will check that table already belongs
120 // to the schedule
121 return insertOperation(ScheduleStorage< TABLE, CONTAINER >(table, container), false);
122 }
123
124} /* namespace gum */
125
126#endif /* DOXYGEN_SHOULD_SKIP_THIS */
The Table-agnostic base class of scheduleMultiDim.
the base class for "low-level" operators used to schedule inferences
const ScheduleOperator & emplaceBinaryCombination(const ScheduleMultiDim< TABLE1 > &table1, const ScheduleMultiDim< TABLE2 > &table2, TABLE_RES(*combine)(const TABLE1 &, const TABLE2 &), const bool is_result_persistent=false)
emplace a new schedule binary combination operation
Bijection< const IScheduleMultiDim *, Idx > _multidim2id_
a bijection between pointers to IScheduleMultiDim and their Ids
Definition schedule.h:399
const IScheduleMultiDim * insertTable(const TABLE &table, const bool copy, const Idx id=0)
inserts a new table as a source operation's input, i.e., this table is not computed by any ScheduleOp...
Idx _version_number_
a number that identifies the current version of the schedule
Definition schedule.h:423
HashTable< const IScheduleMultiDim *, NodeSet > _multidim2nodes_
maps the multidims to the set of operations that use them
Definition schedule.h:405
const ScheduleOperator & emplaceStorage(const IScheduleMultiDim &table, CONTAINER< TABLE > &container)
emplace a new schedule storage operation
const ScheduleOperator & emplaceDeletion(const ScheduleMultiDim< TABLE > &table)
emplace a new schedule deletion operation
const ScheduleOperator & insertOperation(const ScheduleOperator &op, const bool are_results_persistent=false)
inserts an operation into the schedule
HashTable< const IScheduleMultiDim *, std::pair< ScheduleOperator *, Idx > > _multidim_location_
a structure to indicate precisely where a ScheduleMultiDim comes from
Definition schedule.h:396
const ScheduleOperator & emplaceProjection(const ScheduleMultiDim< TABLE > &table, const gum::VariableSet &del_vars, TABLE(*project)(const TABLE &, const gum::VariableSet &), const bool is_result_persistent=false)
emplace a new schedule projection operation
#define GUM_ERROR(type, msg)
Definition exceptions.h:76
Size Idx
Type for indexes.
Definition types.h:79
Set< NodeId > NodeSet
Some typdefs and define for shortcuts ...
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.