9 #include <alps/config.hpp> 25 #include <boost/utility.hpp> 28 #include <type_traits> 31 namespace accumulators {
39 template<
typename R,
typename C>
static char helper(R(C::*)()
const);
40 template<
typename R,
typename C>
static char helper(R(C::*)(std::size_t)
const);
41 template<
typename C>
static char check(std::integral_constant<std::size_t,
sizeof(helper(&
C::error))>*);
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 error_impl(A
const & acc) {
60 template<
typename A>
typename std::enable_if<
61 !has_feature<A, error_tag>::value
63 >::type error_impl(A
const & ) {
64 throw std::runtime_error(std::string(
typeid(A).name()) +
" has no error-method" +
ALPS_STACKTRACE);
71 template<
typename T,
typename B>
struct Accumulator<T, error_tag, B> :
public B {
83 : B(args), m_sum2(T())
86 error_type
const error()
const;
89 void operator()(T
const & val);
91 template<
typename S>
void print(S & os,
bool terse=
false)
const {
99 static std::size_t
rank() {
return B::rank() + 1; }
108 template <
typename A>
111 using alps::numeric::operator+=;
115 m_sum2 += rhs.m_sum2;
119 void collective_merge(
123 void collective_merge(
133 template<
typename T,
typename B>
class Result<T, error_tag, B> :
public B {
138 typedef typename detail::make_scalar_result_type<impl::Result,T,error_tag,B>::type
scalar_result_type;
142 , m_error(error_type())
145 template<
typename A>
Result(A
const & acc)
147 , m_error(detail::error_impl(acc))
154 template<
typename S>
void print(S & os,
bool terse=
false)
const {
162 static std::size_t
rank() {
return B::rank() + 1; }
167 template<
typename U>
void operator*=(U
const & arg) { augmul(arg); }
168 template<
typename U>
void operator/=(U
const & arg) { augdiv(arg); }
192 template<
typename U>
void augaddsub (U
const & arg,
typename std::enable_if<!std::is_scalar<U>::value,
int>::type = 0) {
193 using alps::numeric::operator+;
194 m_error = m_error + arg.error();
196 template<
typename U>
void augaddsub (U
const & ,
typename std::enable_if<std::is_scalar<U>::value,
int>::type = 0) {}
198 template<
typename U>
void augmul (U
const & arg,
typename std::enable_if<!std::is_scalar<U>::value,
int>::type = 0) {
199 using alps::numeric::operator*;
200 using alps::numeric::operator+;
203 m_error = m_error * arg.mean() + this->
mean() * arg.error();
206 template<
typename U>
void augmul (U
const & arg,
typename std::enable_if<std::is_scalar<U>::value,
int>::type = 0) {
207 using alps::numeric::operator*;
208 m_error = m_error *
static_cast<error_scalar_type
>(arg);
212 template<
typename U>
void augdiv (U
const & arg,
typename std::enable_if<!std::is_scalar<U>::value,
int>::type = 0) {
213 using alps::numeric::operator*;
214 using alps::numeric::operator/;
215 using alps::numeric::operator+;
216 m_error = m_error / arg.mean() + this->
mean() * arg.error() / (arg.mean() * arg.mean());
219 template<
typename U>
void augdiv (U
const & arg,
typename std::enable_if<std::is_scalar<U>::value,
int>::type = 0) {
220 using alps::numeric::operator/;
221 m_error = m_error /
static_cast<error_scalar_type
>(arg);
226 template<
typename T,
typename B>
class BaseWrapper<T, error_tag, B> :
public B {
228 virtual bool has_error()
const = 0;
232 template<
typename T,
typename B>
class DerivedWrapper<T, error_tag, B> :
public B {
void merge(const A &rhs)
Merge the mean & error of given accumulator of type A into this accumulator.
void operator*=(U const &arg)
void print(S &os, bool terse=false) const
result_wrapper cbrt(result_wrapper const &arg)
void check_size(T &, U const &)
alps::numeric::scalar< error_type >::type error_scalar_type
error_type const error() const
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)
result_wrapper sqrt(result_wrapper const &arg)
result_wrapper cb(result_wrapper const &arg)
result_wrapper sq(result_wrapper const &arg)
void operator+=(U const &arg)
error_type< B >::type error() const
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.
Metafunction returning "mathematical scalar" type for type T.
boost::array< T, N > & operator+=(boost::array< T, N > &lhs, boost::array< T, N > const &rhs)
detail::make_scalar_result_type< impl::Result, T, error_tag, B >::type scalar_result_type
mean_type< T >::type mean(T const &arg)
void operator/=(U const &arg)
Accumulator(ArgumentPack const &args, typename std::enable_if<!is_accumulator< ArgumentPack >::value, int >::type=0)
DerivedWrapper(T const &arg)
result_wrapper log(result_wrapper const &arg)
void print(S &os, bool terse=false) const
void reset(accumulator_wrapper &arg)
boost::array< T, N > & operator/=(boost::array< T, N > &lhs, boost::array< T, N > const &rhs)
boost::array< T, N > exp(boost::array< T, N > arg)
alps::numeric::scalar< error_type >::type error_scalar_type
result_wrapper tanh(result_wrapper const &arg)
error_type< T >::type error(T const &arg)
boost::array< T, N > & operator*=(boost::array< T, N > &lhs, boost::array< T, N > const &rhs)
void operator-=(U const &arg)
Accumulator(Accumulator const &arg)
static std::size_t rank()
alps::accumulators::error_type< B >::type error_type
result_wrapper acos(result_wrapper const &arg)
std::ostream & print(std::ostream &s, const dict_value &dv, bool terse)
std::integral_constant< bool, sizeof(char)==sizeof(check< T >0))> type
result_wrapper sin(result_wrapper const &arg)
result_wrapper asin(result_wrapper const &arg)
result_wrapper tan(result_wrapper const &arg)
alps::accumulators::error_type< B >::type error_type
result_wrapper sinh(result_wrapper const &arg)
static std::size_t rank()
std::vector< T > & merge(std::vector< T > &left, const std::vector< T > &right)
Vector merge.
Result< T, error_tag, typename B::result_type > result_type
result_wrapper cosh(result_wrapper const &arg)
boost::array< T, N > & operator-=(boost::array< T, N > &lhs, boost::array< T, N > const &rhs)
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 >())