Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 import unittest | |
| 6 | |
| 7 from libs.math.logarithms import logsumexp | |
| 8 | |
| 9 | |
| 10 INFINITY = float('inf') | |
| 11 | |
| 12 | |
| 13 class LogarithmsTest(unittest.TestCase): | |
| 14 | |
| 15 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
| |
| 16 """The empty sum is zero, log of zero is negative infinity.""" | |
| 17 self.assertEqual(-INFINITY, logsumexp([])) | |
| 18 | |
| 19 def testLogsumexpInfinite(self): | |
| 20 """If any summand is infinite, the whole thing is infinite.""" | |
| 21 self.assertEqual(INFINITY, logsumexp([INFINITY])) | |
| 22 self.assertEqual(INFINITY, logsumexp([INFINITY, -INFINITY])) | |
| 23 self.assertEqual(INFINITY, logsumexp([0, 1, 2, INFINITY, 9, 8, 7])) | |
| 24 | |
| 25 def testLogsumexpCommutative(self): | |
| 26 """Check that ``log(x+y) == log(y+x)`` as it should.""" | |
| 27 # N.B., we must choose these two values carefully, to ensure we | |
| 28 # don't trivially pass the test. | |
| 29 xs = [0.1, 0.3] | |
| 30 ys = xs[::-1] | |
| 31 self.assertEqual(logsumexp(xs), logsumexp(ys)) | |
| OLD | NEW |