[math] Only float vectors have *_array_log, *_array_exp, etc.

This commit is contained in:
Al
2015-08-26 17:58:01 -04:00
parent a2ec8001b0
commit 07b0bed602
2 changed files with 36 additions and 31 deletions

View File

@@ -37,8 +37,8 @@ VECTOR_INIT_NUMERIC(int32_array, int32_t)
VECTOR_INIT_NUMERIC(uint32_array, uint32_t)
VECTOR_INIT_NUMERIC(int64_array, int64_t)
VECTOR_INIT_NUMERIC(uint64_array, uint64_t)
VECTOR_INIT_NUMERIC(float_array, float)
VECTOR_INIT_NUMERIC(double_array, double)
VECTOR_INIT_NUMERIC_FLOAT(float_array, float)
VECTOR_INIT_NUMERIC_FLOAT(double_array, double)
VECTOR_INIT(char_array, char)
VECTOR_INIT(uchar_array, unsigned char)

View File

@@ -113,18 +113,6 @@
} \
} \
\
static inline void name##_log(name *vector, type c, size_t n) { \
for (int i = 0; i < n; i++) { \
vector->a[i] += log(vector->a[i]); \
} \
} \
\
static inline void name##_exp(name *vector, type c, size_t n) { \
for (int i = 0; i < n; i++) { \
vector->a[i] += exp(vector->a[i]); \
} \
} \
\
static inline type name##_sum(name *vector, size_t n) { \
type result = 0; \
for (int i = 0; i < n; i++) { \
@@ -141,23 +129,6 @@
return result; \
} \
\
static inline type name##_log_sum(name *vector, size_t n) { \
type result = 0; \
for (int i = 0; i < n; i++) { \
result += log(vector->a[i]); \
} \
return result; \
} \
\
static inline type name##_log_sum_exp(name *vector, size_t n) { \
type max = name##_max(vector, n); \
type result = 0; \
for (int i = 0; i < n; i++) { \
result += exp(vector->a[i] - max); \
} \
return max + log(result); \
} \
\
static inline void name##_add_vector(name *v1, name *v2, size_t n) { \
for (int i = 0; i < n; i++) { \
v1->a[i] += v2->a[i]; \
@@ -191,4 +162,38 @@
}
#define VECTOR_INIT_NUMERIC_FLOAT(name, type) \
VECTOR_INIT_NUMERIC(name, type) \
\
static inline void name##_log(name *vector, type c, size_t n) { \
for (int i = 0; i < n; i++) { \
vector->a[i] += log(vector->a[i]); \
} \
} \
\
static inline void name##_exp(name *vector, type c, size_t n) { \
for (int i = 0; i < n; i++) { \
vector->a[i] += exp(vector->a[i]); \
} \
} \
\ \
static inline type name##_log_sum(name *vector, size_t n) { \
type result = 0; \
for (int i = 0; i < n; i++) { \
result += log(vector->a[i]); \
} \
return result; \
} \
\
static inline type name##_log_sum_exp(name *vector, size_t n) { \
type max = name##_max(vector, n); \
type result = 0; \
for (int i = 0; i < n; i++) { \
result += exp(vector->a[i] - max); \
} \
return max + log(result); \
}
#endif