aGrUM  0.16.0
multiDimArray.h
Go to the documentation of this file.
1 
29 #ifndef GUM_MULTI_DIM_ARRAY_H
30 #define GUM_MULTI_DIM_ARRAY_H
31 
32 #include <agrum/agrum.h>
34 #include <vector>
35 
36 namespace gum {
37 
38  template < typename GUM_SCALAR >
40 
41  // ===========================================================================
42  // === GUM_MULTI_DIM_ARRAY ===
43  // ===========================================================================
53  template < typename GUM_SCALAR >
54  class MultiDimArray : public MultiDimWithOffset< GUM_SCALAR > {
55  public:
56  template < typename GUM_SCALARBIS >
57  friend class MultiDimBijArray;
58  // =========================================================================
60  // =========================================================================
62 
68  MultiDimArray();
69 
79 
96  virtual ~MultiDimArray();
97 
99 
101  // =========================================================================
103  // =========================================================================
105 
109  virtual void copyFrom(const MultiDimContainer< GUM_SCALAR >& src) const;
110 
115  virtual void apply(std::function< GUM_SCALAR(GUM_SCALAR) > f) const;
116 
122  virtual GUM_SCALAR
123  reduce(std::function< GUM_SCALAR(GUM_SCALAR, GUM_SCALAR) > f,
124  GUM_SCALAR base) const;
125 
129  virtual void add(const DiscreteVariable& v);
130 
134  virtual void erase(const DiscreteVariable& v);
135 
139  virtual Size realSize() const;
140 
144  virtual void fill(const GUM_SCALAR& d) const;
145 
149  virtual const std::string& name() const;
150 
152  // =========================================================================
154  // =========================================================================
156 
177  const GUM_SCALAR& unsafeGet(Idx offset) const;
178 
197  const GUM_SCALAR& getByOffset(Idx offset) const;
198 
218  void unsafeSet(Idx offset, const GUM_SCALAR& val);
219 
237  void setByOffset(Idx offset, const GUM_SCALAR& val);
238 
240 
241  protected:
244  mutable std::vector< GUM_SCALAR > _values;
245 
246  virtual void _commitMultipleChanges();
247 
248  virtual void _commitMultipleChanges(const GUM_SCALAR&);
249 
250  virtual GUM_SCALAR& _get(const Instantiation& i) const;
251 
252  virtual void _replace(const DiscreteVariable* x, const DiscreteVariable* y);
253  };
254 
255 
256 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
257  extern template class MultiDimArray< double >;
258 #endif
259 
260 
261 } /* namespace gum */
262 
264 
265 #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.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Decorator of a MultiDimArray, using a bijection over the variables.
Definition: multiDimArray.h:39
virtual void erase(const DiscreteVariable &v)
Removes a variable.
virtual GUM_SCALAR & _get(const Instantiation &i) const
Return a data, given a Instantiation.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
virtual void copyFrom(const MultiDimContainer< GUM_SCALAR > &src) const
Copy from a other MultiDimContainer.
Base class for discrete random variable.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
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:54
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:83
MultiDimArray()
Default constructor.
Size Idx
Type for indexes.
Definition: types.h:53
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:48
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.