aGrUM 2.3.2
a C++ library for (probabilistic) graphical models
gum::ScheduleMultiDim< TABLE > Class Template Reference

a Wrapper for multi-dimensional tables used for scheduling inferences More...

#include <agrum/base/graphicalModels/inference/scheduler/scheduleMultiDim.h>

Inheritance diagram for gum::ScheduleMultiDim< TABLE >:
Collaboration diagram for gum::ScheduleMultiDim< TABLE >:

Classes

struct  ElementType
 metaprogramming to get the types of the elements stored into the ScheduleMultidims More...
struct  ElementType< CONTAINER< T, Args... > >

Public Member Functions

Constructors / Destructors
 ScheduleMultiDim (const TABLE &table, const bool copy, const Idx id=0)
 constructs a ScheduleMultiDim by copying/referencing table
 ScheduleMultiDim (TABLE &&table, const Idx id=0)
 constructs a ScheduleMultiDim by moving a table inside it
 ScheduleMultiDim (const Sequence< const DiscreteVariable * > &vars, const Idx id=0)
 construct a ScheduleMultiDim for a multidimensional table yet to be built
 ScheduleMultiDim (const ScheduleMultiDim< TABLE > &from)
 copy constructor
 ScheduleMultiDim (ScheduleMultiDim< TABLE > &&from)
 move constructor
virtual ScheduleMultiDim< TABLE > * clone () const
 virtual copy constructor
virtual ScheduleMultiDim< TABLE > * clone (bool force_copy) const
 virtual copy constructor enabling to force a copy of the content
virtual ~ScheduleMultiDim ()
 destructor
Operators
ScheduleMultiDim< TABLE > & operator= (const ScheduleMultiDim< TABLE > &from)
 copy operator
ScheduleMultiDim< TABLE > & operator= (ScheduleMultiDim< TABLE > &&from)
 move operator
virtual bool operator== (const ScheduleMultiDim< TABLE > &) const
 checks whether two ScheduleMultiDim have exactly the same ID
virtual bool operator== (const IScheduleMultiDim &) const
 checks whether two ScheduleMultiDim have the same ID and type
virtual bool operator!= (const ScheduleMultiDim< TABLE > &) const
 checks whether two ScheduleMultiDim have different IDs
virtual bool operator!= (const IScheduleMultiDim &) const
 checks whether two ScheduleMultiDim have different IDs or types
Accessors/Modifiers
virtual bool hasSameVariables (const IScheduleMultiDim &m) const
 checks whether two ScheduleMultiDim have the same variables and types
virtual bool hasSameVariables (const ScheduleMultiDim< TABLE > &m) const
 checks whether two ScheduleMultiDim have the same variables
virtual bool hasSameContent (const IScheduleMultiDim &) const
 checks whether two ScheduleMultiDim contain precisely the same table
virtual bool hasSameContent (const ScheduleMultiDim< TABLE > &) const
 checks whether two ScheduleMultiDim contain precisely the same table
bool isAbstract () const final
 returns whether the ScheduleMultiDim contains a real table or not
bool containsMultiDim () const final
 indicates whether the ScheduleMultiDim contains a table and possesses it
void makeAbstract () final
 if the ScheduleMultiDim is not abstract, make it abstract again
TABLE * exportMultiDim ()
 returns the contained multidimensional table, if any, and make the ScheduleMultiDim abstract
const TABLE & multiDim () const
 returns the table actually contained in the ScheduleMultiDim
const Sequence< const DiscreteVariable * > & variablesSequence () const final
 returns the set of variables involved in the ScheduleMultiDim
Size domainSize () const final
 returns the domain size the table would have after its creation
double sizeOfContent () const final
 returns the sizeof of the elements stored into the ScheduleMultiDim
void setMultiDim (const TABLE &table, const bool copy)
 assigns a new table inside the wrapper
void setMultiDim (TABLE &&pot)
 sets by move a new table inside the wrapper
std::string toString () const final
 displays the content of the ScheduleMultiDim

Protected Attributes

Idx id_
 the unique Id of the ScheduleMultiDim

Private Member Functions

void _removeTable_ ()
 remove the table if it is contained in the ScheduleMultiDim

Static Private Member Functions

static Idx _newId_ ()
 returns a new distinct ID for each abstract scheduleMultiDim

Private Attributes

TABLE * _table_ {nullptr}
 the multidimensional table stored into the ScheduleMultiDim
bool _table_contained_ {true}
 indicates whether table is contained or referenced
Sequence< const DiscreteVariable * > _var_sequence_
 returns the sequence of variables of the table
Size _domain_size_ {Size(1)}
 the domain size of the table

