diff options
author | Thomas White <taw@physics.org> | 2019-08-23 17:05:06 +0200 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2019-08-26 14:04:06 +0200 |
commit | b6af09d78d49d552a05b81bd20a7854a180373f5 (patch) | |
tree | 32c69f31c8b86cc9c6c697d6781034ca36323b5e /libcrystfel/src/utils.h | |
parent | cc9f746053a86fc88915f8a45b916ab77487a581 (diff) |
Formatting/fussiness
Diffstat (limited to 'libcrystfel/src/utils.h')
-rw-r--r-- | libcrystfel/src/utils.h | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/libcrystfel/src/utils.h b/libcrystfel/src/utils.h index 44e6af6c..02aca4c7 100644 --- a/libcrystfel/src/utils.h +++ b/libcrystfel/src/utils.h @@ -269,21 +269,25 @@ static inline struct quaternion invalid_quaternion(void) return quat; } -/* function to compute mean and variance stably + +/** * \param x value * \param w weight * \param sumw pointer to accumulator variable for the sum of weights * \param mean pointer to online mean value * \param M2 pointer to online variance times sumw + * + * Function to compute mean and variance stably */ -static inline void mean_variance(const double x, - const double w, - double* sumw, double* mean, double* M2) +static inline void mean_variance(const double x, const double w, + double *sumw, double *mean, double *M2) { - if (w<DBL_MIN) return; const double temp = w + *sumw; const double delta = x - *mean; - const double R = delta * w / temp; + const double R = delta * w / temp; + + if ( w < DBL_MIN ) return; + *mean += R; *M2 += *sumw*delta*R; *sumw = temp; |