13 #ifndef __defined_libdai_util_h
14 #define __defined_libdai_util_h
22 #include <boost/foreach.hpp>
23 #include <boost/functional/hash.hpp>
24 #include <boost/lexical_cast.hpp>
37 #include <boost/tr1/unordered_map.hpp>
39 #include <boost/tr1/unordered_map.hpp>
41 #include <boost/tr1/unordered_map.hpp>
43 #include <tr1/unordered_map>
48 #define bforeach BOOST_FOREACH
57 #define DAI_PV(x) do {std::cerr << #x "= " << (x) << std::endl;} while(0)
59 #define DAI_DMSG(str) do {std::cerr << str << std::endl;} while(0)
61 #define DAI_PV(x) do {} while(0)
62 #define DAI_DMSG(str) do {} while(0)
66 #define DAI_IFVERB(n, stmt) if(props.verbose>=n) { std::cerr << stmt; }
71 double atanh(
double x );
74 double log1p(
double x );
77 #define INFINITY (std::numeric_limits<Real>::infinity())
80 #define NAN (std::numeric_limits<Real>::quiet_NaN())
85 #pragma warning( disable : 4996 )
87 #if (_MSC_VER >= 1600)
88 #define __STDC_UTF_16__
139 template <
typename T,
typename U,
typename H = boost::hash<T> >
140 class hash_map :
public std::tr1::unordered_map<T,U,H> {};
149 inline T
abs(
const T &t ) {
150 return (t < 0) ? (-t) : t;
164 int rnd_int(
int min,
int max );
175 return boost::lexical_cast<std::string>(x);
182 return boost::lexical_cast<T>(x);
188 std::ostream& operator << (std::ostream& os, const std::vector<T> & x) {
190 for(
typename std::vector<T>::const_iterator it = x.begin(); it != x.end(); it++ )
191 os << (it != x.begin() ?
", " :
"") << *it;
198 std::ostream& operator << (std::ostream& os, const std::set<T> & x) {
200 for(
typename std::set<T>::const_iterator it = x.begin(); it != x.end(); it++ )
201 os << (it != x.begin() ?
", " :
"") << *it;
207 template<
class T1,
class T2>
208 std::ostream& operator << (std::ostream& os, const std::map<T1,T2> & x) {
210 for(
typename std::map<T1,T2>::const_iterator it = x.begin(); it != x.end(); it++ )
211 os << (it != x.begin() ?
", " :
"") << it->first <<
"->" << it->second;
217 template<
class T1,
class T2>
218 std::ostream& operator << (std::ostream& os, const std::pair<T1,T2> & x) {
219 os <<
"(" << x.first <<
", " << x.second <<
")";
225 std::vector<T>
concat(
const std::vector<T>& u,
const std::vector<T>& v ) {
227 w.reserve( u.size() + v.size() );
228 for(
size_t i = 0; i < u.size(); i++ )
230 for(
size_t i = 0; i < v.size(); i++ )
241 std::vector<std::string>
tokenizeString(
const std::string& s,
bool singleDelim,
const std::string& delim=
"\t\n" );
259 typedef enum { DISTL1, DISTLINF, DISTTV, DISTKL, DISTHEL }
ProbDistType;