Commit 07ab802f authored by sw440870's avatar sw440870

can now add a valarray

parent 5e271ed5
......@@ -5,6 +5,7 @@
#include <map>
#include <string>
#include <vector>
#include <valarray>
namespace loadl {
......@@ -20,6 +21,9 @@ public:
template<class T>
void add(const std::vector<T> &);
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
......@@ -73,4 +77,29 @@ void observable::add(const std::vector<T> &val) {
current_bin_filling_ = 0;
}
}
template<class T>
void observable::add(const std::valarray<T> &val) {
if(vector_length_ != val.size()) {
throw std::runtime_error{
fmt::format("observable::add: added vector has unexpected size ({}). Observable was "
"initialized with vector length ({})",
val.size(), vector_length_)};
}
for(size_t j = 0; j < vector_length_; ++j)
samples_[j + current_bin_ * vector_length_] += static_cast<double>(val[j]);
current_bin_filling_++;
if(current_bin_filling_ == bin_length_) { // need to start a new bin next time
if(bin_length_ > 1) {
for(size_t j = 0; j < vector_length_; ++j) {
samples_[current_bin_ * vector_length_ + j] /= bin_length_;
}
}
current_bin_++;
samples_.resize((current_bin_ + 1) * vector_length_);
current_bin_filling_ = 0;
}
}
}
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