Static Private Attributes

static std::atomic< Idx_multidim_id_

Accessors/Modifiers

Idx id () const
 returns the id of the ScheduleMultiDim
static void resetIdGenerator ()
 reset the id generator to 0

Detailed Description

template<typename TABLE>
class gum::ScheduleMultiDim< TABLE >

a Wrapper for multi-dimensional tables used for scheduling inferences

A ScheduleMultiDim is a wrapper that contains either a "real" multidmensional table or a nullptr if this table has not been computed yet (by an executor).

Here is a brief piece of code that should highlight the concept:

// some arbitrary tensors (to be initialized before going on)
gum::Tensor< float > pot1, pot2, pot3;
// we wish to schedule ( pot1 + pot2 ) + pot3
// so, first, create ScheduleMultiDims for wrapping these tensors
// now schedule a combination (+) between f1 and f2
gum::ScheduleCombination< gum::Tensor< float >,
gum::Tensor< float > > comb1 ( &f1, &f2, add );
// get the result and schedule it with f3
const ScheduleMultiDim< gum::Tensor< float > >& result1 = comb1.result ();
gum::ScheduleCombination< gum::Tensor< float >,
gum::Tensor< float > > comb2 ( &result2, &f3, add );
// get the resulting ScheduleMultiDim
const ScheduleMultiDim<gum::Tensor< float > >& result2 = comb2.result ();
// here, no addition has been performed yet. We just have a structure
// that indicates which operations we wish to do. So, for the moment,
// result1 and result2 do not contain real Tensors.
// As such, they are called abstract and trying to get their "real"
// Tensor (using method multiDim()) would throw a NullElement exception.
std::cout << result1.isAbstract ();
std::cout << result2.isAbstract ();
std::cout << ! f1.isAbstract ();
// now, we can actually perform the operators
comb1.execute ();
std::cout << ! result1.isAbstract ();
comb2.execute ();
// here, we can display the content of the real Tensor stored
// into result2
std::cout << result2.multiDim ();
a Wrapper for multi-dimensional tables used for scheduling inferences
const TABLE & multiDim() const
returns the table actually contained in the ScheduleMultiDim
ScheduleMultiDim(const TABLE &table, const bool copy, const Idx id=0)
constructs a ScheduleMultiDim by copying/referencing table
bool isAbstract() const final
returns whether the ScheduleMultiDim contains a real table or not
aGrUM's Tensor is a multi-dimensional array with tensor operators.
Definition tensor.h:85

So, to summarize the key idea underlying Schedule* classes: these classes encapsulate operations to perform and multidim tables that should be passed as argument to these operations. But nothing is actually computed until the execute() methods of the scheduled operators are executed.

Definition at line 118 of file scheduleMultiDim.h.

Constructor & Destructor Documentation

◆ ScheduleMultiDim() [1/5]

template<typename TABLE>
gum::ScheduleMultiDim< TABLE >::ScheduleMultiDim ( const TABLE & table,
const bool copy,
const Idx id = 0 )
explicit

constructs a ScheduleMultiDim by copying/referencing table

Parameters
tablethe multidimensional table that we wish to be contained into the ScheduleMultiDim
copyindicates whether the ScheduleMultiDim should use internally a copy of table or rather if it should just use a reference on an already created table.
idif specified and different from 0, this will be the id of the constructed ScheduleMultiDim, else an Id is automatically provided to the ScheduleMultiDim.

Referenced by ScheduleMultiDim(), ScheduleMultiDim(), clone(), clone(), hasSameContent(), hasSameVariables(), operator!=(), operator=(), operator=(), and operator==().

Here is the caller graph for this function:

◆ ScheduleMultiDim() [2/5]

template<typename TABLE>
gum::ScheduleMultiDim< TABLE >::ScheduleMultiDim ( TABLE && table,
const Idx id = 0 )
explicit

constructs a ScheduleMultiDim by moving a table inside it

Parameters
tablethe multidimensional table that we wish to be contained into the ScheduleMultiDim
idif specified and different from 0, this will be the id of the constructed ScheduleMultiDim, else an Id is automatically provided to the ScheduleMultiDim.

◆ ScheduleMultiDim() [3/5]

template<typename TABLE>
gum::ScheduleMultiDim< TABLE >::ScheduleMultiDim ( const Sequence< const DiscreteVariable * > & vars,
const Idx id = 0 )
explicit

construct a ScheduleMultiDim for a multidimensional table yet to be built

The ScheduleMultiDim created is abstract, i.e., it does not contain a proper multidimensional table yet. However, the variables of the latter need be known to optimize inference processes

