aGrUM 3.1.1
a C++ library for (probabilistic) graphical models
multiDimContainer.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
48
49#ifndef GUM_MULTIDIM_CONTAINER_H
50#define GUM_MULTIDIM_CONTAINER_H
51
52#include <functional>
53#include <iostream>
54#include <vector>
55
56#include <agrum/agrum.h>
57
59
61#include <initializer_list>
62
63namespace gum {
64 // needed for content()
65 template < typename GUM_ELEMENT >
67
68 // ==========================================================================
69 // === GUM_MULTI_DIM ===
70 // ==========================================================================
112 template < typename GUM_ELEMENT >
114 public:
115 // =========================================================================
117 // =========================================================================
119
124
130
132
137
139
143 ~MultiDimContainer() override;
144
146 // =========================================================================
148 // =========================================================================
150
160 virtual void set(const Instantiation& i, const GUM_ELEMENT& value) const;
161
172 virtual GUM_ELEMENT get(const Instantiation& i) const;
173
184 GUM_ELEMENT operator[](const Instantiation& i) const;
185
190 virtual void fill(const GUM_ELEMENT& d) const = 0;
191
210 virtual void populate(const std::vector< GUM_ELEMENT >& v) const;
211
230 virtual void populate(std::initializer_list< GUM_ELEMENT > l) const;
231
233 // =========================================================================
235 // =========================================================================
237
250 virtual void copyFrom(const MultiDimContainer< GUM_ELEMENT >& src) const;
251
266 virtual void copyFrom(const MultiDimContainer< GUM_ELEMENT >& src, Instantiation* p_i) const;
267
280 virtual void extractFrom(const MultiDimContainer< GUM_ELEMENT >& src,
281 const Instantiation& mask);
282
287
292
299
305 const MultiDimAdressable& getMasterRef() const override;
306
307
314 virtual void copy(const MultiDimContainer< GUM_ELEMENT >& src);
315
334 [[nodiscard]] virtual MultiDimContainer< GUM_ELEMENT >* newFactory() const = 0;
335
337 // =========================================================================
339 // =========================================================================
341
346 virtual std::string toString() const;
347
352 std::string toString(const Instantiation* i) const override = 0;
353
359 bool operator==(const MultiDimContainer< GUM_ELEMENT >& p) const;
360
365 virtual void apply(std::function< GUM_ELEMENT(GUM_ELEMENT) > f) const;
366
372 virtual GUM_ELEMENT reduce(std::function< GUM_ELEMENT(GUM_ELEMENT, GUM_ELEMENT) > f,
373 GUM_ELEMENT base) const;
374
375
377 // =========================================================================
379 // =========================================================================
381
389 virtual void beginMultipleChanges() = 0;
390
395 virtual void endMultipleChanges() = 0;
396
401 virtual void endMultipleChanges(const GUM_ELEMENT& v) = 0;
402
404
405 protected:
419 virtual GUM_ELEMENT& get_(const Instantiation& i) const = 0;
420 };
421} /* namespace gum */
422
424
425#endif /* GUM_MULTIDIM_CONTAINER_H */
Class for assigning/browsing values to tuples of discrete variables.
MultiDimAdressable()
Default constructor.
bool operator==(const MultiDimContainer< GUM_ELEMENT > &p) const
Test if this MultiDimContainer is equal to p.
MultiDimContainer & operator=(const MultiDimContainer< GUM_ELEMENT > &src)
Default constructor.
virtual void beginMultipleChanges()=0
Call this method before doing important changes in this MultiDimContainer.
std::string toString(const Instantiation *i) const override=0
Display the internal representation of i.
virtual void set(const Instantiation &i, const GUM_ELEMENT &value) const
Changes the value pointed by i.
virtual void copy(const MultiDimContainer< GUM_ELEMENT > &src)
Removes all variables in this MultiDimContainer and copy the content of src, variables included.
virtual void copyFrom(const MultiDimContainer< GUM_ELEMENT > &src) const
Basic copy of a MultiDimContainer.
virtual void fill(const GUM_ELEMENT &d) const =0
Fill the table with d.
virtual void populate(const std::vector< GUM_ELEMENT > &v) const
Automatically fills this MultiDimContainer with the values in v.
virtual GUM_ELEMENT get(const Instantiation &i) const
Returns the value pointed by i.
virtual GUM_ELEMENT reduce(std::function< GUM_ELEMENT(GUM_ELEMENT, GUM_ELEMENT) > f, GUM_ELEMENT base) const
compute lfold for this container
virtual const MultiDimImplementation< GUM_ELEMENT > * content() const =0
Returns the implementation for this object (may be *this).
MultiDimContainer()
Default constructor.
virtual void endMultipleChanges(const GUM_ELEMENT &v)=0
Call this method after doing important changes in this MultiDimContainer.
virtual void endMultipleChanges()=0
Call this method after doing important changes in this MultiDimContainer.
GUM_ELEMENT operator[](const Instantiation &i) const
An [] operator using a Instantiation as argument.
virtual void extractFrom(const MultiDimContainer< GUM_ELEMENT > &src, const Instantiation &mask)
Basic extraction of a MultiDimContainer.
virtual MultiDimImplementation< GUM_ELEMENT > * content()=0
Returns the implementation for this object (may be *this).
virtual void apply(std::function< GUM_ELEMENT(GUM_ELEMENT) > f) const
Apply a function on every element of the container.
virtual std::string toString() const
Returns a representation of this MultiDimContainer.
MultiDimAdressable & getMasterRef() override
In order to insure the dereference for decorators, we need to virtualize the access to master pointer...
virtual MultiDimContainer< GUM_ELEMENT > * newFactory() const =0
Creates an empty clone of this MultiDimContainer.
virtual GUM_ELEMENT & get_(const Instantiation &i) const =0
Return a data, given a Instantiation.
~MultiDimContainer() override
Destructor.
<agrum/base/multidim/multiDimImplementation.h>
Useful macros for maths.
Headers for the abstract base class for all multi dimensionnal containers.
Implementation of the MultiDimContainer class.
gum is the global namespace for all aGrUM entities
Definition agrum.h:46