From d43989cf1cdcad5a840aaa606afb5b3496e85127 Mon Sep 17 00:00:00 2001 From: Al Date: Wed, 15 Mar 2017 00:22:17 -0400 Subject: [PATCH] [fix] log_sum_exp in SSE mode shouldn't modify the original array --- src/vector_math.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/vector_math.h b/src/vector_math.h index 84fc4b74..7ac49730 100644 --- a/src/vector_math.h +++ b/src/vector_math.h @@ -465,9 +465,10 @@ static inline void remez9_0_log2_sse(double *values, size_t num) \ static inline type name##_log_sum_exp(type *array, size_t n) { \ type max = name##_max(array, n); \ - name##_sub(array, max, n); \ - remez9_0_log2_sse(array, n); \ - type result = name##_sum(array, n); \ + type result = 0; \ + for (size_t i = 0; i < n; i++) { \ + result += exp(array[i] - max); \ + } \ return max + log(result); \ }