aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
multiDimSparse.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#ifndef GUM_MULTI_DIM_SPARSE_H
49#define GUM_MULTI_DIM_SPARSE_H
50
51#include <vector>
52
53#include <agrum/agrum.h>
54
56
57namespace gum {
58
59 // ===========================================================================
60 // === GUM_MULTI_DIM_ARRAY ===
61 // ===========================================================================
71 template < typename GUM_SCALAR >
72 class MultiDimSparse final: public MultiDimWithOffset< GUM_SCALAR > {
73 public:
74 // =========================================================================
76 // =========================================================================
78
83 explicit MultiDimSparse(const GUM_SCALAR& default_value);
84
94
103
107 virtual ~MultiDimSparse();
108
109
111 // =========================================================================
113 // =========================================================================
115
117
118 void add(const DiscreteVariable& v);
119
120 void erase(const DiscreteVariable& v);
121
122 virtual void fill(const GUM_SCALAR& d) const;
123
124 virtual GUM_SCALAR get(const Instantiation& i) const;
125
126 virtual void set(const Instantiation& i, const GUM_SCALAR& value) const;
127
128 virtual const std::string& name() const;
129
130 virtual Size realSize() const;
131
133
134 protected:
138
140 mutable GUM_SCALAR default_;
141
143 virtual void commitMultipleChanges_();
144
149 virtual GUM_SCALAR& get_(const Instantiation& i) const;
150
151 // =========================================================================
153 // =========================================================================
155
156 virtual void replace_(const DiscreteVariable* x, const DiscreteVariable* y);
157
159 };
160
161
162#ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
163 extern template class MultiDimSparse< double >;
164#endif
165
166
167} /* namespace gum */
168
170
171#endif /* GUM_MULTI_DIM_SPARSE_H */
Base class for discrete random variable.
Class for assigning/browsing values to tuples of discrete variables.
Abstract base class for all multi dimensionnal containers.
Multidimensional matrix stored as a sparse array in memory.
virtual Size realSize() const
Returns the real number of parameters used for this table.
MultiDimSparse(const GUM_SCALAR &default_value)
Default constructor: creates an empty null dimensional matrix.
void add(const DiscreteVariable &v)
Adds a new var to the variables of the multidimensional matrix.
void erase(const DiscreteVariable &v)
Removes a var from the variables of the multidimensional matrix.
virtual ~MultiDimSparse()
Copy operator.
virtual void set(const Instantiation &i, const GUM_SCALAR &value) const
Changes the value pointed by i.
virtual void fill(const GUM_SCALAR &d) const
Fill the table with d.
GUM_SCALAR default_
The default value.
virtual MultiDimContainer< GUM_SCALAR > * newFactory() const
Class constructor.
virtual GUM_SCALAR & get_(const Instantiation &i) const
virtual void commitMultipleChanges_()
Synchronise content after MultipleChanges.
virtual const std::string & name() const
Returns the real name of the multiDim implementation.
HashTable< Size, GUM_SCALAR > params_
The true data : the values is mutable since we can change the value in a const multiDimArray.
virtual void replace_(const DiscreteVariable *x, const DiscreteVariable *y)
Replace variable x by y.
virtual GUM_SCALAR get(const Instantiation &i) const
Returns the value pointed by i.
MultiDimWithOffset()
Class constructor.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74
Implementation of MultiDimSparse.
Headers of the MultiDimWithOffset class.
gum is the global namespace for all aGrUM entities
Definition agrum.h:46