Updated copyrights
[libdai.git] / include / dai / util.h
1 /* Copyright (C) 2006-2008 Joris Mooij [joris dot mooij at tuebingen dot mpg dot de]
2 Radboud University Nijmegen, The Netherlands /
3 Max Planck Institute for Biological Cybernetics, Germany
4
5 This file is part of libDAI.
6
7 libDAI is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 libDAI is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with libDAI; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22
23 #ifndef __defined_libdai_util_h
24 #define __defined_libdai_util_h
25
26
27 #include <vector>
28 #include <set>
29 #include <map>
30 #include <iostream>
31 #include <cstdio>
32 #include <boost/foreach.hpp>
33
34
35 #ifdef WINDOWS
36 #include <map>
37 #else
38 #include <tr1/unordered_map>
39 #endif
40
41
42 #define foreach BOOST_FOREACH
43
44
45 #ifdef WINDOWS
46 bool isnan( double x );
47 double atanh( double x );
48 double log1p( double x );
49 #endif
50
51
52 namespace dai {
53
54
55 #ifdef WINDOWS
56 template <typename T, typename U>
57 class hash_map : public std::map<T,U> {};
58 #else
59 template <typename T, typename U>
60 class hash_map : public std::tr1::unordered_map<T,U> {};
61 #endif
62
63
64 double toc();
65 void rnd_seed( size_t seed );
66 double rnd_uniform();
67 double rnd_stdnormal();
68 int rnd_int( int min, int max );
69
70
71 // Output a std::vector
72 template<class T>
73 std::ostream& operator << (std::ostream& os, const std::vector<T> & x) {
74 os << "(";
75 for( typename std::vector<T>::const_iterator it = x.begin(); it != x.end(); it++ )
76 os << (it != x.begin() ? ", " : "") << *it;
77 os << ")";
78 return os;
79 }
80
81
82 // Output a std::set
83 template<class T>
84 std::ostream& operator << (std::ostream& os, const std::set<T> & x) {
85 os << "{";
86 for( typename std::set<T>::const_iterator it = x.begin(); it != x.end(); it++ )
87 os << (it != x.begin() ? ", " : "") << *it;
88 os << "}";
89 return os;
90 }
91
92
93 /// Output a std::map
94 template<class T1, class T2>
95 std::ostream& operator << (std::ostream& os, const std::map<T1,T2> & x) {
96 os << "{";
97 for( typename std::map<T1,T2>::const_iterator it = x.begin(); it != x.end(); it++ )
98 os << (it != x.begin() ? ", " : "") << it->first << "->" << it->second;
99 os << "}";
100 return os;
101 }
102
103
104 /// Output a std::pair
105 template<class T1, class T2>
106 std::ostream& operator << (std::ostream& os, const std::pair<T1,T2> & x) {
107 os << "(" << x.first << ", " << x.second << ")";
108 return os;
109 }
110
111
112 } // end of namespace dai
113
114
115 #endif