59 template <
typename GUM_ELEMENT >
66 template <
typename GUM_ELEMENT >
72 template <
typename GUM_ELEMENT >
78 template <
typename GUM_ELEMENT >
85 template <
typename GUM_ELEMENT >
95 template <
typename GUM_ELEMENT >
102 template <
typename GUM_ELEMENT >
109 template <
typename GUM_ELEMENT >
111 const GUM_ELEMENT& value)
const {
117 template <
typename GUM_ELEMENT >
124 template <
typename GUM_ELEMENT >
128 if (this->
nbrDim() == 0) {
return "[]"; }
130 std::stringstream ss;
135 for (inst.setFirst(); !inst.end(); ++inst) {
136 if (!first) { ss <<
" /"; }
139 ss << inst <<
" :: " << get(inst);
147 template <
typename GUM_ELEMENT >
151 if (
nbrDim() == 0)
return true;
163 for (i.setFirst(); !i.end(); ++i) {
164 if (cmp(
get(i), p.
get(i))) {
return false; }
171 template <
typename GUM_ELEMENT >
185 template <
typename GUM_ELEMENT >
193 for (
const auto& elt: l) {
199 template <
typename GUM_ELEMENT >
207 template <
typename GUM_ELEMENT >
209 std::function< GUM_ELEMENT(GUM_ELEMENT, GUM_ELEMENT) > f,
210 GUM_ELEMENT base)
const {
211 GUM_ELEMENT tmp = base;
214 tmp = f(tmp,
get(i));
219 template <
typename GUM_ELEMENT >
227 if (p_i ==
nullptr) {
233 Instantiation i_dest(*
this);
234 Instantiation i_src(src);
235 for (i_dest.setFirst(), i_src.setFirst(); !i_dest.end(); i_dest.incIn(*p_i), ++i_src) {
236 set(i_dest, src[i_src]);
241 template <
typename GUM_ELEMENT >
247 for (
Idx i = 0; i < nbr; i++) {
255 this->endMultipleChanges();
259 Instantiation inst(src);
261 for (inst.setFirstOut(imask); !inst.end(); inst.incOut(imask))
262 set(inst, src[inst]);
265 template <
typename GUM_ELEMENT >
277 set(i_dest, src[i_src]);
283 template <
typename GUM_ELEMENT >
289 for (
Idx i = 0; i < nbr; i++) {
301 template <
typename GUM_ELEMENT >
306 template <
typename GUM_ELEMENT >
313 template <
typename GUM_ELEMENT >
Exception : fatal (unknown ?) error.
Class for assigning/browsing values to tuples of discrete variables.
bool end() const
Returns true if the Instantiation reached the end.
bool contains(const DiscreteVariable &v) const final
Indicates whether a given variable belongs to the Instantiation.
void setFirst()
Assign the first values to the tuple of the Instantiation.
MultiDimAdressable()
Default constructor.
MultiDimAdressable & operator=(const MultiDimAdressable &from)
Default constructor.
Abstract base class for all multi dimensionnal containers.
bool operator==(const MultiDimContainer< GUM_ELEMENT > &p) const
Test if this MultiDimContainer is equal to p.
MultiDimContainer & operator=(const MultiDimContainer< GUM_ELEMENT > &src)
Default constructor.
virtual void beginMultipleChanges()=0
Call this method before doing important changes in this MultiDimContainer.
virtual void set(const Instantiation &i, const GUM_ELEMENT &value) const
Changes the value pointed by i.
virtual void copy(const MultiDimContainer< GUM_ELEMENT > &src)
Removes all variables in this MultiDimContainer and copy the content of src, variables included.
virtual void copyFrom(const MultiDimContainer< GUM_ELEMENT > &src) const
Basic copy of a MultiDimContainer.
virtual void populate(const std::vector< GUM_ELEMENT > &v) const
Automatically fills this MultiDimContainer with the values in v.
virtual GUM_ELEMENT get(const Instantiation &i) const
Returns the value pointed by i.
virtual GUM_ELEMENT reduce(std::function< GUM_ELEMENT(GUM_ELEMENT, GUM_ELEMENT) > f, GUM_ELEMENT base) const
compute lfold for this container
virtual const MultiDimImplementation< GUM_ELEMENT > * content() const =0
Returns the implementation for this object (may be *this).
MultiDimContainer()
Default constructor.
virtual void endMultipleChanges()=0
Call this method after doing important changes in this MultiDimContainer.
GUM_ELEMENT operator[](const Instantiation &i) const
An [] operator using a Instantiation as argument.
virtual void extractFrom(const MultiDimContainer< GUM_ELEMENT > &src, const Instantiation &mask)
Basic extraction of a MultiDimContainer.
virtual void apply(std::function< GUM_ELEMENT(GUM_ELEMENT) > f) const
Apply a function on every element of the container.
virtual std::string toString() const
Returns a representation of this MultiDimContainer.
MultiDimAdressable & getMasterRef() override
In order to insure the dereference for decorators, we need to virtualize the access to master pointer...
virtual GUM_ELEMENT & get_(const Instantiation &i) const =0
Return a data, given a Instantiation.
~MultiDimContainer() override
Destructor.
virtual const Sequence< const DiscreteVariable * > & variablesSequence() const =0
Returns a const ref to the sequence of DiscreteVariable*.
virtual Size domainSize() const =0
Returns the product of the variables domain size.
virtual void add(const DiscreteVariable &v)=0
virtual Idx nbrDim() const =0
Returns the number of vars in the multidimensional container.
virtual const DiscreteVariable & variable(Idx i) const =0
Returns a const ref to the ith var.
virtual void erase(const DiscreteVariable &v)=0
Removes a var from the variables of the multidimensional matrix.
Exception : operation not allowed.
Exception : problem with size.
#define GUM_ERROR(type, msg)
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Size Idx
Type for indexes.
Headers of the MultiDimContainer class.
gum is the global namespace for all aGrUM entities
std::ostream & operator<<(std::ostream &stream, const AVLTree< Val, Cmp > &tree)
display the content of a tree
Indicate whether two elements are (almost) different or not.