16 namespace alps {
namespace alea {
20 : batch_(size, num_batches)
40 , num_batches_(num_batches)
41 , base_size_(base_size)
43 , cursor_(num_batches)
44 , offset_(num_batches)
46 if (num_batches % 2 != 0) {
47 throw std::runtime_error(
"Number of batches must be even to allow " 51 offset_[i] = i * base_size_;
57 , num_batches_(other.num_batches_)
58 , base_size_(other.base_size_)
59 , store_(other.store_ ? new
batch_data<T>(*other.store_) : nullptr)
60 , cursor_(other.cursor_)
61 , offset_(other.offset_)
68 num_batches_ = other.num_batches_;
69 base_size_ = other.base_size_;
70 store_.reset(other.store_ ?
new batch_data<T>(*other.store_) :
nullptr);
71 cursor_ = other.cursor_;
72 offset_ = other.offset_;
80 for (
size_t i = 0; i != num_batches_; ++i)
81 offset_[i] = i * base_size_;
102 base_size_ = batch_size;
107 template <
typename T>
118 template <
typename T>
130 store_->count()(cursor_.
current()) += count;
133 template <
typename T>
145 store_->batch() += other_store.
batch();
146 store_->count() += other_store.
count();
150 template <
typename T>
157 store_->count()(cursor_.
current()) = 0;
161 store_->batch().col(cursor_.
current());
162 store_->batch().col(cursor_.
current()).fill(0);
171 template <
typename T>
179 template <
typename T>
187 template <
typename T>
191 result.store_.reset();
192 result.store_.swap(store_);
199 template <
typename T>
201 : store_(other.store_ ? new
batch_data<T>(*other.store_) : nullptr)
204 template <
typename T>
207 store_.reset(other.store_ ?
new batch_data<T>(*other.store_) :
nullptr);
211 template <
typename T>
223 template <
typename T>
226 return store_->batch().rowwise().sum() /
count();
229 template <
typename T>
230 template <
typename Str>
234 for (
size_t i = 0; i != store_->num_batches(); ++i) {
238 return aux_acc.finalize().var();
241 template <
typename T>
242 template <
typename Str>
246 for (
size_t i = 0; i != store_->num_batches(); ++i)
248 return aux_acc.finalize().cov();
251 template <
typename T>
255 for (
size_t i = 0; i != store_->num_batches(); ++i) {
259 return aux_acc.finalize().stderror();
262 template <
typename T>
268 r.
reduce(
view<T>(store_->batch().data(), store_->batch().size()));
271 if (pre_commit && post_commit) {
293 template <
typename T>
313 template <
typename T>
320 size_t new_size, new_nbatches;
324 self.store_.reset(
new batch_data<T>(new_size, new_nbatches));
338 template void serialize(
serializer &,
const std::string &key,
const batch_result<double> &);
344 template <
typename T>
345 std::ostream &operator<<(std::ostream &str, const batch_result<T> &
self)
353 str <<
self.mean() <<
" +- " <<
self.stderror();
356 str <<
"\n<Xi> = " <<
self.store().batch()
357 <<
"\nNi = " <<
self.store().count();
362 template std::ostream &operator<<(std::ostream &, const batch_result<double> &);
363 template std::ostream &operator<<(std::ostream &, const batch_result<std::complex<double>> &);
eigen< typename bind< Strategy, T >::cov_type >::matrix cov() const
void reduce(const reducer &r)
friend void serialize(serializer &, const std::string &, const batch_result &)
void set_batch_size(size_t batch_size)
friend void deserialize(deserializer &, const std::string &, batch_result &)
void set_num_batches(size_t batch_size)
void check_valid(const Acc &acc)
void finalize_to(batch_result< T > &result)
eigen< T >::matrix & batch()
std::enable_if<!is_sequence< T >::value, std::size_t >::type size(T const &)
batch_result< T > finalize()
void reset(bool merge_mode=false)
batch_result & operator=(const batch_result &other)
eigen< size_t >::row & count()
size_t merge_into() const
void add(const computed< T > &source, size_t count, var_acc *cascade)
virtual void commit() const =0
T & get_format(std::ios_base &stream, T initial_value=T())
batch_acc(size_t size=1, size_t num_batches=256, size_t base_size=1)
column< typename bind< Strategy, T >::var_type > var() const
batch_data(size_t size, size_t num_batches=256)
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > matrix
virtual void read(const std::string &key, ndview< double >)=0
size_t num_batches() const
batch_result< T > result() const
virtual void add_to(view< T > out) const =0
void set_size(size_t size)
column< typename bind< circular_var, T >::var_type > stderror() const
bool operator==(const autocorr_result< T > &r1, const autocorr_result< T > &r2)
size_t num_batches() const
size_t num_batches() const
virtual reducer_setup get_setup() const =0
batch_acc & operator<<(const computed< T > &src)
virtual void enter(const std::string &group)=0
T r(T x, T y=T(), T z=T())
eigen_adapter< typename Derived::Scalar, Derived > make_adapter(const Eigen::DenseBase< Derived > &in)
size_t current_batch_size() const
virtual void reduce(view< double > data) const =0
void add(const computed< T > &source, size_t count)
const batch_data< T > & store() const
virtual void enter(const std::string &group)=0
batch_acc & operator=(const batch_acc &other)
void add(const computed< T > &source, size_t count)