aGrUM  0.14.2
multiDimSparse.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Pierre-Henri WUILLEMIN et Christophe GONZALES *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
26 #ifndef GUM_MULTI_DIM_SPARSE_H
27 #define GUM_MULTI_DIM_SPARSE_H
28 
29 #include <agrum/agrum.h>
31 #include <vector>
32 
33 namespace gum {
34 
35  // ===========================================================================
36  // === GUM_MULTI_DIM_ARRAY ===
37  // ===========================================================================
47  template < typename GUM_SCALAR >
48  class MultiDimSparse : public MultiDimWithOffset< GUM_SCALAR > {
49  public:
50  // =========================================================================
52  // =========================================================================
54 
59  explicit MultiDimSparse(const GUM_SCALAR& default_value);
60 
70 
83  virtual ~MultiDimSparse();
84 
85 
87  // =========================================================================
89  // =========================================================================
91 
93 
94  void add(const DiscreteVariable& v);
95 
96  void erase(const DiscreteVariable& v);
97 
98  virtual void fill(const GUM_SCALAR& d) const;
99 
100  virtual GUM_SCALAR get(const Instantiation& i) const;
101 
102  virtual void set(const Instantiation& i, const GUM_SCALAR& value) const;
103 
104  virtual const std::string& name() const;
105 
106  virtual Size realSize() const;
107 
109 
110  protected:
114 
116  mutable GUM_SCALAR _default;
117 
119  virtual void _commitMultipleChanges();
120 
125  virtual GUM_SCALAR& _get(const Instantiation& i) const;
126 
127  // =========================================================================
129  // =========================================================================
131 
132  virtual void _replace(const DiscreteVariable* x, const DiscreteVariable* y);
133 
135  };
136 
137 
138 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
139  extern template class MultiDimSparse< double >;
140 #endif
141 
142 
143 } /* namespace gum */
144 
146 
147 #endif /* GUM_MULTI_DIM_SPARSE_H */
GUM_SCALAR _default
The default value.
void erase(const DiscreteVariable &v)
Removes a var from the variables of the multidimensional matrix.
virtual ~MultiDimSparse()
Copy operator.
Headers of the MultiDimWithOffset class.
Base class for discrete random variable.
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
Abstract base class for all multi dimensionnal containers.
virtual MultiDimContainer< GUM_SCALAR > * newFactory() const
Class constructor.
Abstract class for Multidimensional matrix stored as an array in memory and with an offset associated...
Implementation of MultiDimSparse.
virtual void _commitMultipleChanges()
Synchronise content after MultipleChanges.
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.
Class for assigning/browsing values to tuples of discrete variables.
Definition: instantiation.h:80
MultiDimSparse(const GUM_SCALAR &default_value)
Default constructor: creates an empty null dimensional matrix.
virtual GUM_SCALAR & _get(const Instantiation &i) const
HashTable< Size, GUM_SCALAR > _params
The true data : the values is mutable since we can change the value in a const multiDimArray.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45
virtual void _replace(const DiscreteVariable *x, const DiscreteVariable *y)
Replace variable x by y.
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.