VectorT_dummy_data.hpp 841 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
#pragma once

#include <valarray>
#include <complex>

template<typename T>
T make_dummy_component() {
    return T();
}

template<> std::valarray<double> make_dummy_component();

template<typename Vec>
Vec make_dummy_vector() {
    return Vec(make_dummy_component<typename Vec::value_type>());
}

template<typename Scalar>
double observe_dummy_component(const Scalar& _s) {
    return _s;
}

template<typename T>
double observe_dummy_component(const std::valarray<T>& _s) {
    return _s.sum();
}

template<typename T>
double observe_dummy_component(const std::complex<T>& _s) {
    return _s.real() + _s.imag();
}

template<typename Vec>
double observe_dummy_vector(const Vec& _vec) {
    double result = 0.0;
    for (int dim = 0; dim < _vec.dim(); ++dim) {
        result += observe_dummy_component(_vec[dim]);
    }
    return result;
}