Commit 2ff2366b authored by Lukas Weber's avatar Lukas Weber

make it actually work for valarray

parent c43f9386
......@@ -5,7 +5,6 @@
#include <map>
#include <string>
#include <vector>
#include <valarray>
namespace loadl {
......@@ -15,15 +14,12 @@ public:
const std::string &name() const;
template<class T>
auto add(T val) -> decltype(val + val, void());
template<class T, std::enable_if_t<std::is_arithmetic_v<std::remove_reference_t<T>>> * = nullptr>
void add(T val);
template<class T>
auto add(const T& val) -> decltype(val[0], void());
template<class T>
void add(const std::valarray<T> &);
void checkpoint_write(const iodump::group &dump_file) const;
// This will empty the cache of already completed bins
......@@ -46,8 +42,8 @@ private:
std::vector<double> samples_;
};
template<class T>
auto observable::add(T val) -> decltype(val + val, void()) {
template<class T, std::enable_if_t<std::is_arithmetic_v<std::remove_reference_t<T>>> * = nullptr>
void observable::add(T val) {
add(std::array<T,1>{val});
}
......
#include "silly_mc.h"
#include <valarray>
silly_mc::silly_mc(const loadl::parser &p) : loadl::mc(p) {
}
......@@ -11,6 +12,8 @@ void silly_mc::do_measurement() {
std::vector<double> silly = {1.*idx_, 1.*(3-idx_%5)*idx_};
measure.add("MagicNumber", silly);
measure.add("MagicNumber2", idx_*idx_);
std::valarray<double> silly2 = {1.*idx_, 1.*(3-idx_%5)*idx_};
measure.add("MagicNumberValarray", silly2);
}
void silly_mc::init() {
......@@ -19,6 +22,7 @@ void silly_mc::init() {
int binsize = param.get("binsize", 1);
measure.register_observable("MagicNumber", binsize,2);
measure.register_observable("MagicNumber2", binsize);
measure.register_observable("MagicNumberValarray", binsize,2);
}
void silly_mc::checkpoint_write(const loadl::iodump::group &d) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment