diff options
author | Patrick Simianer <p@simianer.de> | 2014-06-12 13:56:42 +0200 |
---|---|---|
committer | Patrick Simianer <p@simianer.de> | 2014-06-12 13:56:42 +0200 |
commit | 244971287003d079e46193b8a209c28955f90134 (patch) | |
tree | 8beaae6b12b913acb213fc7f2415fd63886192f9 /utils/logval.h | |
parent | 5250fd67a4b8f242068cff87f0a6a4211f8b0fcf (diff) | |
parent | b66e838ed52decc0be1eb5817b2a77c3840db2c5 (diff) |
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'utils/logval.h')
-rw-r--r-- | utils/logval.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/utils/logval.h b/utils/logval.h index ec1f6acd..0c9ee982 100644 --- a/utils/logval.h +++ b/utils/logval.h @@ -11,6 +11,7 @@ #include <cassert> #include "semiring.h" #include "show.h" +#include "star.h" //TODO: template for supporting negation or not - most uses are for nonnegative "probs" only; probably some 10-20% speedup available template <class T> @@ -242,4 +243,15 @@ bool operator>=(const LogVal<T>& lhs, const LogVal<T>& rhs) { template <class T> std::size_t hash_value(const LogVal<T>& x) { return x.hash_impl(); } +template <class T> +inline LogVal<T> star(LogVal<T> x) { + if (x.is_0()) return x; + if (x.v_ >= 0) { + x.v_ = std::numeric_limits<T>::infinity(); + } else { + x.v_ = -log1p(-x.as_float()); + } + return x; +} + #endif |