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

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

Issue 2625073003: [Predator] Add MetaWeight and MetaFeatureValue to group multiple weights and features together. (Closed)
Patch Set: Rebase. Created 3 years, 11 months 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
« no previous file with comments | « appengine/findit/crash/loglinear/weight.py ('k') | appengine/findit/libs/math/vectors.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: appengine/findit/libs/math/test/vectors_test.py
diff --git a/appengine/findit/libs/math/test/vectors_test.py b/appengine/findit/libs/math/test/vectors_test.py
index 0e7983d37a7714d834f4164ac669e56143f31b97..36c225f2abd0dc2c45bce4fc9c9a7a3d65480289 100644
--- a/appengine/findit/libs/math/test/vectors_test.py
+++ b/appengine/findit/libs/math/test/vectors_test.py
@@ -54,7 +54,7 @@ class VectorsTest(unittest.TestCase):
"""
self.assertIsNone(vsum([]))
- def testVSumEmptyWithShape(self):
+ def testVsumEmptyWithShape(self):
"""Ensure ``vsum`` returns the zero vector when expected.
The empty summation should return the zero vector. If we know the
@@ -68,3 +68,22 @@ class VectorsTest(unittest.TestCase):
self.assertTupleEqual(expected_shape, total.shape)
self.assertListEqual(np.zeros(expected_shape).tolist(), total.tolist())
+ def testVsumWithNonFloatVector(self):
+ """Tests that ``vsum`` works for list of float-like objects."""
+ class MimicFloat(object):
+
+ def __init__(self, value):
+ self.value = float(value)
+
+ def __add__(self, number):
+ return math.fsum([self.value, number])
+
+ __radd__ = __add__
+
+ lists = [[2.3, 0.4], [0.2, 0.3]]
+ array_lists = [np.array(l) for l in lists]
+ mimic_float_lists = [[MimicFloat(number) for number in l] for l in lists]
+ array_mimic_float_lists = [np.array(l) for l in mimic_float_lists]
+
+ self.assertListEqual(vsum(array_lists).tolist(),
+ vsum(array_mimic_float_lists).tolist())
« no previous file with comments | « appengine/findit/crash/loglinear/weight.py ('k') | appengine/findit/libs/math/vectors.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698