9 #include <alps/config.hpp> 24 #include <boost/utility.hpp> 27 #include <type_traits> 30 namespace accumulators {
36 :
public std::conditional<std::is_integral<typename value_type<T>::type>::value, double, typename value_type<T>::type>
40 template<
typename R,
typename C>
static char helper(R(C::*)()
const);
41 template<
typename C>
static char check(std::integral_constant<std::size_t,
sizeof(helper(&
C::mean))>*);
42 template<
typename C>
static double check(...);
43 typedef std::integral_constant<bool, sizeof(char) == sizeof(check<T>(0))>
type;
44 constexpr
static bool value = type::value;
53 template<
typename A>
typename std::enable_if<
56 >::type mean_impl(A
const & acc) {
60 template<
typename A>
typename std::enable_if<
61 !has_feature<A, mean_tag>::value
63 >::type mean_impl(A
const & acc) {
64 throw std::runtime_error(std::string(
typeid(A).name()) +
" has no mean-method" +
ALPS_STACKTRACE);
71 template<
typename T,
typename B>
struct Accumulator<T, mean_tag, B> :
public B {
84 mean_type
const mean()
const;
87 void operator()(T
const & val);
89 template<
typename S>
void print(S & os,
bool terse=
false)
const {
97 static std::size_t
rank() {
return B::rank() + 1; }
106 template <
typename A>
109 using alps::numeric::operator+=;
117 void collective_merge(
121 void collective_merge(
128 T
const & sum()
const;
134 template<
typename T,
typename B>
class Result<T, mean_tag, B> :
public B {
138 typedef typename detail::make_scalar_result_type<impl::Result,T,mean_tag,B>::type
scalar_result_type;
142 , m_mean(mean_type())
145 template<
typename A>
Result(A
const & acc)
147 , m_mean(detail::mean_impl(acc))
154 template<
typename S>
void print(S & os,
bool terse=
false)
const {
162 static std::size_t
rank() {
return B::rank() + 1; }
165 template<
typename U>
void operator+=(U
const & arg) { augadd(arg); }
166 template<
typename U>
void operator-=(U
const & arg) { augsub(arg); }
167 template<
typename U>
void operator*=(U
const & arg) { augmul(arg); }
168 template<
typename U>
void operator/=(U
const & arg) { augdiv(arg); }
172 #define NUMERIC_FUNCTION_DECLARATION(FUNCTION_NAME) \ 173 void FUNCTION_NAME (); 191 #undef NUMERIC_FUNCTION_DECLARATION 197 #define NUMERIC_FUNCTION_OPERATOR(OP_NAME, OPEQ_NAME, OP, OP_TOKEN) \ 198 template<typename U> void aug ## OP_TOKEN (U const & arg, typename std::enable_if<!std::is_scalar<U>::value, int>::type = 0) { \ 199 using alps::numeric:: OP_NAME ; \ 200 m_mean = m_mean OP arg.mean(); \ 201 B:: OPEQ_NAME (arg); \ 203 template<typename U> void aug ## OP_TOKEN (U const & arg, \ 204 typename std::enable_if<std::is_scalar<U>::value, int>::type = 0) { \ 205 using alps::numeric:: OP_NAME ; \ 206 m_mean = m_mean OP static_cast<typename alps::numeric::scalar<mean_type>::type>(arg); \ 207 B:: OPEQ_NAME (arg); \ 215 #undef NUMERIC_FUNCTION_OPERATOR 218 template<
typename T,
typename B>
class BaseWrapper<T, mean_tag, B> :
public B {
220 virtual bool has_mean()
const = 0;
224 template<
typename T,
typename B>
class DerivedWrapper<T, mean_tag, B> :
public B {
static std::size_t rank()
void merge(const A &rhs)
Merge the sum (mean) of given accumulator of type A into this sum (mean)
alps::accumulators::mean_type< B >::type mean_type
DerivedWrapper(T const &arg)
result_wrapper cbrt(result_wrapper const &arg)
void check_size(T &, U const &)
void operator-=(U const &arg)
#define NUMERIC_FUNCTION_OPERATOR(OP_NAME, OPEQ_NAME, OP, OP_TOKEN)
void load(archive &ar, std::string const &path, T &value, std::vector< std::size_t > chunk=std::vector< std::size_t >(), std::vector< std::size_t >=std::vector< std::size_t >())
result_wrapper cos(result_wrapper const &arg)
mean_type< B >::type mean() const
mean_type const mean() const
result_wrapper sqrt(result_wrapper const &arg)
Accumulator(ArgumentPack const &args, typename std::enable_if<!is_accumulator< ArgumentPack >::value, int >::type=0)
result_wrapper cb(result_wrapper const &arg)
result_wrapper sq(result_wrapper const &arg)
std::integral_constant< bool, sizeof(char)==sizeof(check< T >0))> type
static std::size_t rank()
detail::short_print_proxy< T const > short_print(T const &v, std::size_t p=6)
Encapsulation of an MPI communicator and some communicator-related operations.
mean_type< T >::type mean(T const &arg)
result_wrapper log(result_wrapper const &arg)
void operator*=(U const &arg)
void reset(accumulator_wrapper &arg)
void print(S &os, bool terse=false) const
void operator+=(U const &arg)
result_wrapper tanh(result_wrapper const &arg)
result_wrapper acos(result_wrapper const &arg)
alps::accumulators::mean_type< B >::type mean_type
std::ostream & print(std::ostream &s, const dict_value &dv, bool terse)
void print(S &os, bool terse=false) const
Accumulator(Accumulator const &arg)
detail::make_scalar_result_type< impl::Result, T, mean_tag, B >::type scalar_result_type
result_wrapper sin(result_wrapper const &arg)
result_wrapper asin(result_wrapper const &arg)
result_wrapper tan(result_wrapper const &arg)
result_wrapper abs(result_wrapper const &arg)
result_wrapper sinh(result_wrapper const &arg)
#define NUMERIC_FUNCTION_DECLARATION(FUNCTION_NAME)
Result< T, mean_tag, typename B::result_type > result_type
std::vector< T > & merge(std::vector< T > &left, const std::vector< T > &right)
Vector merge.
result_wrapper cosh(result_wrapper const &arg)
void operator/=(U const &arg)
result_wrapper atan(result_wrapper const &arg)
void save(archive &ar, std::string const &path, T const &value, std::vector< std::size_t >=std::vector< std::size_t >(), std::vector< std::size_t > chunk=std::vector< std::size_t >(), std::vector< std::size_t >=std::vector< std::size_t >())