9#include <kernel/lafem/meta_element.hpp> 
   36      template<
typename,
typename...>
 
   71      template <
typename DT2_ = DataType, 
typename IT2_ = IndexType>
 
   77      template <
typename DataType2_, 
typename IndexType2_>
 
   81      static_assert(std::is_same<DataType, typename RestClass::DataType>::value,
 
   82                    "sub-vectors have different data-types");
 
   83      static_assert(std::is_same<IndexType, typename RestClass::IndexType>::value,
 
   84                    "sub-vectors have different index-types");
 
  106        _first(std::forward<First_>(the_first)),
 
  113        _first(std::forward<First_>(the_first)),
 
  114        _rest(std::forward<Rest_>(the_rest)...)
 
  130          _first = std::forward<First_>(other._first);
 
  131          _rest = std::forward<RestClass>(other._rest);
 
  162        _first.clone(other._first, clone_mode);
 
  174        _first.clone(other._first);
 
  187        std::uint64_t isize = *(std::uint64_t*) data.data(); 
 
  188        std::vector<char>::iterator start = std::begin(data) + 
sizeof(std::uint64_t);
 
  189        std::vector<char>::iterator last_of_first = std::begin(data) + 
sizeof(std::uint64_t) + (
int) isize;
 
  190        std::vector<char> buffer_first(start, last_of_first);
 
  191        _first.restore_from_checkpoint_data(buffer_first);
 
  193        data.erase(std::begin(data), last_of_first);
 
  200        std::size_t old_size = data.size();
 
  201        data.insert(std::end(data), 
sizeof(std::uint64_t), 0); 
 
  202        std::uint64_t ireal_size = 
_first.set_checkpoint_data(data, config); 
 
  203        char* csize = 
reinterpret_cast<char*
>(&ireal_size);
 
  204        for(std::size_t i(0) ; i < 
sizeof(std::uint64_t) ; ++i)  
 
  206          data[old_size +i] = csize[i];
 
  218      const First_& first()
 const 
  223      TupleVector<Rest_...>& rest()
 
  228      const TupleVector<Rest_...>& 
rest()
 const 
  246        static_assert((0 <= i_) && (i_ < 
num_blocks), 
"invalid sub-vector index");
 
  254        static_assert((0 <= i_) && (i_ < 
num_blocks), 
"invalid sub-vector index");
 
  259      template <Perspective perspective_ = Perspective::native>
 
  262        return _first.template size<perspective_>() + 
_rest.template size<perspective_>();
 
  285        first().format(
value);
 
  286        rest().format(
value);
 
  298        first().format(rng, min, max);
 
  299        rest().format(rng, min, max);
 
  318        first().copy(x.first(), full);
 
  319        rest().copy(x.rest(), full);
 
  324        first().axpy(x.first(), alpha);
 
  325        rest().axpy(x.rest(), alpha);
 
  328      void component_product(
const TupleVector & x, 
const TupleVector & y)
 
  330        first().component_product(x.first(), y.first());
 
  331        rest().component_product(x.rest(), y.rest());
 
  336        first().component_invert(x.first(), alpha);
 
  337        rest().component_invert(x.rest(), alpha);
 
  340      void scale(
const TupleVector& x, 
DataType alpha)
 
  342        first().scale(x.first(), alpha);
 
  343        rest().scale(x.rest(), alpha);
 
  346      DataType dot(
const TupleVector& x)
 const 
  348        return first().dot(x.first()) + 
rest().dot(x.rest());
 
  356        return first().triple_dot(x.first(), y.first())
 
  357          + rest().triple_dot(x.rest(), y.rest());
 
  362        return first().norm2sqr() + rest().norm2sqr();
 
  416      template <
