aGrUM 2.3.2
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-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
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_SCALAR >
67
68 // ==========================================================================
69 // === GUM_MULTI_DIM ===
70 // ==========================================================================
112 template < typename GUM_SCALAR >
114 public:
115 // =========================================================================
117 // =========================================================================
119
124
130
132
137
139
143 virtual ~MultiDimContainer();
144
146 // =========================================================================
148 // =========================================================================
150
160 virtual void set(const Instantiation& i, const GUM_SCALAR& value) const;
161
172 virtual GUM_SCALAR get(const Instantiation& i) const;
173
184 GUM_SCALAR operator[](const Instantiation& i) const;
185
190 virtual void fill(const GUM_SCALAR& d) const = 0;
191
210 virtual void populate(const std::vector< GUM_SCALAR >& v) const;
211
230 virtual void populate(std::initializer_list< GUM_SCALAR > l) const;
231
233 // =========================================================================
235 // =========================================================================
237
250 virtual void copyFrom(const MultiDimContainer< GUM_SCALAR >& src) const;
251
266 virtual void copyFrom(const MultiDimContainer< GUM_SCALAR >& src, Instantiation* p_i) const;
267
280 virtual void extractFrom(const MultiDimContainer< GUM_SCALAR >& src, const Instantiation& mask);
281
286
291
298
304 virtual const MultiDimAdressable& getMasterRef() const;
305
306
313 virtual void copy(const MultiDimContainer< GUM_SCALAR >& src);
314
334
336 // =========================================================================
338 // =========================================================================
340
345 virtual std::string toString() const;
346
351 virtual std::string toString(const Instantiation* i) const = 0;
352
358 bool operator==(const MultiDimContainer< GUM_SCALAR >& p) const;
359
365 bool operator!=(const MultiDimContainer< GUM_SCALAR >& p) const;
366
371 virtual void apply(std::function< GUM_SCALAR(GUM_SCALAR) > f) const;
372
378 virtual GUM_SCALAR reduce(std::function< GUM_SCALAR(GUM_SCALAR, GUM_SCALAR) > f,
379 GUM_SCALAR base) const;
380
381
383 // =========================================================================
385 // =========================================================================
387
395 virtual void beginMultipleChanges() = 0;
396
401 virtual void endMultipleChanges() = 0;
402
407 virtual void endMultipleChanges(const GUM_SCALAR& v) = 0;
408
410
411 protected:
425 virtual GUM_SCALAR& get_(const Instantiation& i) const = 0;
426 };
427} /* namespace gum */
428
430
431#endif /* GUM_MULTIDIM_CONTAINER_H */
Class for assigning/browsing values to tuples of discrete variables.
MultiDimAdressable()
Default constructor.
virtual void copy(const MultiDimContainer< GUM_SCALAR > &src)
Removes all variables in this MultiDimContainer and copy the content of src, variables included.
virtual void extractFrom(const MultiDimContainer< GUM_SCALAR > &src, const Instantiation &mask)
Basic extraction of a MultiDimContainer.
MultiDimContainer & operator=(const MultiDimContainer< GUM_SCALAR > &src)
Default constructor.
virtual void endMultipleChanges(const GUM_SCALAR &v)=0
Call this method after doing important changes in this MultiDimContainer.
virtual MultiDimContainer< GUM_SCALAR > * newFactory() const =0
Creates an empty clone of this MultiDimContainer.
virtual const MultiDimImplementation< GUM_SCALAR > * content() const =0
Returns the implementation for this object (may be *this).
virtual MultiDimImplementation< GUM_SCALAR > * content()=0
Returns the implementation for this object (may be *this).
virtual std::string toString(const Instantiation *i) const =0
Display the internal representation of i.
virtual ~MultiDimContainer()
Destructor.
virtual MultiDimAdressable & getMasterRef()
In order to insure the dereference for decorators, we need to virtualize the access to master pointer...
bool operator!=(const MultiDimContainer< GUM_SCALAR > &p) const
Test if this MultiDimContainer is different of p.
virtual void beginMultipleChanges()=0
Call this method before doing important changes in this MultiDimContainer.
virtual GUM_SCALAR & get_(const Instantiation &i) const =0
Return a data, given a Instantiation.
virtual void set(const Instantiation &i, const GUM_SCALAR &value) const
Changes the value pointed by i.
MultiDimContainer()
Default constructor.
virtual void endMultipleChanges()=0
Call this method after doing important changes in this MultiDimContainer.
virtual void fill(const GUM_SCALAR &d) const =0
Fill the table with d.
virtual GUM_SCALAR reduce(std::function< GUM_SCALAR(GUM_SCALAR, GUM_SCALAR) > f, GUM_SCALAR base) const
compute lfold for this container
virtual GUM_SCALAR get(const Instantiation &i) const
Returns the value pointed by i.
virtual void populate(const std::vector< GUM_SCALAR > &v) const
Automatically fills this MultiDimContainer with the values in v.
GUM_SCALAR operator[](const Instantiation &i) const
An [] operator using a Instantiation as argument.
virtual void copyFrom(const MultiDimContainer< GUM_SCALAR > &src) const
Basic copy of a MultiDimContainer.
virtual void apply(std::function< GUM_SCALAR(GUM_SCALAR) > f) const
Apply a function on every element of the container.
virtual std::string toString() const
Returns a representation of this MultiDimContainer.
bool operator==(const MultiDimContainer< GUM_SCALAR > &p) const
Test if this MultiDimContainer is equal to p.
<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