Parameters
idif specified and different from 0, this will be the id of the constructed ScheduleMultiDim, else an Id is automatically provided to the ScheduleMultiDim.
Warning
the sequence of variables is copied into the MultiDim.

◆ ScheduleMultiDim() [4/5]

template<typename TABLE>
gum::ScheduleMultiDim< TABLE >::ScheduleMultiDim ( const ScheduleMultiDim< TABLE > & from)

copy constructor

References ScheduleMultiDim().

Here is the call graph for this function:

◆ ScheduleMultiDim() [5/5]

template<typename TABLE>
gum::ScheduleMultiDim< TABLE >::ScheduleMultiDim ( ScheduleMultiDim< TABLE > && from)

move constructor

References ScheduleMultiDim().

Here is the call graph for this function:

◆ ~ScheduleMultiDim()

template<typename TABLE>
virtual gum::ScheduleMultiDim< TABLE >::~ScheduleMultiDim ( )
virtual

destructor

Member Function Documentation

◆ _newId_()

Idx gum::IScheduleMultiDim::_newId_ ( )
staticprivateinherited

returns a new distinct ID for each abstract scheduleMultiDim

◆ _removeTable_()

template<typename TABLE>
void gum::ScheduleMultiDim< TABLE >::_removeTable_ ( )
private

remove the table if it is contained in the ScheduleMultiDim

◆ clone() [1/2]

template<typename TABLE>
virtual ScheduleMultiDim< TABLE > * gum::ScheduleMultiDim< TABLE >::clone ( ) const
virtual

virtual copy constructor

Implements gum::IScheduleMultiDim.

References ScheduleMultiDim().

Here is the call graph for this function:

◆ clone() [2/2]

template<typename TABLE>
virtual ScheduleMultiDim< TABLE > * gum::ScheduleMultiDim< TABLE >::clone ( bool force_copy) const
virtual

virtual copy constructor enabling to force a copy of the content

Implements gum::IScheduleMultiDim.

References ScheduleMultiDim().

Here is the call graph for this function:

◆ containsMultiDim()

template<typename TABLE>
bool gum::ScheduleMultiDim< TABLE >::containsMultiDim ( ) const
finalvirtual

indicates whether the ScheduleMultiDim contains a table and possesses it

Non-abstract ScheduleMultiDim can either contain a multidimensional table or they can reference an external table. This method indicates whether we are in the first case (true) or the second case (false) described above.

Implements gum::IScheduleMultiDim.

References containsMultiDim().

Referenced by containsMultiDim().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ domainSize()

template<typename TABLE>
Size gum::ScheduleMultiDim< TABLE >::domainSize ( ) const
finalvirtual

returns the domain size the table would have after its creation

Implements gum::IScheduleMultiDim.

References domainSize().

Referenced by domainSize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ exportMultiDim()

template<typename TABLE>
TABLE * gum::ScheduleMultiDim< TABLE >::exportMultiDim ( )

returns the contained multidimensional table, if any, and make the ScheduleMultiDim abstract

Exceptions
NullElementis raised if the ScheduleMultiDim is abstract
OperationNotAllowedis raised if the ScheduleMultiDim does not own (contain) its table

References exportMultiDim().

Referenced by exportMultiDim().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hasSameContent() [1/2]

template<typename TABLE>
virtual bool gum::ScheduleMultiDim< TABLE >::hasSameContent ( const IScheduleMultiDim< TABLE > & ) const
virtual

checks whether two ScheduleMultiDim contain precisely the same table

By "contain precisely the same table", we mean that the actual tables pointed to by the ScheduleMultiDim are the same (i.e., either they are both not yet allocated but have the same sequences of variables or they have the same content)

Implements gum::IScheduleMultiDim.

References gum::IScheduleMultiDim::IScheduleMultiDim().

Here is the call graph for this function:

◆ hasSameContent() [2/2]

template<typename TABLE>
virtual bool gum::ScheduleMultiDim< TABLE >::hasSameContent ( const ScheduleMultiDim< TABLE > & ) const
virtual

checks whether two ScheduleMultiDim contain precisely the same table

By "contain precisely the same table", we mean that the actual tables pointed to by the ScheduleMultiDim are the same (i.e., either they are both not yet allocated but have the same sequences of variables or they have the same content)

References ScheduleMultiDim().

Here is the call graph for this function:

◆ hasSameVariables() [1/2]

template<typename TABLE>
virtual bool gum::ScheduleMultiDim< TABLE >::hasSameVariables ( const IScheduleMultiDim< TABLE > & m) const
virtual

checks whether two ScheduleMultiDim have the same variables and types

