aGrUM  0.20.3
a C++ library for (probabilistic) graphical models
multiDimBijArray.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 the MultiDimBijArray class.
25  *
26  * @author Pierre-Henri WUILLEMIN(@LIP6) & Christophe GONZALES(@AMU)
27  * @author Lionel TORTI
28  */
29 
30 #ifndef GUM_MULTIDIMBIJARRAY_H
31 #define GUM_MULTIDIMBIJARRAY_H
32 
33 #include <initializer_list>
34 
35 #include <agrum/tools/core/bijection.h>
36 
37 #include <agrum/tools/multidim/implementations/multiDimArray.h>
38 #include <agrum/tools/multidim/implementations/multiDimWithOffset.h>
39 
40 namespace gum {
41 
42  /**
43  * @class MultiDimBijArray
44  * @headerfile multiDimBijArray.h <agrum/tools/multidim/multiDimBijArray.h>
45  * @ingroup multidim_group
46  *
47  * @brief Decorator of a MultiDimArray, using a bijection over the variables.
48  *
49  * @tparam GUM_SCALAR The type of scaler stored in this multidimensional
50  * table.
51  */
52  template < typename GUM_SCALAR >
54  public:
56 
57  // =========================================================================
58  /// @name Constructors / Destructors
59  // =========================================================================
60  /// @{
61 
62  /**
63  * @brief Class constructor.
64  *
65  * @param bijection The bijection between variables in array and variable
66  * in this.
67  * @param array The MultiDimArray decorated by this MultiDimBijArray.
68  */
69  MultiDimBijArray(const VarBijection& bijection, const MultiDimArray< GUM_SCALAR >& array);
70 
71  /**
72  * @brief Class constructor.
73  *
74  * @param bijection The bijection between variables in array and variable
75  * in this.
76  * @param array The MultiDimBijArray decorated by this MultiDimBijArray.
77  */
78  MultiDimBijArray(const VarBijection& bijection, const MultiDimBijArray< GUM_SCALAR >& array);
79 
80  /**
81  * @brief Copy constructor.
82  *
83  * The newly created matrix contains the same variables and the same values
84  * as from, but no instantiation is associated to it.
85  *
86  * @param from The MultiDimBijArray to copy.
87  */
88  MultiDimBijArray(const MultiDimBijArray< GUM_SCALAR >& from);
89 
90  /**
91  * @brief Class destructor.
92  */
93  virtual ~MultiDimBijArray();
94 
95  /// @}
96  // ========================================================================
97  /// @name Modifiers -- will raise OperationNotAllowed exceptions
98  // ========================================================================
99  /// @{
100  /**
101  * @warning This will raise an exception: read only structure.
102  * @throw OperationNotAllowed Raised since you can't change a readonly
103  * structure.
104  */
105  MultiDimBijArray< GUM_SCALAR >& operator=(const MultiDimBijArray< GUM_SCALAR >& from);
106 
107  /**
108  * @warning This will raise an exception: read only structure.
109  * @throw OperationNotAllowed Raised since you can't change a readonly
110  * structure.
111  */
112  virtual void set(const Instantiation& i, const GUM_SCALAR& value) const;
113 
114  /**
115  * This will raise an exception: you can't change the variables in a
116  * MultiDimBijArray.
117  * @param v The variable not added.
118  * @throw OperationNotAllowed You can't add variable in a MultiDimBijArray.
119  */
120  virtual void add(const DiscreteVariable& v);
121 
122  /**
123  * This will raise an exception: you can't change the variables in a
124  * MultiDimBijArray.
125  * @param v The variable not added.
126  * @throw OperationNotAllowed You can't add variable in a MultiDimBijArray.
127  */
128  virtual void erase(const DiscreteVariable& v);
129 
130  /**
131  * This will raise an exception: you can't change the data
132  * @param d the value changed
133  * @throw OperationNotAllowed You can't change data.
134  */
135  virtual void fill(const GUM_SCALAR& d) const;
136 
137  /**
138  * This will raise an exception: you can't change the variables in a
139  * MultiDimBijArray.
140  * @param v The variable not added.
141  * @throw OperationNotAllowed You can't add variable in a MultiDimBijArray.
142  */
143  virtual void populate(const std::vector< GUM_SCALAR >& v) const;
144 
145  /**
146  * This will raise an exception: you can't change the variables in a
147  * MultiDimBijArray.
148  * @param l The variable not added.
149  * @throw OperationNotAllowed You can't add variable in a MultiDimBijArray.
150  */
151  virtual void populate(std::initializer_list< GUM_SCALAR > l) const;
152 
153  /// @}
154  // ========================================================================
155  /// @name Inherited methods
156  // ========================================================================
157  /// @{
158 
159  virtual const std::string& name() const;
160 
161  virtual GUM_SCALAR get(const Instantiation& i) const;
162 
163  virtual Size realSize() const;
164 
165  virtual MultiDimBijArray< GUM_SCALAR >* newFactory() const;
166 
167  /// @}
168 
169  protected:
170  virtual GUM_SCALAR& get_(const Instantiation& i) const;
171 
172  virtual void commitMultipleChanges_();
173 
174  virtual void replace_(const DiscreteVariable* x, const DiscreteVariable* y);
175 
176  private:
177  /// The true data.
179 
180  /// The class name.
182  };
183 
184 
185 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
186  extern template class MultiDimBijArray< double >;
187 #endif
188 
189 } // namespace gum
190 
191 #include <agrum/tools/multidim/implementations/multiDimBijArray_tpl.h>
192 
193 #endif // GUM_MULTIDIMBIJARRAY_H
MultiDimBijArray(const MultiDimBijArray< GUM_SCALAR > &from)
Copy constructor.
virtual const std::string & name() const
Returns the real name of the multiDim implementation.
MultiDimBijArray< GUM_SCALAR > & operator=(const MultiDimBijArray< GUM_SCALAR > &from)
INLINE void emplace(Args &&... args)
Definition: set_tpl.h:643
virtual void fill(const GUM_SCALAR &d) const
This will raise an exception: you can&#39;t change the data.
const MultiDimArray< GUM_SCALAR > & _array_
The true data.
virtual Size realSize() const
Returns the real number of parameters used for this table.
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
virtual void commitMultipleChanges_()
Synchronize content after MultipleChanges.
virtual MultiDimBijArray< GUM_SCALAR > * newFactory() const
Class constructor.
MultiDimBijArray(const VarBijection &bijection, const MultiDimArray< GUM_SCALAR > &array)
Class constructor.
virtual void populate(const std::vector< GUM_SCALAR > &v) const
This will raise an exception: you can&#39;t change the variables in a MultiDimBijArray.
std::string _name_
The class name.
virtual GUM_SCALAR & get_(const Instantiation &i) const
Return a data, given a Instantiation.
virtual void add(const DiscreteVariable &v)
This will raise an exception: you can&#39;t change the variables in a MultiDimBijArray.
virtual ~MultiDimBijArray()
Class destructor.
friend class MultiDimBijArray
Definition: multiDimArray.h:56
virtual void erase(const DiscreteVariable &v)
This will raise an exception: you can&#39;t change the variables in a MultiDimBijArray.
MultiDimBijArray(const VarBijection &bijection, const MultiDimBijArray< GUM_SCALAR > &array)
Class constructor.
virtual void populate(std::initializer_list< GUM_SCALAR > l) const
This will raise an exception: you can&#39;t change the variables in a MultiDimBijArray.