include/dai/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 <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

namespace  dai
 

Namespace for libDAI.


Defines

#define foreach   BOOST_FOREACH
 An alias to the BOOST_FOREACH macro from the boost::foreach library.
#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)
#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.

Typedefs

typedef double dai::Real
 Real number (alias for double, which could be changed to long double if necessary).

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

Real dai::log (Real x)
 Returns logarithm of x.
Real dai::log0 (Real x)
 Returns logarithm of x, or 0 if x == 0.
Real dai::exp (Real x)
 Returns exponent of x.
Real dai::pow (Real x, Real y)
 Returns to the power y.
double dai::toc ()
 Returns wall clock time in seconds.
template<class T >
dai::abs (const T &t)
 Returns absolute value of t.
void dai::rnd_seed (size_t seed)
 Sets the random seed.
Real dai::rnd_uniform ()
 Returns a real number, distributed uniformly on [0,1).
Real dai::rnd_stdnormal ()
 Returns a real number from a standard-normal distribution.
int dai::rnd_int (int min, int max)
 Returns a random integer in interval [min, max].
int dai::rnd (int n)
 Returns a random integer in the half-open interval [0, n).
template<class T >
std::string dai::toString (const T &x)
 Converts a variable of type T to a std::string by using a std::stringstream.
template<class T >
std::ostream & dai::operator<< (std::ostream &os, const std::vector< T > &x)
 Writes a std::vector<> to a std::ostream.
template<class T >
std::ostream & dai::operator<< (std::ostream &os, const std::set< T > &x)
 Writes a std::set<> to a std::ostream.
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.
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.
template<class T >
std::vector< T > dai::concat (const std::vector< T > &u, const std::vector< T > &v)
 Concatenates two vectors.
void dai::tokenizeString (const std::string &s, std::vector< std::string > &outTokens, const std::string &delim="\t\n")
 Split a string into tokens delimited by one of the characters in delim.

Detailed Description

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


Define Documentation

#define foreach   BOOST_FOREACH

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

#define DAI_PV (  )     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:

 DAI_PV(3+4) 

Output:

 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.

Generated on Sun May 9 16:51:32 2010 for libDAI by  doxygen 1.6.3