mirror of
https://github.com/ETLCPP/etl.git
synced 2026-04-30 19:09:10 +08:00
Optimisation of floating point specialisations of etl::cumulative_moving_average.
This commit is contained in:
parent
9fbbb5cc19
commit
f3959810cb
@ -202,9 +202,8 @@ namespace etl
|
||||
/// \param initial_value The initial value for the average.
|
||||
//*************************************************************************
|
||||
cumulative_moving_average(const T initial_value)
|
||||
: samples(T(SAMPLE_SIZE_)),
|
||||
samples_plus_1(T(SAMPLE_SIZE_ + 1U)),
|
||||
average(initial_value)
|
||||
: reciprocal_samples_plus_1(T(1.0) / T(SAMPLE_SIZE_ + 1U))
|
||||
, average(initial_value)
|
||||
{
|
||||
}
|
||||
|
||||
@ -223,9 +222,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
void add(const T new_value)
|
||||
{
|
||||
average *= samples;
|
||||
average += new_value;
|
||||
average /= samples_plus_1;
|
||||
average += (new_value - average) * reciprocal_samples_plus_1;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -239,9 +236,8 @@ namespace etl
|
||||
|
||||
private:
|
||||
|
||||
const T samples; ///< The sample size to average over.
|
||||
const T samples_plus_1; ///< One greater than the sample size.
|
||||
T average; ///< The current cumulative average.
|
||||
const T reciprocal_samples_plus_1; ///< Reciprocal of one greater than the sample size.
|
||||
T average; ///< The current cumulative average.
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
@ -260,9 +256,8 @@ namespace etl
|
||||
/// \param initial_value The initial value for the average.
|
||||
//*************************************************************************
|
||||
cumulative_moving_average(const T initial_value, const size_t sample_size)
|
||||
: samples(T(sample_size)),
|
||||
samples_plus_1(T(sample_size + 1U)),
|
||||
average(initial_value)
|
||||
: reciprocal_samples_plus_1(T(1.0) / T(sample_size + 1U))
|
||||
, average(initial_value)
|
||||
{
|
||||
}
|
||||
|
||||
@ -281,8 +276,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
void set_sample_size(const size_t sample_size)
|
||||
{
|
||||
samples = T(sample_size);
|
||||
samples_plus_1 = samples + T(1);
|
||||
reciprocal_samples_plus_1 = T(1.0) / (T(sample_size) + T(1));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -291,9 +285,7 @@ namespace etl
|
||||
//*************************************************************************
|
||||
void add(const T new_value)
|
||||
{
|
||||
average *= samples;
|
||||
average += new_value;
|
||||
average /= samples_plus_1;
|
||||
average += (new_value - average) * reciprocal_samples_plus_1;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -307,9 +299,8 @@ namespace etl
|
||||
|
||||
private:
|
||||
|
||||
T samples; ///< The sample size to average over.
|
||||
T samples_plus_1; ///< One greater than the sample size.
|
||||
T average; ///< The current cumulative average.
|
||||
T reciprocal_samples_plus_1; ///< Reciprocal of one greater than the sample size.
|
||||
T average; ///< The current cumulative average.
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -39,7 +39,7 @@ SOFTWARE.
|
||||
|
||||
#define ETL_VERSION_MAJOR 14
|
||||
#define ETL_VERSION_MINOR 28
|
||||
#define ETL_VERSION_PATCH 0
|
||||
#define ETL_VERSION_PATCH 1
|
||||
|
||||
#define ETL_VERSION ETL_STRINGIFY(ETL_VERSION_MAJOR) ETL_STRINGIFY(ETL_VERSION_MINOR) ETL_STRINGIFY(ETL_VERSION_PATCH)
|
||||
#define ETL_VERSION_W ETL_WIDE_STRING(ETL_CONCAT(ETL_CONCAT(ETL_VERSION_MAJOR, ETL_VERSION_MINOR), ETL_VERSION_PATCH))
|
||||
|
||||
@ -1,3 +1,7 @@
|
||||
===============================================================================
|
||||
14.28.1
|
||||
Optimisation of floating point specialisations of etl::cumulative_moving_average.
|
||||
|
||||
===============================================================================
|
||||
14.28.0
|
||||
Added runtime sample size specialisations to etl::cumulative_moving_average.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user