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
5 This file is part of libDAI.
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.
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.
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
23 #ifndef __defined_libdai_util_h
24 #define __defined_libdai_util_h
32 #include <boost/foreach.hpp>
38 #include <tr1/unordered_map>
42 #define foreach BOOST_FOREACH
46 bool isnan( double x
);
47 double atanh( double x
);
48 double log1p( double x
);
56 template <typename T
, typename U
>
57 class hash_map
: public std::map
<T
,U
> {};
59 template <typename T
, typename U
>
60 class hash_map
: public std::tr1::unordered_map
<T
,U
> {};
65 void rnd_seed( size_t seed
);
67 double rnd_stdnormal();
68 int rnd_int( int min
, int max
);
71 // Output a std::vector
73 std::ostream
& operator << (std::ostream
& os
, const std::vector
<T
> & x
) {
75 for( typename
std::vector
<T
>::const_iterator it
= x
.begin(); it
!= x
.end(); it
++ )
76 os
<< (it
!= x
.begin() ? ", " : "") << *it
;
84 std::ostream
& operator << (std::ostream
& os
, const std::set
<T
> & x
) {
86 for( typename
std::set
<T
>::const_iterator it
= x
.begin(); it
!= x
.end(); it
++ )
87 os
<< (it
!= x
.begin() ? ", " : "") << *it
;
94 template<class T1
, class T2
>
95 std::ostream
& operator << (std::ostream
& os
, const std::map
<T1
,T2
> & x
) {
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
;
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
<< ")";
112 } // end of namespace dai