aGrUM  0.20.2
a C++ library for (probabilistic) graphical models
multiDimBijArray.h
Go to the documentation of this file.
1 /**
2  *
3  * Copyright 2005-2020 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:
55  using VarBijection
57 
58  // =========================================================================
59  /// @name Constructors / Destructors
60  // =========================================================================
61  /// @{
62 
63  /**
64  * @brief Class constructor.
65  *
66  * @param bijection The bijection between variables in array and variable
67  * in this.
68  * @param array The MultiDimArray decorated by this MultiDimBijArray.
69  */
70  MultiDimBijArray(const VarBijection& bijection,
71  const MultiDimArray< GUM_SCALAR >& array);
72 
73  /**
74  * @brief Class constructor.
75  *
76  * @param bijection The bijection between variables in array and variable
77  * in this.
78  * @param array The MultiDimBijArray decorated by this MultiDimBijArray.
79  */
80  MultiDimBijArray(const VarBijection& bijection,
81  const MultiDimBijArray< GUM_SCALAR >& array);
82 
83  /**
84  * @brief Copy constructor.
85  *
86  * The newly created matrix contains the same variables and the same values
87  * as from, but no instantiation is associated to it.
88  *
89  * @param from The MultiDimBijArray to copy.
90  */
91  MultiDimBijArray(const MultiDimBijArray< GUM_SCALAR >& from);
92 
93  /**
94  * @brief Class destructor.
95  */
96  virtual ~MultiDimBijArray();
97 
98  /// @}
99  // ========================================================================
100  /// @name Modifiers -- will raise OperationNotAllowed exceptions
101  // ========================================================================
102  /// @{
103  /**
104  * @warning This will raise an exception: read only structure.
105  * @throw OperationNotAllowed Raised since you can't change a readonly
106  * structure.
107  */
108  MultiDimBijArray< GUM_SCALAR >&
109  operator=(const MultiDimBijArray< GUM_SCALAR >& from);
110 
111  /**
112  * @warning This will raise an exception: read only structure.
113  * @throw OperationNotAllowed Raised since you can't change a readonly
114  * structure.
115  */
116  virtual void set(const Instantiation& i, const GUM_SCALAR& value) const;
117 
118  /**
119  * This will raise an exception: you can't change the variables in a
120  * MultiDimBijArray.
121  * @param v The variable not added.
122  * @throw OperationNotAllowed You can't add variable in a MultiDimBijArray.
123  */
124  virtual void add(const DiscreteVariable& v);
125 
126  /**
127  * This will raise an exception: you can't change the variables in a
128  * MultiDimBijArray.
129  * @param v The variable not added.
130  * @throw OperationNotAllowed You can't add variable in a MultiDimBijArray.
131  */
132  virtual void erase(const DiscreteVariable& v);
133 
134  /**
135  * This will raise an exception: you can't change the data
136  * @param d the value changed
137  * @throw OperationNotAllowed You can't change data.
138  */
139  virtual void fill(const GUM_SCALAR& d) const;
140 
141  /**
142  * This will raise an exception: you can't change the variables in a
143  * MultiDimBijArray.
144  * @param v The variable not added.
145  * @throw OperationNotAllowed You can't add variable in a MultiDimBijArray.
146  */
147  virtual void populate(const std::vector< GUM_SCALAR >& v) const;
148 
149  /**
150  * This will raise an exception: you can't change the variables in a
151  * MultiDimBijArray.
152  * @param l The variable not added.
153  * @throw OperationNotAllowed You can't add variable in a MultiDimBijArray.
154  */
155  virtual void populate(std::initializer_list< GUM_SCALAR > l) const;
156 
157  /// @}
158  // ========================================================================
159  /// @name Inherited methods
160  // ========================================================================
161  /// @{
162 
163  virtual const std::string& name() const;
164 
165  virtual GUM_SCALAR get(const Instantiation& i) const;
166 
167  virtual Size realSize() const;
168 
169  virtual MultiDimBijArray< GUM_SCALAR >* newFactory() const;
170 
171  /// @}
172 
173  protected:
174  virtual GUM_SCALAR& get_(const Instantiation& i) const;
175 
176  virtual void commitMultipleChanges_();
177 
178  virtual void replace_(const DiscreteVariable* x, const DiscreteVariable* y);
179 
180  private:
181  /// The true data.
183 
184  /// The class name.
186  };
187 
188 
189 #ifndef GUM_NO_EXTERN_TEMPLATE_CLASS
190  extern template class MultiDimBijArray< double >;
191 #endif
192 
193 } // namespace gum
194 
195 #include <agrum/tools/multidim/implementations/multiDimBijArray_tpl.h>
196 
197 #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:669
virtual void fill(const GUM_SCALAR &d) const
This will raise an exception: you can&#39;t change the 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.
const MultiDimArray< GUM_SCALAR > & array__
The true data.
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.
std::string name__
The class name.
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.
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.