From 65bc41090720cdc249c1b0b9b9b8a8f062b41268 Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Thu, 25 May 2023 22:22:25 -0400 Subject: mean and variance: More tests Add some more tests that test conventional and weighted mean simultaneously, and with a table of values that represents events that we'll be using this to look for so we can verify-by-eyeball that the output looks sane. Signed-off-by: Kent Overstreet --- fs/bcachefs/mean_and_variance.h | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'fs/bcachefs/mean_and_variance.h') diff --git a/fs/bcachefs/mean_and_variance.h b/fs/bcachefs/mean_and_variance.h index 880e9501c614..6dd4c050e78a 100644 --- a/fs/bcachefs/mean_and_variance.h +++ b/fs/bcachefs/mean_and_variance.h @@ -176,14 +176,12 @@ static inline s64 fast_divpow2(s64 n, u8 d) * * see linked pdf equation 12. */ -static inline struct mean_and_variance -mean_and_variance_update(struct mean_and_variance s, s64 v) -{ - return (struct mean_and_variance) { - .n = s.n + 1, - .sum = s.sum + v, - .sum_squares = u128_add(s.sum_squares, u128_square(abs(v))), - }; +static inline void +mean_and_variance_update(struct mean_and_variance *s, s64 v) +{ + s->n++; + s->sum += v; + s->sum_squares = u128_add(s->sum_squares, u128_square(abs(v))); } s64 mean_and_variance_get_mean(struct mean_and_variance s); -- cgit v1.2.3