aGrUM  0.14.2
multiDimBijArray_tpl.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  ***************************************************************************/
29 
30 namespace gum {
31 
32  template < typename GUM_SCALAR >
34  const MultiDimBijArray< GUM_SCALAR >& from) :
35  MultiDimWithOffset< GUM_SCALAR >(),
36  __array(from.__array), __name(from.__name) {
37  GUM_CONS_CPY(MultiDimBijArray);
38 
39  for (auto var : from.variablesSequence()) {
41  }
42  }
43 
44  template < typename GUM_SCALAR >
46  const VarBijection& bijection, const MultiDimArray< GUM_SCALAR >& array) :
47  MultiDimWithOffset< GUM_SCALAR >(),
48  __array(array), __name("MultiDimBijArray") {
49  GUM_CONSTRUCTOR(MultiDimBijArray);
50 
51  for (auto var : array.variablesSequence()) {
53  }
54  }
55 
56  template < typename GUM_SCALAR >
58  const VarBijection& bijection, const MultiDimBijArray< GUM_SCALAR >& array) :
59  MultiDimWithOffset< GUM_SCALAR >(),
60  __array(array.__array), __name("MultiDimBijArray") {
61  GUM_CONSTRUCTOR(MultiDimBijArray);
62 
63  for (auto var : array.variablesSequence()) {
65  }
66  }
67 
68  template < typename GUM_SCALAR >
70  GUM_DESTRUCTOR(MultiDimBijArray);
71  }
72 
73  template < typename GUM_SCALAR >
76  GUM_ERROR(OperationNotAllowed, "MultiDimBijArray are readonly.");
77  }
78 
79  template < typename GUM_SCALAR >
82  return new MultiDimBijArray< GUM_SCALAR >(*this);
83  }
84 
85  template < typename GUM_SCALAR >
86  INLINE const std::string& MultiDimBijArray< GUM_SCALAR >::name() const {
87  return __name;
88  }
89 
90  template < typename GUM_SCALAR >
92  GUM_ERROR(OperationNotAllowed, "MultiDimBijArray<GUM_SCALAR> are read only.");
93  }
94 
95  template < typename GUM_SCALAR >
97  GUM_ERROR(OperationNotAllowed, "MultiDimBijArray<GUM_SCALAR> are read only.");
98  }
99 
100  template < typename GUM_SCALAR >
102  return (Size)0;
103  }
104 
105  template < typename GUM_SCALAR >
106  INLINE void MultiDimBijArray< GUM_SCALAR >::fill(const GUM_SCALAR& d) const {
107  GUM_ERROR(OperationNotAllowed, "MultiDimBijArray<GUM_SCALAR> are read only.");
108  }
109 
110  template < typename GUM_SCALAR >
112  // Do nothing
113  }
114 
115  template < typename GUM_SCALAR >
116  INLINE GUM_SCALAR
118  if (i.isMaster(this)) {
119  return __array._values[this->_offsets[&i]];
120  } else {
121  return __array._values[this->_getOffs(i)];
122  }
123  }
124 
125  template < typename GUM_SCALAR >
127  const GUM_SCALAR& value) const {
128  GUM_ERROR(OperationNotAllowed, "MultiDimBijArray<GUM_SCALAR> are read only.");
129  }
130 
131  template < typename GUM_SCALAR >
133  const std::vector< GUM_SCALAR >& v) const {
134  GUM_ERROR(OperationNotAllowed, "MultiDimBijArray<GUM_SCALAR> are read only.");
135  }
136 
137  template < typename GUM_SCALAR >
139  std::initializer_list< GUM_SCALAR > l) const {
140  GUM_ERROR(OperationNotAllowed, "MultiDimBijArray<GUM_SCALAR> are read only.");
141  }
142 
143  template < typename GUM_SCALAR >
144  INLINE GUM_SCALAR&
146  GUM_ERROR(OperationNotAllowed, "MultiDimBijArray<GUM_SCALAR> are read only.");
147  }
148 
149  template < typename GUM_SCALAR >
151  const DiscreteVariable* y) {
153  }
154 
155 } // namespace gum
virtual GUM_SCALAR & _get(const Instantiation &i) const
Return a data, given a Instantiation.
const MultiDimArray< GUM_SCALAR > & __array
The true data.
const T2 & second(const T1 &first) const
Returns the second value of a pair given its first value.
Decorator of a MultiDimArray, using a bijection over the variables.
Definition: multiDimArray.h:36
virtual const std::string & name() const
Returns the real name of the multiDim implementation.
HashTable< const Instantiation *, Size > _offsets
The position in the array of each slave Instantiation.
MultiDimBijArray< GUM_SCALAR > & operator=(const MultiDimBijArray< GUM_SCALAR > &from)
Headers of the MultiDimBijArray class.
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.
std::string __name
The class name.
virtual GUM_SCALAR get(const Instantiation &i) const
Returns the value pointed by i.
Base class for discrete random variable.
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
virtual void _commitMultipleChanges()
Synchronize content after MultipleChanges.
virtual void add(const DiscreteVariable &v)
Adds a new var to the variables of the multidimensional matrix.
virtual void set(const Instantiation &i, const GUM_SCALAR &value) const
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.
Abstract class for Multidimensional matrix stored as an array in memory and with an offset associated...
virtual void _replace(const DiscreteVariable *x, const DiscreteVariable *y) override
Replace variable x by y.
Multidimensional matrix stored as an array in memory.
Definition: multiDimArray.h:51
Set of pairs of elements with fast search for both elements.
Definition: bijection.h:1803
Size _getOffs(const Instantiation &i) const
Compute the offset of a Instantiation.
virtual void add(const DiscreteVariable &v)
This will raise an exception: you can&#39;t change the variables in a MultiDimBijArray.
virtual const Sequence< const DiscreteVariable *> & variablesSequence() const override
Returns a const ref to the sequence of DiscreteVariable*.
Class for assigning/browsing values to tuples of discrete variables.
Definition: instantiation.h:80
virtual ~MultiDimBijArray()
Class destructor.
bool isMaster(const MultiDimAdressable *m) const
Indicates whether m is the master of this instantiation.
virtual void erase(const DiscreteVariable &v)
This will raise an exception: you can&#39;t change the variables in a MultiDimBijArray.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition: types.h:45
#define GUM_ERROR(type, msg)
Definition: exceptions.h:52
virtual void _replace(const DiscreteVariable *x, const DiscreteVariable *y)
Replace variable x by y.