37 template <
typename GUM_SCALAR >
41 __internalChangeMethod = __InternalChangeMethod::DIRECT_CHANGE;
42 __internalChangeState = __InternalChangeState::NO_CHANGE;
48 template <
typename GUM_SCALAR >
52 __vars(from.__vars), __internalChangeMethod(from.__internalChangeMethod),
53 __internalChangeState(from.__internalChangeState),
54 __domainSize(from.__domainSize) {
56 GUM_ASSERT(!this->_isCommitNeeded());
61 template <
typename GUM_SCALAR >
67 __slaveInstantiations.beginSafe();
68 iter != __slaveInstantiations.endSafe();
70 (*iter)->forgetMaster();
75 template <
typename GUM_SCALAR >
80 if (__vars.exists(&v)) {
82 "Var " << v.
name() <<
" already exists in this instantiation");
84 for (
const auto& w : __vars) {
85 if (w->name() == v.
name())
87 "A var with name '" << v.
name()
88 <<
"' already exists in this instantiation");
97 __slaveInstantiations.beginSafe();
98 iter != __slaveInstantiations.endSafe();
100 (*iter)->addWithMaster(
this, v);
103 if (_isInMultipleChangeMethod()) __setNotCommitedChange();
108 template <
typename GUM_SCALAR >
113 if (!__vars.exists(&v)) {
123 __slaveInstantiations.beginSafe();
124 iter != __slaveInstantiations.endSafe();
126 (*iter)->eraseWithMaster(
this, v);
129 if (_isInMultipleChangeMethod()) __setNotCommitedChange();
135 template <
typename GUM_SCALAR >
137 operator<<(MultiDimImplementation< GUM_SCALAR >& array,
145 template <
typename GUM_SCALAR >
149 if (slave.
nbrDim() != __vars.size())
return false;
153 iter != __vars.endSafe();
155 if (!slave.
contains(*iter))
return false;
159 __slaveInstantiations += (&slave);
166 template <
typename GUM_SCALAR >
169 __slaveInstantiations.eraseByVal(&slave);
174 template <
typename GUM_SCALAR >
176 return __vars.size();
179 template <
typename GUM_SCALAR >
184 template <
typename GUM_SCALAR >
187 return *(__vars.atPos(i));
190 template <
typename GUM_SCALAR >
192 const std::string& name)
const {
193 for (
const auto& v : __vars) {
194 if (v->name() == name)
return *v;
198 "'" << name <<
"' can not be found in the multidim structure.")
201 template <
typename GUM_SCALAR >
204 return __vars.
pos(&v);
207 template <
typename GUM_SCALAR >
210 return __vars.exists(&v);
215 template <
typename GUM_SCALAR >
222 template <
typename GUM_SCALAR >
224 GUM_ASSERT(!this->_isCommitNeeded());
225 return __vars.empty();
228 template <
typename GUM_SCALAR >
230 __internalChangeMethod = __InternalChangeMethod::MULTIPLE_CHANGE;
233 template <
typename GUM_SCALAR >
235 if (__internalChangeState == __InternalChangeState::NOT_COMMITTED_CHANGE) {
236 _commitMultipleChanges();
237 __internalChangeState = __InternalChangeState::NO_CHANGE;
240 __internalChangeMethod = __InternalChangeMethod::DIRECT_CHANGE;
243 template <
typename GUM_SCALAR >
245 const GUM_SCALAR& x) {
246 if (__internalChangeState == __InternalChangeState::NOT_COMMITTED_CHANGE) {
247 _commitMultipleChanges(x);
248 __internalChangeState = __InternalChangeState::NO_CHANGE;
251 __internalChangeMethod = __InternalChangeMethod::DIRECT_CHANGE;
254 template <
typename GUM_SCALAR >
259 template <
typename GUM_SCALAR >
266 template <
typename GUM_SCALAR >
269 return (__internalChangeMethod == __InternalChangeMethod::MULTIPLE_CHANGE);
273 template <
typename GUM_SCALAR >
275 return (__internalChangeState == __InternalChangeState::NOT_COMMITTED_CHANGE);
279 template <
typename GUM_SCALAR >
282 return __slaveInstantiations;
286 template <
typename GUM_SCALAR >
288 __internalChangeState = __InternalChangeState::NOT_COMMITTED_CHANGE;
292 template <
typename GUM_SCALAR >
294 return ((
float)1) - (float)realSize() / (float)domainSize();
298 template <
typename GUM_SCALAR >
300 static const std::string str =
"MultiDimImplementation";
304 template <
typename GUM_SCALAR >
308 __vars.setAtPos(__vars.pos(x), y);
311 __slaveInstantiations.beginSafe();
312 iter != __slaveInstantiations.endSafe();
318 template <
typename GUM_SCALAR >
324 template <
typename GUM_SCALAR >
328 return out << static_cast< const MultiDimContainer< GUM_SCALAR >& >(array);
333 template <
typename GUM_SCALAR >
340 template <
typename GUM_SCALAR >
Safe iterators for Sequence.
Idx nbrDim() const final
Returns the number of variables in the Instantiation.
Safe iterators for Lists.
The generic class for storing (ordered) sequences of objects.
Base class for discrete random variable.
Generic doubly linked lists.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
Abstract base class for all multi dimensionnal containers.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
virtual Size domainSize() const =0
MultiDimImplementation()
Default constructor.
INLINE std::ostream & operator<<(std::ostream &out, const MultiDimImplementation< GUM_SCALAR > &array)
For friendly displaying the content of the array.
Class for assigning/browsing values to tuples of discrete variables.
bool contains(const DiscreteVariable &v) const final
Indicates whether a given variable belongs to the Instantiation.
void synchronizeWithMaster(const MultiDimAdressable *m)
Force the variables sequence to be the same as the master one.
void replace(const DiscreteVariable &x, const DiscreteVariable &y)
Replace variables in this multidim.
<agrum/multidim/multiDimImplementation.h>
Size Idx
Type for indexes.
virtual Idx pos(const DiscreteVariable &v) const override
Returns the index of a variable.
std::size_t Size
In aGrUM, hashed values are unsigned long int.
const std::string & name() const
returns the name of the variable
#define GUM_ERROR(type, msg)