[LNT] r238973 - All of these routines make the assumption of floats, check that

Chris Matthews cmatthews5 at apple.com
Wed Jun 3 14:01:45 PDT 2015


Author: cmatthews
Date: Wed Jun  3 16:01:45 2015
New Revision: 238973

URL: http://llvm.org/viewvc/llvm-project?rev=238973&view=rev
Log:
All of these routines make the assumption of floats, check that

Modified:
    lnt/trunk/lnt/util/stats.py

Modified: lnt/trunk/lnt/util/stats.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/util/stats.py?rev=238973&r1=238972&r2=238973&view=diff
==============================================================================
--- lnt/trunk/lnt/util/stats.py (original)
+++ lnt/trunk/lnt/util/stats.py Wed Jun  3 16:01:45 2015
@@ -10,17 +10,34 @@ def safe_min(l):
     else:
         return min(l)
 
+
+def check_floating(l):
+    """These math ops are totally wrong when they done on anything besides
+    floats.  I would just cast them, however that really slows them down.
+    So lets error on this """
+    for v in l:
+        assert type(v) == float, "Math op on non-floating point:" + str(v) + \
+            str(l)
+
+
 def mean(l):
+    check_floating(l)
     if l:
-        return sum(l)/len(l)
+        l = map(float, l)
+        return float_mean(l)
     else:
         return None
 
 
+def float_mean(l):
+    return sum(l)/len(l)
+
+
 def median(l):
     if not l:
         return None
-    l = list(l)
+    l = list(l)  # Could be a tuple.
+    check_floating(l)
     l.sort()
     N = len(l)
     return (l[(N-1)//2] + l[N//2])*.5
@@ -29,11 +46,13 @@ def median(l):
 def median_absolute_deviation(l, med = None):
     if med is None:
         med = median(l)
+    check_floating(l)
     return median([abs(x - med) for x in l])
 
 
 def standard_deviation(l):
-    m = mean(l)
+    check_floating(l)
+    m = float_mean(l)
     means_sqrd = sum([(v - m)**2 for v in l]) / len(l)
     rms = math.sqrt(means_sqrd)
     return rms
@@ -43,6 +62,8 @@ def mannwhitneyu(a, b, sigLevel = .05):
     """
     Determine if sample a and b are the same at given significance level.
     """
+    check_floating(a)
+    check_floating(b)
     if len(a) <= 20 and len(b) <= 20:
         return mannwhitneyu_small(a, b, sigLevel)
     else:
@@ -62,7 +83,7 @@ def mannwhitneyu_small(a, b, sigLevel):
     assert len(a) <= 20, "Sample size must be less than 20."
     assert len(b) <= 20, "Sample size must be less than 20."
 
-    if not sigLevel in SIGN_TABLES:
+    if sigLevel not in SIGN_TABLES:
         raise ValueError("Do not have according significance table.")
 
     # Calculate U value for sample groups using method described on Wikipedia.





More information about the llvm-commits mailing list