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 INFINITY = float('inf') | |
| 10 | |
| 11 class LogarithmsTest(unittest.TestCase): | |
| 12 | |
| 13 def testLogsumexpEmpty(self): | |
|
Martin Barbella
2016/12/02 20:07:02
Docstrings here as well.
wrengr
2016/12/02 21:00:58
Done.
| |
| 14 self.assertEqual(-INFINITY, logsumexp([])) | |
| 15 | |
| 16 def testLogsumexpInfinite(self): | |
| 17 self.assertEqual(INFINITY, logsumexp([INFINITY])) | |
| 18 self.assertEqual(INFINITY, logsumexp([INFINITY, -INFINITY])) | |
| 19 self.assertEqual(INFINITY, logsumexp([0, 1, 2, INFINITY, 9, 8, 7])) | |
| 20 | |
| 21 def testLogsumexpCommutative(self): | |
| 22 # N.B., we must choose these two values carefully, to ensure we | |
| 23 # don't trivially pass the test. | |
| 24 xs = [0.1, 0.3] | |
| 25 ys = xs[::-1] | |
| 26 self.assertEqual(logsumexp(xs), logsumexp(ys)) | |
| OLD | NEW |