From 606e3e38b8a830dbbe65963ebf6c5ce7866b7800 Mon Sep 17 00:00:00 2001 From: Chris Dyer Date: Tue, 18 Mar 2014 01:41:17 -0400 Subject: star function --- utils/logval.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'utils/logval.h') 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 #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 @@ -242,4 +243,15 @@ bool operator>=(const LogVal& lhs, const LogVal& rhs) { template std::size_t hash_value(const LogVal& x) { return x.hash_impl(); } +template +LogVal star(LogVal x) { + if (x.is_0()) return x; + if (x.v_ >= 0) { + x.v_ = std::numeric_limits::infinity(); + } else { + x.v_ = -log1p(-x.as_float()); + } + return x; +} + #endif -- cgit v1.2.3