diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2022-03-05 20:49:26 +0000 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2022-03-05 20:49:26 +0000 |
commit | d753ba5f49a061464c90b46de852944fe5fe3763 (patch) | |
tree | 7f334774dc30c8b224a69169a093c488fcf48df3 /src/lua/lua_tensor.c | |
parent | 0b4e9a4f0b3bfa7d3bc3a40239b41d85a15a44be (diff) | |
download | rspamd-d753ba5f49a061464c90b46de852944fe5fe3763.tar.gz rspamd-d753ba5f49a061464c90b46de852944fe5fe3763.zip |
[Minor] Deduplicate sum function
Diffstat (limited to 'src/lua/lua_tensor.c')
-rw-r--r-- | src/lua/lua_tensor.c | 17 |
1 files changed, 3 insertions, 14 deletions
diff --git a/src/lua/lua_tensor.c b/src/lua/lua_tensor.c index 76756e148..b78a17fc8 100644 --- a/src/lua/lua_tensor.c +++ b/src/lua/lua_tensor.c @@ -634,21 +634,10 @@ lua_tensor_eigen (lua_State *L) } 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 |