aGrUM 2.3.2
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-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#pragma once
41
42
43#ifndef DOXYGEN_SHOULD_SKIP_THIS
44
46
47namespace gum {
48
49 namespace learning {
50
52 INLINE DBRowGeneratorSet::DBRowGeneratorSet() { GUM_CONSTRUCTOR(DBRowGeneratorSet); }
53
56 _generators_(std::move(from._generators_)), _nb_generators_(from._nb_generators_),
57 _output_row_(from._output_row_),
58 _setInputRow_performed_(std::move(from._setInputRow_performed_)) {
59 GUM_CONS_MOV(DBRowGeneratorSet);
60 }
61
63 INLINE DBRowGenerator& DBRowGeneratorSet::operator[](const std::size_t i) {
64 return *(_generators_[i]);
65 }
66
68 INLINE const DBRowGenerator& DBRowGeneratorSet::operator[](const std::size_t i) const {
69 return *(_generators_[i]);
70 }
71
73 INLINE std::size_t DBRowGeneratorSet::nbGenerators() const noexcept { return _nb_generators_; }
74
76 INLINE std::size_t DBRowGeneratorSet::size() const noexcept { return _nb_generators_; }
77
79 INLINE bool DBRowGeneratorSet::hasRows() { return _output_row_ != nullptr; }
80
82 INLINE bool DBRowGeneratorSet::setInputRow(const DBRow< DBTranslatedValue >& input_row) {
83 // reset all the generators: ask them to use method setInputDBRow
84 if (hasRows())
85 for (auto& performed: _setInputRow_performed_)
86 performed = 0;
87
88 // now, parse the row generation tree
89 return _produceNextRow_(&input_row, std::size_t(0));
90 }
91
93 INLINE const DBRow< DBTranslatedValue >& DBRowGeneratorSet::generate() {
94 // get the row that we should return
95 const auto row = _output_row_;
96
97 // we should ask the last generator to produce the next output row
98 _produceNextRow_(_output_row_, _nb_generators_ - 1);
99
100 return *row;
101 }
102
104 INLINE void DBRowGeneratorSet::reset() {
105 for (auto gen: _generators_)
106 gen->reset();
107 for (auto& performed: _setInputRow_performed_)
108 performed = 0;
109 _output_row_ = nullptr;
110 }
111
114 INLINE void DBRowGeneratorSet::setColumnsOfInterest(
115 const std::vector< std::size_t >& cols_of_interest) {
116 // check that no output row generation is still active
117 if (_output_row_ != nullptr)
119 "you cannot change the columns of interest while a "
120 "generation is still being processed");
121 for (auto gen: _generators_)
122 gen->setColumnsOfInterest(cols_of_interest);
123 }
124
127 INLINE void
128 DBRowGeneratorSet::setColumnsOfInterest(std::vector< std::size_t >&& cols_of_interest) {
129 if (_output_row_ != nullptr)
131 "you cannot change the columns of interest while a "
132 "generation is still being processed");
133 for (auto gen: _generators_)
134 gen->setColumnsOfInterest(cols_of_interest);
135 }
136
138 INLINE const std::vector< std::size_t >& DBRowGeneratorSet::columnsOfInterest() const {
139 if (_nb_generators_ == std::size_t(0)) {
141 "there are no generators yet in the generator set, so "
142 "there are no columns of interest");
143 }
144 return _generators_[0]->columnsOfInterest();
145 }
146
147
148 } /* namespace learning */
149
150} /* namespace gum */
151
152#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:72
include the inlined functions if necessary
Definition CSVParser.h:54
gum is the global namespace for all aGrUM entities
Definition agrum.h:46