Method hasSameVariables tests whether two ScheduleMultiDim contain the same sequences of variables. It is weaker than operator== in the sense that we do not check for the ScheduleMultiDim's ID nor for the content of the table stored into the IScheduleMultiDim, if any.

Parameters
mthe ScheduleMultiDim with which we test similarity.

Implements gum::IScheduleMultiDim.

References gum::IScheduleMultiDim::IScheduleMultiDim().

Here is the call graph for this function:

◆ hasSameVariables() [2/2]

template<typename TABLE>
virtual bool gum::ScheduleMultiDim< TABLE >::hasSameVariables ( const ScheduleMultiDim< TABLE > & m) const
virtual

checks whether two ScheduleMultiDim have the same variables

Method hasSameVariables tests whether two ScheduleMultiDim contain the same sequences of variables. It is weaker than operator== in the sense that we do not check for the ScheduleMultiDim's ID nor for the content of the table stored into the IScheduleMultiDim, if any.

Parameters
mthe ScheduleMultiDim with which we test similarity.

References ScheduleMultiDim().

Here is the call graph for this function:

◆ id()

Idx gum::IScheduleMultiDim::id ( ) const
inherited

returns the id of the ScheduleMultiDim

Each ScheduleMultiDim has an Id that enables to find it easily. This is especially useful when copying schedule trees.

Warning
Note that different schedule trees may contain ScheduleMultiDim with the same ids. However, within a given tree, no two ScheduleMultiDim should have the same id.

◆ isAbstract()

template<typename TABLE>
bool gum::ScheduleMultiDim< TABLE >::isAbstract ( ) const
finalvirtual

returns whether the ScheduleMultiDim contains a real table or not

Returns
true if the ScheduleMultiDim is abstract, i.e., it is does not actually contains an allocated multidimensional table.

Implements gum::IScheduleMultiDim.

◆ makeAbstract()

template<typename TABLE>
void gum::ScheduleMultiDim< TABLE >::makeAbstract ( )
finalvirtual

if the ScheduleMultiDim is not abstract, make it abstract again

When a ScheduleMultiDim contains a multidimensional table, making it abstract is equivalent to freeing the table from memory and saying that the ScheduleMultiDim contains a null pointer. If the ScheduleMultiDim contains only a reference on an external table, then this table is kept untouched, but the ScheduleMultiDim now points toward a null pointer. Of course, if the ScheduleMultiDim was already abstract, then nothing is executed.

Warning
Making a ScheduleMultiDim abstract has an impact neither on the set of variables of the ScheduleMultiDim nor on its domain size. This just affects the table contained into the ScheduleMultiDim.

Implements gum::IScheduleMultiDim.

References makeAbstract().

Referenced by makeAbstract().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ multiDim()

template<typename TABLE>
const TABLE & gum::ScheduleMultiDim< TABLE >::multiDim ( ) const

returns the table actually contained in the ScheduleMultiDim

Exceptions
NullElementexception is thrown if the table does not exist yet (because it has not been computed yet)

References multiDim().

Referenced by multiDim().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator!=() [1/2]

template<typename TABLE>
virtual bool gum::ScheduleMultiDim< TABLE >::operator!= ( const IScheduleMultiDim< TABLE > & ) const
virtual

checks whether two ScheduleMultiDim have different IDs or types

Two ScheduleMultiDim having different IDs should mean that they either contain the different sequences of variables and/or different tables.

Reimplemented from gum::IScheduleMultiDim.

References gum::IScheduleMultiDim::IScheduleMultiDim().

Here is the call graph for this function:

◆ operator!=() [2/2]

template<typename TABLE>
virtual bool gum::ScheduleMultiDim< TABLE >::operator!= ( const ScheduleMultiDim< TABLE > & ) const
virtual

checks whether two ScheduleMultiDim have different IDs

Two ScheduleMultiDim having different IDs should mean that they either contain the different sequences of variables and/or different tables.

References ScheduleMultiDim().

Here is the call graph for this function:

◆ operator=() [1/2]

template<typename TABLE>
ScheduleMultiDim< TABLE > & gum::ScheduleMultiDim< TABLE >::operator= ( const ScheduleMultiDim< TABLE > & from)

copy operator

References ScheduleMultiDim().

Here is the call graph for this function:

◆ operator=() [2/2]

template<typename TABLE>
ScheduleMultiDim< TABLE > & gum::ScheduleMultiDim< TABLE >::operator= ( ScheduleMultiDim< TABLE > && from)

move operator

References ScheduleMultiDim().

Here is the call graph for this function:

◆ operator==() [1/2]

