X-Git-Url: https://gerrit.fd.io/r/gitweb?p=csit.git;a=blobdiff_plain;f=resources%2Flibraries%2Fpython%2FPLRsearch%2Flog_plus.py;h=1c802a5599624c07945fbfb119c7590e25970b56;hp=3f21cc78d7f93a6eca613f75e231e5fac26de6f0;hb=3d1e8a1fdfa0ec734adf7cc4370e955508882fdc;hpb=51511689eb9f93134878c314ba0349f28ef2ec4f diff --git a/resources/libraries/python/PLRsearch/log_plus.py b/resources/libraries/python/PLRsearch/log_plus.py index 3f21cc78d7..1c802a5599 100644 --- a/resources/libraries/python/PLRsearch/log_plus.py +++ b/resources/libraries/python/PLRsearch/log_plus.py @@ -1,4 +1,4 @@ -# Copyright (c) 2018 Cisco and/or its affiliates. +# Copyright (c) 2019 Cisco and/or its affiliates. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at: @@ -87,3 +87,16 @@ def log_minus(first, second): raise RuntimeError("log_minus: non-positive number to log") else: return first + math.log(factor) + + +def safe_exp(log_value): + """Return exponential of the argument, or zero if the argument is None. + + :param log_value: The value to exponentiate. + :type log_value: NoneType or float + :returns: The exponentiated value. + :rtype: float + """ + if log_value is None: + return 0.0 + return math.exp(log_value)