libDAI
Public Member Functions | Private Attributes | List of all members
dai::Permute Class Reference

Tool for calculating permutations of linear indices of multi-dimensional arrays. More...

#include <dai/index.h>

Public Member Functions

 Permute ()
 Default constructor. More...
 
 Permute (const std::vector< size_t > &rs, const std::vector< size_t > &sigma)
 Construct from vector of index ranges and permutation. More...
 
 Permute (const std::vector< Var > &vars, bool reverse=false)
 Construct from vector of variables. More...
 
size_t convertLinearIndex (size_t li) const
 Calculates a permuted linear index. More...
 
const std::vector< size_t > & sigma () const
 Returns constant reference to the permutation. More...
 
std::vector< size_t > & sigma ()
 Returns reference to the permutation. More...
 
const std::vector< size_t > & ranges ()
 Returns constant reference to the dimensionality vector. More...
 
size_t operator[] (size_t i) const
 Returns the result of applying the permutation on i. More...
 
Permute inverse () const
 Returns the inverse permutation. More...
 

Private Attributes

std::vector< size_t > _ranges
 Stores the number of possible values of all indices. More...
 
std::vector< size_t > _sigma
 Stores the permutation. More...
 

Detailed Description

Tool for calculating permutations of linear indices of multi-dimensional arrays.

Note
This is mainly useful for converting indices into multi-dimensional arrays corresponding to joint states of variables to and from the canonical ordering used in libDAI.
Examples:
example_permute.cpp.

Constructor & Destructor Documentation

dai::Permute::Permute ( )
inline

Default constructor.

dai::Permute::Permute ( const std::vector< size_t > &  rs,
const std::vector< size_t > &  sigma 
)
inline

Construct from vector of index ranges and permutation.

dai::Permute::Permute ( const std::vector< Var > &  vars,
bool  reverse = false 
)
inline

Construct from vector of variables.

The implied permutation maps the index of each variable in vars according to the canonical ordering (i.e., sorted ascendingly according to their label) to the index it has in vars. If reverse == true, reverses the indexing in vars first.

Member Function Documentation

size_t dai::Permute::convertLinearIndex ( size_t  li) const
inline

Calculates a permuted linear index.

Converts the linear index li to a vector index, permutes its components, and converts it back to a linear index.

Examples:
example_permute.cpp.
const std::vector<size_t>& dai::Permute::sigma ( ) const
inline

Returns constant reference to the permutation.

Examples:
example_permute.cpp.
std::vector<size_t>& dai::Permute::sigma ( )
inline

Returns reference to the permutation.

const std::vector<size_t>& dai::Permute::ranges ( )
inline

Returns constant reference to the dimensionality vector.

size_t dai::Permute::operator[] ( size_t  i) const
inline

Returns the result of applying the permutation on i.

Permute dai::Permute::inverse ( ) const
inline

Returns the inverse permutation.

Member Data Documentation

std::vector<size_t> dai::Permute::_ranges
private

Stores the number of possible values of all indices.

std::vector<size_t> dai::Permute::_sigma
private

Stores the permutation.


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