typename First2_, 
typename... Rest2_>
 
  424      void set_vec(
DataType * 
const pval_set)
 const 
  426        this->first().set_vec(pval_set);
 
  427        this->rest().set_vec(pval_set + this->first().
template size<Perspective::pod>());
 
  431      void set_vec_inv(
const DataType * 
const pval_set)
 
  433        this->first().set_vec_inv(pval_set);
 
  434        this->rest().set_vec_inv(pval_set + this->first().
template size<Perspective::pod>());
 
  445      template <
typename First2_, 
typename... Rest2_>
 
  448        this->first().convert(other.first());
 
  449        this->rest().convert(other.rest());
 
  466        std::ifstream file(filename.c_str(), std::ifstream::in | std::ifstream::binary);
 
  467        if (! file.is_open())
 
  468          XABORTM(
"Unable to open Vector file " + filename);
 
  486            file.read((
char *)&magic, (
long)(
sizeof(std::uint64_t)));
 
  488              XABORTM(
"Given file or file component is no TupleVector!");
 
  490            file.read((
char *)&count, (
long)(
sizeof(std::uint64_t)));
 
  498            XABORTM(
"Filemode not supported!");
 
  510        std::ofstream file(filename.c_str(), std::ofstream::out | std::ofstream::binary);
 
  511        if (! file.is_open())
 
  512          XABORTM(
"Unable to open Vector file " + filename);
 
  529            size_t gsize(2 * 
sizeof(std::uint64_t)); 
 
  530            std::vector<char> result(gsize);
 
  531            char * array(result.data());
 
  532            std::uint64_t * uiarray(
reinterpret_cast<std::uint64_t *
>(array));
 
  536            file.write(result.data(), 
long(result.size()));
 
  542            XABORTM(
"Filemode not supported!");
 
  548    template<
typename First_>
 
  549    class TupleVector<First_>
 
  552      template<
typename,
typename...>
 
  553      friend class TupleVector;
 
  572      typedef typename First_::DataType 
DataType;
 
  573      typedef typename First_::IndexType 
IndexType;
 
  575      template <
typename DT2_ = DataType, 
typename IT2_ = IndexType>
 
  576      using ContainerType = TupleVector<typename First_::template ContainerType<DT2_, IT2_> >;
 
  579      template <
typename DataType2_, 
typename IndexType2_>
 
  587        return First_::name();
 
  595      explicit TupleVector(First_&& the_first) :
 
  596        _first(std::forward<First_>(the_first))
 
  601      TupleVector(TupleVector&& other) :
 
  607      TupleVector& 
operator=(TupleVector&& other)
 
  617      TupleVector(
const TupleVector&) = 
delete;
 
  619      TupleVector& 
operator=(
const TupleVector&) = 
delete;
 
  630        return TupleVector(
_first.clone(mode));
 
  651      void clone(
const TupleVector& other)
 
  661      const First_& first()
 const 
  669        return _first.get_checkpoint_size(config);
 
  675        _first.restore_from_checkpoint_data(data);
 
  681        return _first.set_checkpoint_data(data, config);
 
  684      template <Perspective perspective_ = Perspective::native>
 
  687        return _first.template size<perspective_>();
 
  703      typename TupleElement<i_, First_>::Type& 
at()
 
  705        static_assert(i_ == 0, 
"invalid sub-vector index");
 
  710      typename TupleElement<i_, First_>::Type 
