1 /* Copyright (C) 2006-2008 Joris Mooij [j dot mooij at science dot ru dot nl]
2 Radboud University Nijmegen, The Netherlands
4 This file is part of libDAI.
6 libDAI is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 libDAI is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with libDAI; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #ifndef __defined_libdai_util_h
23 #define __defined_libdai_util_h
31 #include <boost/foreach.hpp>
37 #include <tr1/unordered_map>
41 #define foreach BOOST_FOREACH
45 bool isnan( double x
);
46 double atanh( double x
);
47 double log1p( double x
);
55 template <typename T
, typename U
>
56 class hash_map
: public std::map
<T
,U
> {};
58 template <typename T
, typename U
>
59 class hash_map
: public std::tr1::unordered_map
<T
,U
> {};
64 void rnd_seed( size_t seed
);
66 double rnd_stdnormal();
67 int rnd_int( int min
, int max
);
70 // Output a std::vector
72 std::ostream
& operator << (std::ostream
& os
, const std::vector
<T
> & x
) {
74 for( typename
std::vector
<T
>::const_iterator it
= x
.begin(); it
!= x
.end(); it
++ )
75 os
<< (it
!= x
.begin() ? ", " : "") << *it
;
83 std::ostream
& operator << (std::ostream
& os
, const std::set
<T
> & x
) {
85 for( typename
std::set
<T
>::const_iterator it
= x
.begin(); it
!= x
.end(); it
++ )
86 os
<< (it
!= x
.begin() ? ", " : "") << *it
;
93 template<class T1
, class T2
>
94 std::ostream
& operator << (std::ostream
& os
, const std::map
<T1
,T2
> & x
) {
96 for( typename
std::map
<T1
,T2
>::const_iterator it
= x
.begin(); it
!= x
.end(); it
++ )
97 os
<< (it
!= x
.begin() ? ", " : "") << it
->first
<< "->" << it
->second
;
103 /// Output a std::pair
104 template<class T1
, class T2
>
105 std::ostream
& operator << (std::ostream
& os
, const std::pair
<T1
,T2
> & x
) {
106 os
<< "(" << x
.first
<< ", " << x
.second
<< ")";
111 } // end of namespace dai