[Scipy-svn] r7008 - branches/0.9.x/scipy/stats

scipy-svn@scip... scipy-svn@scip...
Sun Dec 12 02:19:30 CST 2010


Author: rgommers
Date: 2010-12-12 02:19:30 -0600 (Sun, 12 Dec 2010)
New Revision: 7008

Modified:
   branches/0.9.x/scipy/stats/stats.py
Log:
BUG: 3K: fix integer division and list.sort issues in kendalltau.

Backported from r7006.

Modified: branches/0.9.x/scipy/stats/stats.py
===================================================================
--- branches/0.9.x/scipy/stats/stats.py	2010-12-12 08:19:10 UTC (rev 7007)
+++ branches/0.9.x/scipy/stats/stats.py	2010-12-12 08:19:30 UTC (rev 7008)
@@ -2600,7 +2600,7 @@
             perm[offs] = perm[offs+1]
             perm[offs+1] = t
             return 1
-        length0 = length / 2
+        length0 = length // 2
         length1 = length - length0
         middle = offs + length0
         exchcnt += mergesort(offs, length0)
@@ -2632,25 +2632,25 @@
     else:
         # sort implemented as quicksort, 30% faster but with worst case: O(n^2)
         perm = range(n)
-        perm.sort(lambda a,b: cmp(x[a],x[b]) or cmp(y[a],y[b]))
+        perm.sort(key=lambda a: (x[a], y[a]))
 
     # compute joint ties
     first = 0
     t = 0
     for i in xrange(1, n):
         if x[perm[first]] != x[perm[i]] or y[perm[first]] != y[perm[i]]:
-            t += ((i - first) * (i - first - 1)) / 2
+            t += ((i - first) * (i - first - 1)) // 2
             first = i
-    t += ((n - first) * (n - first - 1)) / 2
+    t += ((n - first) * (n - first - 1)) // 2
 
     # compute ties in x
     first = 0
     u = 0
     for i in xrange(1,n):
         if x[perm[first]] != x[perm[i]]:
-            u += ((i - first) * (i - first - 1)) / 2
+            u += ((i - first) * (i - first - 1)) // 2
             first = i
-    u += ((n - first) * (n - first - 1)) / 2
+    u += ((n - first) * (n - first - 1)) // 2
 
     # count exchanges
     exchanges = mergesort(0, n)
@@ -2659,11 +2659,11 @@
     v = 0
     for i in xrange(1,n):
         if y[perm[first]] != y[perm[i]]:
-            v += ((i - first) * (i - first - 1)) / 2
+            v += ((i - first) * (i - first - 1)) // 2
             first = i
-    v += ((n - first) * (n - first - 1)) / 2
+    v += ((n - first) * (n - first - 1)) // 2
 
-    tot = (n * (n - 1)) / 2
+    tot = (n * (n - 1)) // 2
     if tot == u and tot == v:
         return 1    # Special case for all ties in both ranks
 



More information about the Scipy-svn mailing list