Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Unified Diff: appengine/findit/libs/math/test/logarithms_test.py

Issue 2543333002: Added log-domain summation (Closed)
Patch Set: rebase Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: appengine/findit/libs/math/test/logarithms_test.py
diff --git a/appengine/findit/libs/math/test/logarithms_test.py b/appengine/findit/libs/math/test/logarithms_test.py
new file mode 100644
index 0000000000000000000000000000000000000000..9a8ece889e89c661538aea22be0f9688d7f101d8
--- /dev/null
+++ b/appengine/findit/libs/math/test/logarithms_test.py
@@ -0,0 +1,31 @@
+# Copyright 2016 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import unittest
+
+from libs.math.logarithms import logsumexp
+
+
+INFINITY = float('inf')
+
+
+class LogarithmsTest(unittest.TestCase):
+
+ def testLogsumexpEmpty(self):
inferno 2016/12/04 23:51:24 Can we have a test actual value for logsumpexp for
wrengr 2016/12/05 19:12:59 Testing concrete values is problematic because the
+ """The empty sum is zero, log of zero is negative infinity."""
+ self.assertEqual(-INFINITY, logsumexp([]))
+
+ def testLogsumexpInfinite(self):
+ """If any summand is infinite, the whole thing is infinite."""
+ self.assertEqual(INFINITY, logsumexp([INFINITY]))
+ self.assertEqual(INFINITY, logsumexp([INFINITY, -INFINITY]))
+ self.assertEqual(INFINITY, logsumexp([0, 1, 2, INFINITY, 9, 8, 7]))
+
+ def testLogsumexpCommutative(self):
+ """Check that ``log(x+y) == log(y+x)`` as it should."""
+ # N.B., we must choose these two values carefully, to ensure we
+ # don't trivially pass the test.
+ xs = [0.1, 0.3]
+ ys = xs[::-1]
+ self.assertEqual(logsumexp(xs), logsumexp(ys))
« appengine/findit/libs/math/logarithms.py ('K') | « appengine/findit/libs/math/logarithms.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698