const& 
at()
 const 
  712        static_assert(i_ == 0, 
"invalid sub-vector index");
 
  723        first().format(rng, min, max);
 
  732      void copy(
const TupleVector& x, 
bool full = 
false)
 
  734        first().copy(x.first(), full);
 
  739        first().axpy(x.first(), alpha);
 
  742      void component_product(
const TupleVector & x, 
const TupleVector & y)
 
  744        first().component_product(x.first(), y.first());
 
  749        first().component_invert(x.first(), alpha);
 
  752      void scale(
const TupleVector& x, 
DataType alpha)
 
  754        first().scale(x.first(), alpha);
 
  757      DataType dot(
const TupleVector& x)
 const 
  759        return first().dot(x.first());
 
  764        return first().triple_dot(x.first(), y.first());
 
  767      DataType triple_dot_i(
const TupleVector& x, 
const TupleVector& y)
 const 
  769        return first().triple_dot_i(x.first(), y.first());
 
  774        return first().norm2sqr();
 
  779        return first().norm2();
 
  784        return first().max_abs_element();
 
  789        return first().min_abs_element();
 
  794        return first().max_element();
 
  799        return first().min_element();
 
  802      const typename First_::DataType operator()(
Index index)
 const 
  805        return first()(index);
 
  808      void operator()(
Index index, 
typename First_::DataType 
value)
 
  811        first()(index, 
value);
 
  814      void set_vec(
DataType * 
const pval_set)
 const 
  816        this->first().set_vec(pval_set);
 
  819      void set_vec_inv(
const DataType * 
const pval_set)
 
  821        this->first().set_vec_inv(pval_set);
 
  831      template <
typename First2_>
 
  832      void convert(
const TupleVector<First2_>& other)
 
  834        this->first().convert(
other.first());
 
  838      std::size_t 
bytes()
 const 
  854          read_from_binary(filename);
 
  857          XABORTM(
"Filemode not supported!");
 
  872          read_from_binary(file);
 
  875          XABORTM(
"Filemode not supported!");
 
  884      void read_from_binary(
const String& filename)
 
  886        std::ifstream file(filename.c_str(), std::ifstream::in | std::ifstream::binary);
 
  887        if (! file.is_open())
 
  888          XABORTM(
"Unable to open Vector file " + filename);
 
  889        read_from_binary(file);
 
  898      void read_from_binary(std::istream& file)
 
  901        file.read((
char *)&magic, (
long)(
sizeof(std::uint64_t)));
 
  903          XABORTM(
"Given file or file component is no TupleVector!");
 
  905        file.read((
char *)&count, (
long)(
sizeof(std::uint64_t)));
 
  907          XABORTM(
"PowerVector file read in component count mismatch: class has 1 - " + 
stringify(count) + 
" read in!");
 
  923          write_out_binary(filename);
 
  926          XABORTM(
"Filemode not supported!");
 
  941          write_out_binary(file);
 
  944          XABORTM(
"Filemode not supported!");
 
  953      void write_out_binary(
const String& filename)
 const 
  955        std::ofstream file(filename.c_str(), std::ofstream::out | std::ofstream::binary);
 
  956        if (! file.is_open())
 
  957          XABORTM(
"Unable to open Vector file " + filename);
 
  958        write_out_binary(file);
 
  969      void write_out_binary(std::ostream& file)
 const 
  971        size_t gsize(2 * 
sizeof(std::uint64_t)); 
 
  972        std::vector<char> result(gsize);
 
  973        char * array(result.data());
 
  974        std::uint64_t * uiarray(
reinterpret_cast<std::uint64_t *
>(array));
 
  978        file.write(result.data(), 
long(result.size()));
 
  986    template <
typename First_>
 
  987    inline void dump_tuple_vector(std::ostream & os, 
const TupleVector<First_>& x)
 
  992    template <
typename First_, 
typename... Rest_>
 
  993    inline void dump_tuple_vector(std::ostream & os, 
const TupleVector<First_, Rest_...>& x)
 
  995      os << x.first() << 
",";
 
  996      dump_tuple_vector<Rest_...>(os, x.rest());
 
  999    template <
typename First_, 
typename... Rest_>
 
 1000    inline std::ostream& operator<< (std::ostream & os, 
const TupleVector<First_, Rest_...>& x)
 
 1003      dump_tuple_vector(os, x);
 
