Permalink
Browse files

BUG: 3K: fix integer division and list.sort issues in kendalltau.

Backported from r7006.
  • Loading branch information...
1 parent 8841da8 commit 2f5ca0276f2d63aca050167fc8d1f816b1e2f0c8 @rgommers rgommers committed Dec 12, 2010
Showing with 9 additions and 9 deletions.
  1. +9 −9 scipy/stats/stats.py
View
@@ -2600,7 +2600,7 @@ def mergesort(offs, length):
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 @@ def mergesort(offs, length):
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 @@ def mergesort(offs, length):
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

0 comments on commit 2f5ca02

Please sign in to comment.