aGrUM  0.14.2
multiDimArray.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_ARRAY_H
27 #define GUM_MULTI_DIM_ARRAY_H
28 
29 #include <agrum/agrum.h>
31 #include <vector>
32 
33 namespace gum {
34 
35  template < typename GUM_SCALAR >
37 
38  // ===========================================================================
39  // === GUM_MULTI_DIM_ARRAY ===
40  // ===========================================================================
50  template < typename GUM_SCALAR >
51  class MultiDimArray : public MultiDimWithOffset< GUM_SCALAR > {
52  public:
53  template < typename GUM_SCALARBIS >
54  friend class MultiDimBijArray;
55  // =========================================================================
57  // =========================================================================
59 
65  MultiDimArray();
66 
76 
93  virtual ~MultiDimArray();
94 
96 
98  // =========================================================================
100  // =========================================================================
102 
106  virtual void copyFrom(const MultiDimContainer< GUM_SCALAR >& src) const;
107 
112  virtual void apply(std::function< GUM_SCALAR(GUM_SCALAR) > f) const;
113 
119  virtual GUM_SCALAR
120  reduce(std::function< GUM_SCALAR(GUM_SCALAR, GUM_SCALAR) > f,
121  GUM_SCALAR base) const;
122 
126  virtual void add(const DiscreteVariable& v);
127 
131  virtual void erase(const DiscreteVariable& v);
132 
136  virtual Size realSize() const;
137 
141  virtual void fill(const GUM_SCALAR& d) const;
142 
146  virtual const std::string& name() const;
147 
149  // =========================================================================
151  // =========================================================================
153 
174  const GUM_SCALAR& unsafeGet(Idx offset) const;
175 
194  const GUM_SCALAR& getByOffset(Idx offset) const;
195 
215  void unsafeSet(Idx offset, const GUM_SCALAR& val);
216 
234  void setByOffset(Idx offset, const GUM_SCALAR& val);
235 
237 
238  protected:
241  mutable std::vector< GUM_SCALAR > _values;
242 
243  virtual void _commitMultipleChanges();
244 
245  virtual void _commitMultipleChanges(const GUM_SCALAR&);
246 
247  virtual GUM_SCALAR& _get(const Instantiation& i) const;
248 
249  virtual void _replace(const DiscreteVariable* x, const DiscreteVariable* y);
250  };
251 
252 
253 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
254  extern template class MultiDimArray< double >;
255 #endif
256 
257 
258 } /* namespace gum */
259 
261 
262 #endif /* GUM_MULTI_DIM_ARRAY_H */
std::vector< GUM_SCALAR > _values
The true data : the values is mutable since we can change the value / in a const multiDimArray.
virtual Size realSize() const
Returns the real size of this MultiDimArray.
Implementation of the MultiDimArray class.
Decorator of a MultiDimArray, using a bijection over the variables.
Definition: multiDimArray.h:36
virtual void erase(const DiscreteVariable &v)
Removes a variable.
virtual GUM_SCALAR & _get(const Instantiation &i) const
Return a data, given a Instantiation.
Headers of the MultiDimWithOffset class.
virtual void copyFrom(const MultiDimContainer< GUM_SCALAR > &src) const
Copy from a other MultiDimContainer.
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 void apply(std::function< GUM_SCALAR(GUM_SCALAR) > f) const
Apply a function on every element of the container.
void unsafeSet(Idx offset, const GUM_SCALAR &val)
Modifies the element stored in the multidimArray at a given offset.
virtual ~MultiDimArray()
Copy operator.
virtual void _commitMultipleChanges()
Synchronize content after MultipleChanges.
void setByOffset(Idx offset, const GUM_SCALAR &val)
Modifies the element stored in the multidimArray at a given offset.
Abstract class for Multidimensional matrix stored as an array in memory and with an offset associated...
virtual GUM_SCALAR reduce(std::function< GUM_SCALAR(GUM_SCALAR, GUM_SCALAR) > f, GUM_SCALAR base) const
compute lfold for this container
virtual void fill(const GUM_SCALAR &d) const
Fills the MultiDimArray with the given value.
Multidimensional matrix stored as an array in memory.
Definition: multiDimArray.h:51
virtual MultiDimContainer< GUM_SCALAR > * newFactory() const
Default constructor.
virtual void _replace(const DiscreteVariable *x, const DiscreteVariable *y)
Replace variable x by y.
virtual const std::string & name() const
Returns the MultiDimArray name.
const GUM_SCALAR & getByOffset(Idx offset) const
Returns the element stored in the multidimArray at a given offset.
Class for assigning/browsing values to tuples of discrete variables.
Definition: instantiation.h:80
MultiDimArray()
Default constructor.
Size Idx
Type for indexes.
Definition: types.h:50
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45
const GUM_SCALAR & unsafeGet(Idx offset) const
Returns the element stored in the multidimArray at a given offset.
virtual void add(const DiscreteVariable &v)
Adds a variable.