9 #include <alps/config.hpp> 19 #include <boost/variant/variant.hpp> 20 #include <boost/variant/apply_visitor.hpp> 23 #include <type_traits> 27 namespace accumulators {
32 template<
typename T>
struct value_wrapper {
40 impl::BaseWrapper<T, binning_analysis_tag,
41 impl::BaseWrapper<T, error_tag,
42 impl::BaseWrapper<T, mean_tag,
43 impl::BaseWrapper<T, count_tag,
44 detail::value_wrapper<T>
49 typedef typename detail::value_wrapper<T>::value_type
value_type;
53 virtual void operator()(value_type
const & value) = 0;
59 virtual void print(std::ostream & os,
bool terse)
const = 0;
60 virtual void reset() = 0;
74 template<
typename A> A
const &
extract()
const {
82 template <
typename X>
struct wrap_value_type:
83 public std::conditional<
84 alps::is_scalar<X>::value,
86 base_wrapper<typename alps::numeric::scalar<X>::type> const & > {};
99 virtual void operator+=(wrapped_scalar_value_type) = 0;
100 virtual void operator-=(wrapped_scalar_value_type) = 0;
101 virtual void operator*=(wrapped_scalar_value_type) = 0;
102 virtual void operator/=(wrapped_scalar_value_type) = 0;
111 virtual void negate() = 0;
112 virtual void inverse() = 0;
114 virtual void sin() = 0;
115 virtual void cos() = 0;
116 virtual void tan() = 0;
117 virtual void sinh() = 0;
118 virtual void cosh() = 0;
119 virtual void tanh() = 0;
120 virtual void asin() = 0;
121 virtual void acos() = 0;
122 virtual void atan() = 0;
123 virtual void abs() = 0;
124 virtual void sqrt() = 0;
125 virtual void log() = 0;
126 virtual void sq() = 0;
127 virtual void cb() = 0;
128 virtual void cbrt() = 0;
132 template<
typename A>
class foundation_wrapper :
public base_wrapper<typename value_type<A>::type> {
134 foundation_wrapper(A
const & arg): m_data(arg) {}
144 impl::DerivedWrapper<A, binning_analysis_tag,
145 impl::DerivedWrapper<A, error_tag,
146 impl::DerivedWrapper<A, mean_tag,
147 impl::DerivedWrapper<A, count_tag,
148 detail::foundation_wrapper<A>
158 impl::DerivedWrapper<A, max_num_binning_tag,
159 impl::DerivedWrapper<A, binning_analysis_tag,
160 impl::DerivedWrapper<A, error_tag,
161 impl::DerivedWrapper<A, mean_tag,
162 impl::DerivedWrapper<A, count_tag,
163 detail::foundation_wrapper<A>
171 impl::DerivedWrapper<A, max_num_binning_tag,
172 impl::DerivedWrapper<A, binning_analysis_tag,
173 impl::DerivedWrapper<A, error_tag,
174 impl::DerivedWrapper<A, mean_tag,
175 impl::DerivedWrapper<A, count_tag,
176 detail::foundation_wrapper<A>
194 ar[
""] = this->m_data;
197 ar[
""] >> this->m_data;
200 void print(std::ostream & os,
bool terse)
const {
201 this->m_data.print(os, terse);
205 this->m_data.reset();
215 void collective_merge(
219 this->m_data.collective_merge(comm, root);
222 void collective_merge(
226 this->m_data.collective_merge(comm, root);
243 throw std::runtime_error(std::string(
"A result(") +
typeid(A).name() +
") cannot be converted to a result" +
ALPS_STACKTRACE);
247 #define OPERATOR_PROXY(AUGOPNAME, AUGOP, AUGOPFN) \ 248 void AUGOPNAME(base_wrapper<typename value_type<A>::type> const & arg) { \ 249 this->m_data AUGOP arg.template extract<A>(); \ 252 void do_##AUGOPFN(void*) { \ 253 throw std::logic_error("This virtual method plug should never be called"); \ 255 template <typename W> \ 256 void do_##AUGOPFN(W& arg) { \ 257 this->m_data AUGOP arg.template extract<typename A::scalar_result_type>(); \ 259 void AUGOPNAME(wrapped_scalar_value_type arg) { \ 263 void AUGOPNAME(long double arg) { \ 264 this->m_data AUGOP arg; \ 270 #undef OPERATOR_PROXY 273 this->m_data.negate();
276 this->m_data.inverse();
279 #define FUNCTION_PROXY(FUN) \ 281 this->m_data. FUN (); \ 300 #undef FUNCTION_PROXY 319 return result_impl<A>();
323 throw std::runtime_error(
"The Operator += is not implemented for accumulators, only for results" +
ALPS_STACKTRACE);
326 throw std::runtime_error(
"The Operator -= is not implemented for accumulators, only for results" +
ALPS_STACKTRACE);
329 throw std::runtime_error(
"The Operator *= is not implemented for accumulators, only for results" +
ALPS_STACKTRACE);
332 throw std::runtime_error(
"The Operator /= is not implemented for accumulators, only for results" +
ALPS_STACKTRACE);
336 throw std::runtime_error(
"The operator += is not implemented for accumulators, only for results" +
ALPS_STACKTRACE);
339 throw std::runtime_error(
"The operator -= is not implemented for accumulators, only for results" +
ALPS_STACKTRACE);
342 throw std::runtime_error(
"The operator *= is not implemented for accumulators, only for results" +
ALPS_STACKTRACE);
345 throw std::runtime_error(
"The operator /= is not implemented for accumulators, only for results" +
ALPS_STACKTRACE);
349 throw std::runtime_error(
"The Operator += is not implemented for accumulators, only for results" +
ALPS_STACKTRACE);
352 throw std::runtime_error(
"The Operator -= is not implemented for accumulators, only for results" +
ALPS_STACKTRACE);
355 throw std::runtime_error(
"The Operator *= is not implemented for accumulators, only for results" +
ALPS_STACKTRACE);
358 throw std::runtime_error(
"The Operator /= is not implemented for accumulators, only for results" +
ALPS_STACKTRACE);
362 throw std::runtime_error(
"The function negate is not implemented for accumulators, only for results" +
ALPS_STACKTRACE);
365 throw std::runtime_error(
"The function inverse is not implemented for accumulators, only for results" +
ALPS_STACKTRACE);
368 #define FUNCTION_PROXY(FUN) \ 370 throw std::runtime_error("The Function " #FUN " is not implemented for accumulators, only for results" + ALPS_STACKTRACE); \ 389 #undef FUNCTION_PROXY 397 throw std::runtime_error(std::string(
"The type ") +
typeid(A).name() +
" has no result_type" +
ALPS_STACKTRACE);
void operator-=(wrapped_scalar_value_type)
result_wrapper cbrt(result_wrapper const &arg)
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 >())
derived_accumulator_wrapper()
derived_result_wrapper(A const &arg)
result_wrapper cos(result_wrapper const &arg)
derived_accumulator_wrapper(A const &arg)
void operator/=(long double)
result_wrapper sqrt(result_wrapper const &arg)
result_wrapper cb(result_wrapper const &arg)
void merge(const base_wrapper< value_type > &rhs)
Merge the given accumulator into this accumulator.
result_wrapper sq(result_wrapper const &arg)
void print(std::ostream &os, bool terse) const
Encapsulation of an MPI communicator and some communicator-related operations.
void operator*=(base_wrapper< typename value_type< A >::type > const &)
void operator+=(base_wrapper< typename value_type< A >::type > const &)
boost::array< T, N > & operator+=(boost::array< T, N > &lhs, boost::array< T, N > const &rhs)
void operator-=(long double)
wrap_value_type< T >::type wrapped_scalar_value_type
Either wrapped scalar<T>::type or unwrapped void*, depending on T.
#define OPERATOR_PROXY(AUGOPNAME, AUGOP, AUGOPFN)
result_wrapper log(result_wrapper const &arg)
base_wrapper< typename value_type< A >::type > * result() const
void operator-=(base_wrapper< typename value_type< A >::type > const &)
result_wrapper operator/(long double arg1, result_wrapper const &arg2)
void reset(accumulator_wrapper &arg)
boost::array< T, N > & operator/=(boost::array< T, N > &lhs, boost::array< T, N > const &rhs)
result_wrapper tanh(result_wrapper const &arg)
void operator+=(wrapped_scalar_value_type)
boost::array< T, N > & operator*=(boost::array< T, N > &lhs, boost::array< T, N > const &rhs)
result_wrapper acos(result_wrapper const &arg)
void load(hdf5::archive &ar)
std::ostream & print(std::ostream &s, const dict_value &dv, bool terse)
void operator*=(wrapped_scalar_value_type)
derived_wrapper(A const &arg)
#define FUNCTION_PROXY(FUN)
detail::value_wrapper< T >::value_type value_type
void operator/=(wrapped_scalar_value_type)
base_wrapper< typename value_type< A >::type > * clone() const
result_wrapper sin(result_wrapper const &arg)
result_wrapper asin(result_wrapper const &arg)
traits< Acc >::result_type result(const Acc &acc)
void operator*=(long double)
result_wrapper tan(result_wrapper const &arg)
result_wrapper abs(result_wrapper const &arg)
base_wrapper< typename value_type< A >::type > * clone() const
void operator()(value_type const &value)
void operator/=(base_wrapper< typename value_type< A >::type > const &)
result_wrapper sinh(result_wrapper const &arg)
void operator+=(long double)
A const & extract() const
std::vector< T > & merge(std::vector< T > &left, const std::vector< T > &right)
Vector merge.
result_wrapper cosh(result_wrapper const &arg)
void save(hdf5::archive &ar) const
base_wrapper< typename value_type< A >::type > * result() const
boost::array< T, N > & operator-=(boost::array< T, N > &lhs, boost::array< T, N > const &rhs)
result_wrapper atan(result_wrapper const &arg)
A const & extract() const
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 >())