libDAI
Classes | Namespaces | Macros | Typedefs | Enumerations | Functions
util.h File Reference

Defines general utility functions and adds an abstraction layer for platform-dependent functionality. More...

#include <string>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <boost/foreach.hpp>
#include <boost/functional/hash.hpp>
#include <boost/lexical_cast.hpp>
#include <algorithm>
#include <cerrno>
#include <gmpxx.h>
#include <dai/exceptions.h>
#include <tr1/unordered_map>

Go to the source code of this file.

Classes

class  dai::hash_map< T, U, H >
 hash_map is an alias for std::tr1::unordered_map. More...
 

Namespaces

 dai
 Namespace for libDAI.
 

Macros

#define bforeach   BOOST_FOREACH
 An alias to the BOOST_FOREACH macro from the boost::bforeach library. More...
 
#define DAI_PV(x)   do {std::cerr << #x "= " << (x) << std::endl;} while(0)
 "Print variable". Prints the text of an expression, followed by its value (only if DAI_DEBUG is defined) More...
 
#define DAI_DMSG(str)   do {std::cerr << str << std::endl;} while(0)
 "Debugging message": Prints a message (only if DAI_DEBUG is defined) More...
 
#define DAI_IFVERB(n, stmt)   if(props.verbose>=n) { std::cerr << stmt; }
 Macro to write message stmt to std::cerr if props.verbose >= n. More...
 

Typedefs

typedef double dai::Real
 Real number (alias for double, which could be changed to long double if necessary) More...
 
typedef mpz_class dai::BigInt
 Arbitrary precision integer number. More...
 

Enumerations

enum  dai::ProbNormType { NORMPROB, NORMLINF }
 Enumerates different ways of normalizing a probability measure. More...
 
enum  dai::ProbDistType {
  DISTL1, DISTLINF, DISTTV, DISTKL,
  DISTHEL
}
 Enumerates different distance measures between probability measures. More...
 

Functions

size_t dai::BigInt_size_t (const BigInt &N)
 Safe down-cast of big integer to size_t. More...
 
bool dai::isnan (Real x)
 Returns true if argument is NAN (Not A Number) More...
 
Real dai::log (Real x)
 Returns logarithm of x. More...
 
Real dai::log0 (Real x)
 Returns logarithm of x, or 0 if x == 0. More...
 
Real dai::exp (Real x)
 Returns exponent of x. More...
 
Real dai::pow (Real x, Real y)
 Returns x to the power y. More...
 
double dai::toc ()
 Returns wall clock time in seconds. More...
 
template<class T >
dai::abs (const T &t)
 Returns absolute value of t. More...
 
void dai::rnd_seed (size_t seed)
 Sets the random seed. More...
 
Real dai::rnd_uniform ()
 Returns a real number, distributed uniformly on [0,1) More...
 
Real dai::rnd_stdnormal ()
 Returns a real number from a standard-normal distribution. More...
 
int dai::rnd_int (int min, int max)
 Returns a random integer in interval [min, max]. More...
 
int dai::rnd (int n)
 Returns a random integer in the half-open interval [0, n) More...
 
template<class T >
std::string dai::toString (const T &x)
 Converts a variable of type T to a std::string by using a boost::lexical_cast. More...
 
template<class T >
dai::fromString (const std::string &x)
 Converts a variable of type std::string to T by using a boost::lexical_cast. More...
 
template<class T >
std::ostream & dai::operator<< (std::ostream &os, const std::vector< T > &x)
 Writes a std::vector<> to a std::ostream. More...
 
template<class T >
std::ostream & dai::operator<< (std::ostream &os, const std::set< T > &x)
 Writes a std::set<> to a std::ostream. More...
 
template<class T1 , class T2 >
std::ostream & dai::operator<< (std::ostream &os, const std::map< T1, T2 > &x)
 Writes a std::map<> to a std::ostream. More...
 
template<class T1 , class T2 >
std::ostream & dai::operator<< (std::ostream &os, const std::pair< T1, T2 > &x)
 Writes a std::pair<> to a std::ostream. More...
 
template<class T >
std::vector< T > dai::concat (const std::vector< T > &u, const std::vector< T > &v)
 Concatenates two vectors. More...
 
std::vector< std::string > dai::tokenizeString (const std::string &s, bool singleDelim, const std::string &delim="\t\n")
 Split a string into tokens delimited by one of the characters in delim. More...
 

Detailed Description

Defines general utility functions and adds an abstraction layer for platform-dependent functionality.

Macro Definition Documentation

#define bforeach   BOOST_FOREACH

An alias to the BOOST_FOREACH macro from the boost::bforeach library.

Examples:
example_bipgraph.cpp.
#define DAI_PV (   x)    do {std::cerr << #x "= " << (x) << std::endl;} while(0)

"Print variable". Prints the text of an expression, followed by its value (only if DAI_DEBUG is defined)

Useful debugging macro to see what your code is doing. Example:

1 DAI_PV(3+4)

Output:

1 3+4= 7
#define DAI_DMSG (   str)    do {std::cerr << str << std::endl;} while(0)

"Debugging message": Prints a message (only if DAI_DEBUG is defined)

#define DAI_IFVERB (   n,
  stmt 
)    if(props.verbose>=n) { std::cerr << stmt; }

Macro to write message stmt to std::cerr if props.verbose >= n.