#define ASSERT(expr)
Debug-Assertion macro definition.
#define XABORTM(msg)
Abortion macro definition with custom message.
Config class for serialize parameter.
Variadic TupleVector class template.
void clone(const TupleVector &other)
Turns this vector into a clone of other.
TupleElement< i_, First_, Rest_... >::Type & at()
Returns a sub-vector block.
std::size_t bytes() const
Returns the total amount of bytes allocated.
DataType min_abs_element() const
Retrieve the absolute minimum value of this vector.
TupleElement< i_, First_, Rest_... >::Type const & at() const
Returns a sub-vector block.
DataType max_rel_diff(const TupleVector< First2_, Rest2_... > &x) const
Retrieve the maximum relative difference of this vector and another one y.max_rel_diff(x) returns .
int blocks() const
Returns the number of blocks in this tuple-vector.
void read_from(FileMode mode, const String &filename)
Read in vector from file.
void clone(const TupleVector &other, CloneMode clone_mode)
Turns this vector into a clone of other.
void write_out(FileMode mode, const String &filename) const
Write out vector to file.
TupleVector()
default CTOR
std::uint64_t set_checkpoint_data(std::vector< char > &data, SerialConfig &config)
First_ _first
the first sub-vector
TupleVector(TupleVector &&other)
move ctor
void restore_from_checkpoint_data(std::vector< char > &data)
Extract object from checkpoint.
void copy(const TupleVector &x, bool full=false)
Performs .
void format(DataType value=DataType(0))
Reset all elements of the container to a given value or zero if missing.
void write_out(FileMode mode, std::ostream &file) const
Write out vector to file.
First_::DataType DataType
sub-vector data-type
RestClass _rest
all remaining sub-vectors
void convert(const TupleVector< First2_, Rest2_... > &other)
Conversion method.
TupleVector(const TupleVector &)=delete
deleted copy-ctor
TupleVector< typename First_::template ContainerType< DT2_, IT2_ >, typename Rest_::template ContainerType< DT2_, IT2_ >... > ContainerType
Our 'base' class type.
DataType max_element() const
Retrieve the maximum value of this vector.
TupleVector(First_ &&the_first, Rest_ &&... the_rest)
Sub-Vector emplacement constructor.
void _write_out_binary(std::ostream &file) const
write binary data of _first and _rest to file.
void _read_from_binary(std::istream &file)
read binary data of _first and _rest to file.
DataType min_element() const
Retrieve the minimum value of this vector.
DataType triple_dot(const TupleVector &x, const TupleVector &y) const
Calculate .
TupleVector(First_ &&the_first, RestClass &&the_rest)
rest-class emplacement ctor; for internal use only
void clear()
Free all allocated arrays.
TupleVector clone(LAFEM::CloneMode mode=LAFEM::CloneMode::Weak) const
Creates and returns a copy of this vector.
std::uint64_t get_checkpoint_size(SerialConfig &config)
Calculate size.
void format(Random &rng, DataType min, DataType max)
Reset all elements of the container to random values.
First_::IndexType IndexType
sub-vector index-type
TupleVector & operator=(const TupleVector &)=delete
deleted copy-assign operator
static String sub_name_list()
Returns a list of all sub-vector type names.
DataType max_abs_element() const
Retrieve the absolute maximum value of this vector.
void read_from(FileMode mode, std::istream &file)
Read in vector from stream.
static String name()
Returns a descriptive string for this container.
Index size() const
Returns the total size of this tuple-vector.
TupleVector & operator=(TupleVector &&other)
move-assign operator
ContainerType< DataType2_, IndexType2_ > ContainerTypeByDI
this typedef lets you create a vector container with different Data and Index types
static constexpr int num_blocks
number of vector blocks
Pseudo-Random Number Generator.
String class implementation.
@ other
generic/other permutation strategy
T_ sqrt(T_ x)
Returns the square-root of a value.
T_ min(T_ a, T_ b)
Returns the minimum of two values.
T_ max(T_ a, T_ b)
Returns the maximum of two values.
@ rest
restriction (multigrid)
String stringify(const T_ &item)
Converts an item into a String.
@ value
specifies whether the space should supply basis function values
std::uint64_t Index
Index data type.
Tuple container element helper class template.