}
static inline rspamd_tensor_num_t
-mean_vec (rspamd_tensor_num_t *x, int n)
+mean_vec (rspamd_tensor_num_t *x, gsize n)
{
- rspamd_tensor_num_t s = 0;
- volatile rspamd_tensor_num_t c = 0;
-
- /* https://en.wikipedia.org/wiki/Kahan_summation_algorithm */
- for (int i = 0; i < n; i ++) {
- rspamd_tensor_num_t v = x[i];
- rspamd_tensor_num_t y = v - c;
- rspamd_tensor_num_t t = s + y;
- c = (t - s) - y;
- s = t;
- }
-
- return s / (rspamd_tensor_num_t)n;
+ float sum = rspamd_sum_floats (x, &n);
+ return sum / (rspamd_tensor_num_t)n;
}
static gint
cur_stat.actions_stat[METRIC_ACTION_REWRITE_SUBJECT];
gdouble new_ham = cur_stat.actions_stat[METRIC_ACTION_NOACTION];
- /* Kahan sum */
- float sum = 0.0f;
- volatile float c = 0.0f; /* We don't want any optimisations around c */
- int cnt = 0;
-
- for (int i = 0; i < MAX_AVG_TIME_SLOTS; i ++) {
- if (!isnan(cur_stat.avg_time.avg_time[i])) {
- cnt ++;
- float y = cur_stat.avg_time.avg_time[i] - c;
- float t = sum + y;
- c = (t - sum) - y;
- sum = t;
- }
- }
+ gsize cnt = MAX_AVG_TIME_SLOTS;
+ float sum = rspamd_sum_floats (cur_stat.avg_time.avg_time, &cnt);
rspamd_snprintf (proctitle, sizeof (proctitle),
"main process; %.1f msg/sec, %.1f msg/sec spam, %.1f msg/sec ham; %.2fs avg processing time",