ALPS Project
Header file vectortraits.h
This header contains vector type traits
and support for container free numerical algorithms.
Synopsis
namespace alps {
template <class CONTAINER>
struct VectorTraits {
typedef ... value_type;
typedef ... norm_type;
typedef ... iterator;
typedef ... const_iterator;
typedef ... size_type;
static const bool is_complex;
};
namespace vectorops {
template <class C>
inline typename VectorTraits<C>::size_type size(const C& c);
template <class C>
inline typename VectorTraits<C>::value_type* data(C& c);
template <class C>
inline const typename VectorTraits<C>::value_type* data(const C& c);
template <class C>
inline typename VectorTraits<C>::norm_type infinity_norm(const C & c);
template <class C>
inline typename VectorTraits<C>::norm_type one_norm(const C& c);
template <class C>
inline typename VectorTraits<C>::norm_type two_norm2(const C& c);
template <class C>
inline typename VectorTraits<C>::norm_type two_norm(const C& c);
template <class C>
inline typename VectorTraits<C>::norm_type normalize(C& c);
template <class C, class X>
inline void scale(C& c, X val);
template <class C>
inline void add(C& c1, const C& c2);
template <class C>
inline void subtract(C& c1, const C& c2);
template <class C, class X>
inline void add_scaled(C& c1, const C& c2, X val);
template <class C, class X>
inline void subtract_scaled(C& c1, const C& c2, X val);
template <class C>
inline void resize(C& c, std::size_t n);
template <class C>
inline void assign(C& c, typename VectorTraits<C>::value_type x);
template <class C>
inline void assign(C& c1, const C& c2);
template <class C>
inline void swap(C& c1, C& c2);
template <class C>
inline typename VectorTraits<C>::value_type scalar_product(const C& c1, const C& c2);
template <class C>
inline void deallocate(C& c);
// specializations for std::valarray
.
.
.
}
}
The VectorTraits traits class
The VectorTraits<C> traits class encodes useful type properties for
vector-like containers
Member | Default value | Description |
value_type | C::value_type | the value type |
norm_type | TypeTraits<value_type>::norm_t | a type to store the norm of the vector |
iterator | C::value_type | the iterator type |
const_iterator | C::value_type | the const iterator type |
size_type | C::value_type | the size type |
is_complex | TypeTraits<value_type>::is_complex | a flag indicating whether the vector is complex |
The standard template is valid for all standard containers. A specialized
version has been provided for std::valarray.
Numerical operations on vectors
Default behavior is implemented for all containers fulfilling the standard
container requirements. Specializations are provided in this header file
for std::valarray. The files blitz.h and mtl.h contain
specializations for containers from the Blitz++
and MTL libraries.
template <class C>
inline typename VectorTraits<C>::size_type size(const C& c);
returns the size of the vector.
template <class C>
inline typename VectorTraits<C>::value_type* data(C& c);
template <class C>
inline const typename VectorTraits<C>::value_type* data(const C& c);
returns a pointer to the begin of the storage for the vector. Note
that this might not be a sensible operations for all types of vectors.
template <class C>
inline typename VectorTraits<C>::norm_type infinity_norm(const C & c);
returns the infinity norm (maximum absolute element value) of the vector.
template <class C>
inline typename VectorTraits<C>::norm_type one_norm(const C& c);
returns the one-norm (suym of absolute values) of the vector.
template <class C>
inline typename VectorTraits<C>::norm_type two_norm2(const C& c);
returns the square of the 2-norm (sum of squares of absolute values)
of the vector.
template <class C>
inline typename VectorTraits<C>::norm_type two_norm(const C& c);
returns the 2-norm (square root of the sum of squares of absolute values)
of the vector.
template <class C, class X>
inline void scale(C& c, X val);
scales the vector by the scalar. Acts like c*=val.
template <class C>
inline typename VectorTraits<C>::norm_type normalize(C& c);
normalizes the vector (divides by the 2-norm) and returns the 2-norm.
template <class C>
inline void add(C& c1, const C& c2);
adds a vector. Acts like c1+=c2.
template <class C>
inline void subtract(C& c1, const C& c2);
subtracts a vector. Acts like c1-=c2.
template <class C, class X>
inline void add_scaled(C& c1, const C& c2, X val);
adds a scaled vector. Acts like c1+=val*c2
template <class C, class X>
inline void subtract_scaled(C& c1, const C& c2, X val);
subtracts a scaled vector. Acts like c1-=val*c2
template <class C>
inline void resize(C& c, std::size_t n);
resizes the vector.
template <class C>
inline void assign(C& c, typename VectorTraits<C>::value_type x);
assigns a value to all vector elements
template <class C>
inline void assign(C& c1, const C& c2);
makes the vector a copy of another. Acts like c1=c2.
template <class C>
inline void swap(C& c1, C& c2);
an optimized swap.
template <class C>
inline typename VectorTraits<C>::value_type scalar_product(const C& c1, const C& c2);
returns the scalar products of the vectors.
template <class C>
inline void deallocate(C& c);
deallocates the vector (releasing as much memory as possible).
copyright (c) 1994-2003 by Matthias Troyer