aGrUM 3.1.1
a C++ library for (probabilistic) graphical models
DBRowGeneratorSet_inl.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
44#include <agrum/base/database/DBRowGeneratorSet.h> // to ease IDE parser
45#ifndef DOXYGEN_SHOULD_SKIP_THIS
46
48
49namespace gum {
50
51 namespace learning {
52
54 INLINE DBRowGeneratorSet::DBRowGeneratorSet() { GUM_CONSTRUCTOR(DBRowGeneratorSet); }
55
58 _generators_(std::move(from._generators_)), _nb_generators_(from._nb_generators_),
59 _output_row_(from._output_row_),
60 _setInputRow_performed_(std::move(from._setInputRow_performed_)) {
61 GUM_CONS_MOV(DBRowGeneratorSet);
62 }
63
65 INLINE DBRowGenerator& DBRowGeneratorSet::operator[](const std::size_t i) {
66 return *(_generators_[i]);
67 }
68
70 INLINE const DBRowGenerator& DBRowGeneratorSet::operator[](const std::size_t i) const {
71 return *(_generators_[i]);
72 }
73
75 INLINE std::size_t DBRowGeneratorSet::nbGenerators() const noexcept { return _nb_generators_; }
76
78 INLINE std::size_t DBRowGeneratorSet::size() const noexcept { return _nb_generators_; }
79
81 INLINE bool DBRowGeneratorSet::hasRows() { return _output_row_ != nullptr; }
82
84 INLINE bool DBRowGeneratorSet::setInputRow(const DBRow< DBTranslatedValue >& input_row) {
85 // reset all the generators: ask them to use method setInputDBRow
86 if (hasRows())
87 for (auto& performed: _setInputRow_performed_)
88 performed = 0;
89
90 // now, parse the row generation tree
91 return _produceNextRow_(&input_row, std::size_t(0));
92 }
93
95 INLINE const DBRow< DBTranslatedValue >& DBRowGeneratorSet::generate() {
96 // get the row that we should return
97 const auto row = _output_row_;
98
99 // we should ask the last generator to produce the next output row
100 _produceNextRow_(_output_row_, _nb_generators_ - 1);
101
102 return *row;
103 }
104
106 INLINE void DBRowGeneratorSet::reset() {
107 for (auto gen: _generators_)
108 gen->reset();
109 for (auto& performed: _setInputRow_performed_)
110 performed = 0;
111 _output_row_ = nullptr;
112 }
113
116 INLINE void DBRowGeneratorSet::setColumnsOfInterest(
117 const std::vector< std::size_t >& cols_of_interest) {
118 // check that no output row generation is still active
119 if (_output_row_ != nullptr)
121 "you cannot change the columns of interest while a "
122 "generation is still being processed");
123 for (auto gen: _generators_)
124 gen->setColumnsOfInterest(cols_of_interest);
125 }
126
129 INLINE void
130 DBRowGeneratorSet::setColumnsOfInterest(std::vector< std::size_t >&& cols_of_interest) {
131 if (_output_row_ != nullptr)
133 "you cannot change the columns of interest while a "
134 "generation is still being processed");
135 for (auto gen: _generators_)
136 gen->setColumnsOfInterest(cols_of_interest);
137 }
138
140 INLINE const std::vector< std::size_t >& DBRowGeneratorSet::columnsOfInterest() const {
141 if (_nb_generators_ == std::size_t(0)) {
143 "there are no generators yet in the generator set, so "
144 "there are no columns of interest");
145 }
146 return _generators_[0]->columnsOfInterest();
147 }
148
149
150 } /* namespace learning */
151
152} /* namespace gum */
153
154#endif /* DOXYGEN_SHOULD_SKIP_THIS */
class for packing sets of generators
Exception : operation not allowed.
Exception : a looked-for element could not be found.
The class used to pack sets of generators.
DBRowGeneratorSet()
default constructor
#define GUM_ERROR(type, msg)
Definition exceptions.h:76
include the inlined functions if necessary
Definition CSVParser.h:55
gum is the global namespace for all aGrUM entities
Definition agrum.h:46