summaryrefslogtreecommitdiff
path: root/utils/logval.h
diff options
context:
space:
mode:
authorChris Dyer <redpony@gmail.com>2014-03-18 01:41:17 -0400
committerChris Dyer <redpony@gmail.com>2014-03-18 01:41:17 -0400
commit606e3e38b8a830dbbe65963ebf6c5ce7866b7800 (patch)
tree332cec5e0b4c8e3b8d6cc0d631fe5d5815f088f6 /utils/logval.h
parentcc87bfed0697583b7c11243913254dde3c0047d4 (diff)
star function
Diffstat (limited to 'utils/logval.h')
-rw-r--r--utils/logval.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/utils/logval.h b/utils/logval.h
index ec1f6acd..7f1e1024 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>
+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