aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
multiDimSparse.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright (c) 2005-2021 by Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
4  * info_at_agrum_dot_org
5  *
6  * This library is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License
17  * along with this library. If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20 
21 
22 /**
23  * @file
24  * @brief Headers of MultiDimSparse.
25  *
26  * @author Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
27  */
28 #ifndef GUM_MULTI_DIM_SPARSE_H
29 #define GUM_MULTI_DIM_SPARSE_H
30 
31 #include <agrum/agrum.h>
32 #include <agrum/tools/multidim/implementations/multiDimWithOffset.h>
33 #include <vector>
34 
35 namespace gum {
36 
37  // ===========================================================================
38  // === GUM_MULTI_DIM_ARRAY ===
39  // ===========================================================================
40  /**
41  * @class MultiDimSparse
42  * @headerfile multiDimSparse.h <agrum/tools/multidim/multiDimSparse.h>
43  * @ingroup multidim_group
44  *
45  * @brief Multidimensional matrix stored as a sparse array in memory.
46  * @tparam GUM_SCALAR The type of scalars stored in the multidimensional
47  * table.
48  */
49  template < typename GUM_SCALAR >
51  public:
52  // =========================================================================
53  /// @name Constructors / Destructors
54  // =========================================================================
55  /// @{
56 
57  /**
58  * @brief Default constructor: creates an empty null dimensional matrix.
59  * @param default_value The default value of this MultiDimSparse.
60  */
61  explicit MultiDimSparse(const GUM_SCALAR& default_value);
62 
63  /**
64  * @brief Copy constructor.
65  *
66  * The newly created matrix contains the same variables and the same values
67  * as from, but no instantiation is associated to it.
68  *
69  * @param from The MultiDimSparse to copy.
70  */
71  MultiDimSparse(const MultiDimSparse< GUM_SCALAR >& from);
72 
73  /**
74  * @todo operator=
75  *
76  * @brief Copy operator.
77  * @param from The MultiDimSparse to copy.
78  MultiDimSparse<GUM_SCALAR>& operator=( const MultiDimSparse<GUM_SCALAR>&
79  from );
80  */
81 
82  /**
83  * @brief Class destructor.
84  */
85  virtual ~MultiDimSparse();
86 
87 
88  /// @}
89  // =========================================================================
90  /// @name Inherited methods
91  // =========================================================================
92  /// @{
93 
94  virtual MultiDimContainer< GUM_SCALAR >* newFactory() const;
95 
96  void add(const DiscreteVariable& v);
97 
98  void erase(const DiscreteVariable& v);
99 
100  virtual void fill(const GUM_SCALAR& d) const;
101 
102  virtual GUM_SCALAR get(const Instantiation& i) const;
103 
104  virtual void set(const Instantiation& i, const GUM_SCALAR& value) const;
105 
106  virtual const std::string& name() const;
107 
108  virtual Size realSize() const;
109 
110  /// @}
111 
112  protected:
113  /// The true data : the values is mutable since we can change the value
114  /// in a const multiDimArray
116 
117  /// The default value.
118  mutable GUM_SCALAR default_;
119 
120  /// Synchronise content after MultipleChanges.
121  virtual void commitMultipleChanges_();
122 
123  /**
124  * @warning Will raise an OperationNotAllowed as this use its own internal
125  * datastructure.
126  */
127  virtual GUM_SCALAR& get_(const Instantiation& i) const;
128 
129  // =========================================================================
130  /// @name Inherited methods
131  // =========================================================================
132  /// @{
133 
134  virtual void replace_(const DiscreteVariable* x, const DiscreteVariable* y);
135 
136  /// @}
137  };
138 
139 
140 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
141  extern template class MultiDimSparse< double >;
142 #endif
143 
144 
145 } /* namespace gum */
146 
147 #include <agrum/tools/multidim/implementations/multiDimSparse_tpl.h>
148 
149 #endif /* GUM_MULTI_DIM_SPARSE_H */
HashTable< Size, GUM_SCALAR > params_
The true data : the values is mutable since we can change the value in a const multiDimArray.
void erase(const DiscreteVariable &v)
Removes a var from the variables of the multidimensional matrix.
virtual ~MultiDimSparse()
Copy operator.
virtual void commitMultipleChanges_()
Synchronise content after MultipleChanges.
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
GUM_SCALAR default_
The default value.
virtual GUM_SCALAR get(const Instantiation &i) const
Returns the value pointed by i.
virtual void replace_(const DiscreteVariable *x, const DiscreteVariable *y)
Replace variable x by y.
virtual void set(const Instantiation &i, const GUM_SCALAR &value) const
Changes the value pointed by i.
virtual GUM_SCALAR & get_(const Instantiation &i) const
MultiDimSparse(const MultiDimSparse< GUM_SCALAR > &from)
Copy constructor.
virtual MultiDimContainer< GUM_SCALAR > * newFactory() const
Class constructor.
void add(const DiscreteVariable &v)
Adds a new var to the variables of the multidimensional matrix.
virtual const std::string & name() const
Returns the real name of the multiDim implementation.
MultiDimSparse(const GUM_SCALAR &default_value)
Default constructor: creates an empty null dimensional matrix.
virtual void fill(const GUM_SCALAR &d) const
Fill the table with d.
virtual Size realSize() const
Returns the real number of parameters used for this table.
Multidimensional matrix stored as a sparse array in memory.