DiSMEC++
dismec::stats::StatImplBase< Derived > Class Template Reference

Helper class for implementing Statistics classes. More...

#include <stats_base.h>

Inheritance diagram for dismec::stats::StatImplBase< Derived >:
dismec::stats::Statistics

Public Member Functions

void merge (const Statistics &other) override
 Merges this statistics of another one of the same type and settings. More...
 
void record_vec (const DenseRealVector &vector) override
 
- Public Member Functions inherited from dismec::stats::Statistics
virtual ~Statistics ()=default
 
void record (int integer)
 
void record (long integer)
 
void record (real_t real)
 
void record (const DenseRealVector &vector)
 
virtual std::unique_ptr< Statisticsclone () const =0
 
virtual void setup (const StatisticsCollection &source)
 This function has to be called before the Statistics is used to collect data for the first time. More...
 
virtual nlohmann::json to_json () const =0
 Converts the statistics current value into a json object. More...
 

Detailed Description

template<class Derived>
class dismec::stats::StatImplBase< Derived >

Helper class for implementing Statistics classes.

Template Parameters
DerivedCRTP parameter. Needs to be a final class.

This class provides two default implementations to ease writing derived classes. The merge() function checks that the other given statistics is of the same type, and then calls an overload of merge() that expects a Derived reference. The record() function for vector parameters is implemented so that it called the scalar record() for each vector component. Note that we cannot efficiently implement this default behaviour in Statistics, because then each record call would be virtual. Since we do know the Derived type here, no virtual call is necessary.

For this to work, we require that Derived be a final class.

Definition at line 127 of file stats_base.h.

Member Function Documentation

◆ merge()

template<class Derived >
void dismec::stats::StatImplBase< Derived >::merge ( const Statistics other)
inlineoverridevirtual

Merges this statistics of another one of the same type and settings.

This operation is used to perform the reduction of the thread-local statistics into a single global statistics. For this to be possible, the merged statistics need to have not only the same type, but also the same settings (e.g. number of bins in a histogram). This is true for the thread local copies, which are clones of one another.

Parameters
otherThe statistics object to be merged into this. Must be of same type and have the same settings, e.g. a clone of this.

Implements dismec::stats::Statistics.

Definition at line 129 of file stats_base.h.

◆ record_vec()

template<class Derived >
void dismec::stats::StatImplBase< Derived >::record_vec ( const DenseRealVector vector)
inlineoverridevirtual

Reimplemented from dismec::stats::Statistics.

Definition at line 134 of file stats_base.h.

References dismec::stats::Statistics::record().


The documentation for this class was generated from the following file: