34 template <
typename GUM_SCALAR >
38 __internalChangeMethod = __InternalChangeMethod::DIRECT_CHANGE;
39 __internalChangeState = __InternalChangeState::NO_CHANGE;
45 template <
typename GUM_SCALAR >
49 __vars(from.__vars), __internalChangeMethod(from.__internalChangeMethod),
50 __internalChangeState(from.__internalChangeState),
51 __domainSize(from.__domainSize) {
53 GUM_ASSERT(!this->_isCommitNeeded());
58 template <
typename GUM_SCALAR >
64 __slaveInstantiations.beginSafe();
65 iter != __slaveInstantiations.endSafe();
67 (*iter)->forgetMaster();
72 template <
typename GUM_SCALAR >
77 if (__vars.exists(&v)) {
79 "Var " << v.
name() <<
" already exists in this instantiation");
81 for (
const auto& w : __vars) {
82 if (w->name() == v.
name())
84 "A var with name '" << v.
name()
85 <<
"' already exists in this instantiation");
94 __slaveInstantiations.beginSafe();
95 iter != __slaveInstantiations.endSafe();
97 (*iter)->addWithMaster(
this, v);
100 if (_isInMultipleChangeMethod()) __setNotCommitedChange();
105 template <
typename GUM_SCALAR >
110 if (!__vars.exists(&v)) {
120 __slaveInstantiations.beginSafe();
121 iter != __slaveInstantiations.endSafe();
123 (*iter)->eraseWithMaster(
this, v);
126 if (_isInMultipleChangeMethod()) __setNotCommitedChange();
132 template <
typename GUM_SCALAR >
134 operator<<(MultiDimImplementation< GUM_SCALAR >& array,
142 template <
typename GUM_SCALAR >
146 if (slave.
nbrDim() != __vars.size())
return false;
150 iter != __vars.endSafe();
152 if (!slave.
contains(*iter))
return false;
156 __slaveInstantiations += (&slave);
163 template <
typename GUM_SCALAR >
166 __slaveInstantiations.eraseByVal(&slave);
171 template <
typename GUM_SCALAR >
173 return __vars.size();
176 template <
typename GUM_SCALAR >
181 template <
typename GUM_SCALAR >
184 return *(__vars.atPos(i));
187 template <
typename GUM_SCALAR >
189 const std::string& name)
const {
190 for (
const auto& v : __vars) {
191 if (v->name() == name)
return *v;
195 "'" << name <<
"' can not be found in the multidim structure.")
198 template <
typename GUM_SCALAR >
201 return __vars.
pos(&v);
204 template <
typename GUM_SCALAR >
207 return __vars.exists(&v);
212 template <
typename GUM_SCALAR >
219 template <
typename GUM_SCALAR >
221 GUM_ASSERT(!this->_isCommitNeeded());
222 return __vars.empty();
225 template <
typename GUM_SCALAR >
227 __internalChangeMethod = __InternalChangeMethod::MULTIPLE_CHANGE;
230 template <
typename GUM_SCALAR >
232 if (__internalChangeState == __InternalChangeState::NOT_COMMITTED_CHANGE) {
233 _commitMultipleChanges();
234 __internalChangeState = __InternalChangeState::NO_CHANGE;
237 __internalChangeMethod = __InternalChangeMethod::DIRECT_CHANGE;
240 template <
typename GUM_SCALAR >
242 const GUM_SCALAR& x) {
243 if (__internalChangeState == __InternalChangeState::NOT_COMMITTED_CHANGE) {
244 _commitMultipleChanges(x);
245 __internalChangeState = __InternalChangeState::NO_CHANGE;
248 __internalChangeMethod = __InternalChangeMethod::DIRECT_CHANGE;
251 template <
typename GUM_SCALAR >
256 template <
typename GUM_SCALAR >
263 template <
typename GUM_SCALAR >
266 return (__internalChangeMethod == __InternalChangeMethod::MULTIPLE_CHANGE);
270 template <
typename GUM_SCALAR >
272 return (__internalChangeState == __InternalChangeState::NOT_COMMITTED_CHANGE);
276 template <
typename GUM_SCALAR >
279 return __slaveInstantiations;
283 template <
typename GUM_SCALAR >
285 __internalChangeState = __InternalChangeState::NOT_COMMITTED_CHANGE;
289 template <
typename GUM_SCALAR >
291 return ((
float)1) - (float)realSize() / (float)domainSize();
295 template <
typename GUM_SCALAR >
297 static const std::string str =
"MultiDimImplementation";
301 template <
typename GUM_SCALAR >
305 __vars.setAtPos(__vars.pos(x), y);
308 __slaveInstantiations.beginSafe();
309 iter != __slaveInstantiations.endSafe();
315 template <
typename GUM_SCALAR >
321 template <
typename GUM_SCALAR >
325 return out << static_cast< const MultiDimContainer< GUM_SCALAR >& >(array);
330 template <
typename GUM_SCALAR >
337 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.
gum is the global namespace for all aGrUM entities
Abstract base class for all multi dimensionnal containers.
Headers of gum::MultiDimImplementation.
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)