namespace alps {
template <class T>
struct obs_value_traits
{
typedef T value_type;
typedef double count_type;
typedef double time_type;
typedef typename TypeTraits<value_type>::average_t result_type;
typedef T element_type;
typedef double time_element_type;
typedef uint32_t size_type;
typedef uint32_t slice_iterator;
static const uint32_t magic_id = TypeTraits<value_type>::type_tag;
static const bool array_valued;
static element_type max();
static element_type min();
static element_type epsilon();
static time_element_type t_max();
static void check_for_max(const value_type& a,value_type& b);
static void check_for_min(const value_type& a,value_type& b);
static void fix_negative(value_type& x);
static value_type check_divide(const result_type& a,const result_type& b);
template <class X, class Y> static void resize_same_as(X& x,const Y& y);
template <class X, class Y> static void copy(X& x,const Y& y);
template <class X> static std::size_t size(const X& x);
template <class X> static T convert(const X& );
static slice_iterator slice_begin(const value_type&);
static slice_iterator slice_end(const value_type&);
static std::string slice_name(const value_type&,slice_iterator);
static value_type slice_value(const value_type& x, slice_iterator);
};
template <class T>
struct obs_value_traits<std::complex<T> >
{
...
};
template <class T>
struct obs_value_traits<std::valarray<T> >
{
...
};
template<typename T, std::size_t NumDims, typename Allocator>
struct obs_value_traits<alps::multi_array<T,NumDims,Allocator> >
{
...
};
template <class DST,class SRC> DST obs_value_cast(const SRC& s)
{
return obs_value_traits<DST>::convert(s);
}
} // end namespace alps
Type | Explanation |
value_type | The type for which the obs_value_traits are specialized |
count_type | a floating point type appropriate to store the number of measurements |
time_type | a type appropriate to store autocorrelation times for the observables. This is typically a floating point type for scalar types, and an array of floating point types for array valued types. |
result_type | a type appropriate to store averages. Typically value_type except for integral types, where it must be a floating point type |
element_type | for array-valued types, the type of a single elements (usually typename value_type::value_type). For scalar types, the same as value_type |
size_type | for array-valued types, an integral type large enough to store the size or extent of the array (typically typename value_type::size_type). For scalar types, an arbitrary integral type. |
slice_iterator | an iterator to iterate through all elements in the value_type. Important for array-valued types. |
is a unique identifier for the value_type.static const uint32_t magic_id;
is true if the type is array-valued and can be sliced.static const bool array_valued;
return the largest positive number, the largest negative number, and the floating point epsilon for the element_type, which is the same as value_type for scalar types, but the value_type of the array for array types.static element_type max();
static element_type min();
static element_type epsilon();
returns the largest possible timestatic time_element_type t_max();
replace b by the maximum (minimum) of a and b. For complex numbers the absolute value is used. For array types it is performed element wise.static void check_for_max(const value_type& a,value_type& b);
static void check_for_min(const value_type& a,value_type& b);
replaces negative values (element wise) by zerostatic void fix_negative(value_type& a);
calculates the ration a/b, replacig it by 1 if it is 0/0.static value_type check_divide(const result_type& a,const result_type& b);
resizes an array-valued x to the same size as y. Should also be implemented for scalar types, where it is a no-op. The types X are either value_type, time_type, count_type or result_type.template <class X, class Y> static void resize_same_as(X& x,const Y& y);
Copies x to y, resizing the destination if needed. Note that this is needed since no such resizing is done for std::valarray when the assignment operator is used. Should also be implemented for scalar types. The types X are either value_type, time_type, count_type or result_type.template <class X, class Y> static void copy(X& x,const Y& y);
returns the size of the array x or 1 for scalar types X. The type X is either value_type, time_type, count_type or result_type.template <class X> static std::size_t size(const X& x);
converts the argument to type T, performing e.g. static_cast<T> if defined.template <class X> T convert(const X& );
returns an iterator to the first element in the array-valued observable.static slice_iterator slice_begin(const value_type&);
returns an iterator pointing past the last element in the array-valued observable.static slice_iterator slice_end(const value_type&);
returns a string, expressing the slice index in string form. E.g. for a std::valarray, the i-th slice is expressed by the string "[i]".static std::string slice_name(const value_type&,slice_iterator);
returns the value at the position pointed to by the slice_iterator.static value_type slice_value(const value_type& x, slice_iterator);
converts an object of type SRC to type DST, using the obs_value_traits class.template <class DST,class SRC> DST obs_value_cast(const SRC& s)
{
return obs_value_traits<DST>::convert(s);
}
copyright (c) 1994-2010 by Matthias Troyer
Distributed under the Boost Software License, Version 1.0. (See http://www.boost.org/LICENSE_1_0.txt)