template<typename TABLE>
virtual bool gum::ScheduleMultiDim< TABLE >::operator== ( const IScheduleMultiDim< TABLE > & ) const
virtual

checks whether two ScheduleMultiDim have the same ID and type

Two ScheduleMultiDim having the same ID should imply that they also contain the same sequences of variables and the same tables.

Reimplemented from gum::IScheduleMultiDim.

References gum::IScheduleMultiDim::IScheduleMultiDim().

Here is the call graph for this function:

◆ operator==() [2/2]

template<typename TABLE>
virtual bool gum::ScheduleMultiDim< TABLE >::operator== ( const ScheduleMultiDim< TABLE > & ) const
virtual

checks whether two ScheduleMultiDim have exactly the same ID

Two ScheduleMultiDim having the same ID should imply that they also contain the same sequences of variables and the same tables.

References ScheduleMultiDim().

Here is the call graph for this function:

◆ resetIdGenerator()

void gum::IScheduleMultiDim::resetIdGenerator ( )
staticinherited

reset the id generator to 0

This method is essentially useful for performing aGrUM's testunits (depending on the order in which they are executed, the results could be difficult to predict without ensuring that, at the beginning of a testunit, the id of the first ScheduleMultiDim is always 1).

◆ setMultiDim() [1/2]

template<typename TABLE>
void gum::ScheduleMultiDim< TABLE >::setMultiDim ( const TABLE & table,
const bool copy )

assigns a new table inside the wrapper

Parameters
tablethe multidimensional table that we wish to be contained into the ScheduleMultiDim
copyindicates whether the ScheduleMultiDim should use internally a copy of table or rather if it should just use a reference on table

References setMultiDim().

Referenced by setMultiDim(), and setMultiDim().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setMultiDim() [2/2]

template<typename TABLE>
void gum::ScheduleMultiDim< TABLE >::setMultiDim ( TABLE && pot)

sets by move a new table inside the wrapper

References setMultiDim().

Here is the call graph for this function:

◆ sizeOfContent()

template<typename TABLE>
double gum::ScheduleMultiDim< TABLE >::sizeOfContent ( ) const
finalvirtual

returns the sizeof of the elements stored into the ScheduleMultiDim

This method is useful for determining schedules' memory usage: this is actually equal to the number of elements times the sizeof of these elements. The goal of sizeOfContent is to return this sizeof

Implements gum::IScheduleMultiDim.

References sizeOfContent().

Referenced by sizeOfContent().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ toString()

template<typename TABLE>
std::string gum::ScheduleMultiDim< TABLE >::toString ( ) const
finalvirtual

displays the content of the ScheduleMultiDim

Implements gum::IScheduleMultiDim.

References toString().

Referenced by toString().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ variablesSequence()

template<typename TABLE>
const Sequence< const DiscreteVariable * > & gum::ScheduleMultiDim< TABLE >::variablesSequence ( ) const
finalvirtual

returns the set of variables involved in the ScheduleMultiDim

Implements gum::IScheduleMultiDim.

References variablesSequence().

Referenced by variablesSequence().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ _domain_size_

template<typename TABLE>
Size gum::ScheduleMultiDim< TABLE >::_domain_size_ {Size(1)}
private

the domain size of the table

Definition at line 323 of file scheduleMultiDim.h.

323{Size(1)};
std::size_t Size
In aGrUM, hashed values are unsigned long int.
Definition types.h:74

◆ _multidim_id_

std::atomic< Idx > gum::IScheduleMultiDim::_multidim_id_
staticprivateinherited

Definition at line 208 of file IScheduleMultiDim.h.

◆ _table_

template<typename TABLE>
TABLE* gum::ScheduleMultiDim< TABLE >::_table_ {nullptr}
private

the multidimensional table stored into the ScheduleMultiDim

Definition at line 314 of file scheduleMultiDim.h.

314{nullptr};

◆ _table_contained_

template<typename TABLE>
bool gum::ScheduleMultiDim< TABLE >::_table_contained_ {true}
private

indicates whether table is contained or referenced

Definition at line 317 of file scheduleMultiDim.h.

317{true};

◆ _var_sequence_

template<typename TABLE>
Sequence< const DiscreteVariable* > gum::ScheduleMultiDim< TABLE >::_var_sequence_
private

returns the sequence of variables of the table

Definition at line 320 of file scheduleMultiDim.h.

◆ id_

Idx gum::IScheduleMultiDim::id_
protectedinherited

the unique Id of the ScheduleMultiDim

Definition at line 200 of file IScheduleMultiDim.h.


The documentation for this class was generated from the following file: