Index: examples/functions.py =================================================================== --- examples/functions.py +++ examples/functions.py @@ -4,6 +4,8 @@ mathematical functions, keyed off of the current time. """ from __future__ import print_function +from __future__ import division +from past.utils import old_div from lnt.testing import Machine, Run, TestSamples, Report import math import random @@ -28,7 +30,7 @@ else: output = open(output, 'w') - offset = math.pi/5 + offset = old_div(math.pi, 5) delay = 120. machine = Machine('Mr. Sin Wave', info={'delay': delay}) @@ -39,7 +41,8 @@ 'tag': 'simple', 'run_order': 1}) tests = [TestSamples('simple.%s' % name, - [fn(start*2*math.pi / delay + j * offset)], + [fn(old_div(start * 2 * math.pi, delay) + + j * offset)], info={'offset': j}) for j in range(5) for name, fn in (('sin', math.sin), Index: lnt/external/stats/pstat.py =================================================================== --- lnt/external/stats/pstat.py +++ lnt/external/stats/pstat.py @@ -106,6 +106,8 @@ ## 11/08/98 ... fixed aput to output large arrays correctly from __future__ import print_function +from __future__ import division +from past.utils import old_div import string, copy from types import * @@ -137,24 +139,24 @@ addon = [addon] if len(addon) < len(source): # is source list longer? if len(source) % len(addon) == 0: # are they integer multiples? - repeats = len(source)/len(addon) # repeat addon n times + repeats = old_div(len(source), len(addon)) # repeat addon n times origadd = copy.deepcopy(addon) for i in range(repeats-1): addon = addon + origadd else: - repeats = len(source)/len(addon)+1 # repeat addon x times, + repeats = old_div(len(source), len(addon)) + 1 # repeat addon x times, origadd = copy.deepcopy(addon) # x is NOT an integer for i in range(repeats-1): addon = addon + origadd addon = addon[0:len(source)] elif len(source) < len(addon): # is addon list longer? if len(addon) % len(source) == 0: # are they integer multiples? - repeats = len(addon)/len(source) # repeat source n times + repeats = old_div(len(addon), len(source)) # repeat source n times origsour = copy.deepcopy(source) for i in range(repeats-1): source = source + origsour else: - repeats = len(addon)/len(source)+1 # repeat source x times, + repeats = old_div(len(addon), len(source)) + 1 # repeat source x times, origsour = copy.deepcopy(source) # x is NOT an integer for i in range(repeats-1): source = source + origsour Index: lnt/external/stats/stats.py =================================================================== --- lnt/external/stats/stats.py +++ lnt/external/stats/stats.py @@ -223,6 +223,8 @@ ## fixed (a)histogram (which sometimes counted points cover all binsize = ((max(inlist)-min(inlist)+estbinwidth))/float(numbins) - lowerreallimit = min(inlist) - binsize/2 #lower real limit,1st bin + lowerreallimit = min(inlist) - old_div(binsize, 2) #lower real limit,1st bin bins = [0]*(numbins) extrapoints = 0 for num in inlist: @@ -695,7 +697,7 @@ """ sd = stdev(inlist) n = len(inlist) - return sd/math.sqrt(n) + return old_div(sd, math.sqrt(n)) def lz (inlist, score): @@ -705,7 +707,7 @@ Usage: lz(inlist, score) """ - z = (score-mean(inlist))/samplestdev(inlist) + z = old_div(score - mean(inlist), samplestdev(inlist)) return z @@ -847,9 +849,9 @@ ymean = mean(y) r_num = n*(summult(x,y)) - sum(x)*sum(y) r_den = math.sqrt((n*ss(x) - square_of_sums(x))*(n*ss(y)-square_of_sums(y))) - r = (r_num / r_den) # denominator already a float + r = old_div(r_num, r_den) # denominator already a float df = n-2 - t = r*math.sqrt(df/((1.0-r+TINY)*(1.0+r+TINY))) + t = r * math.sqrt(old_div(df, (1.0 - r + TINY) * (1.0 + r + TINY))) prob = betai(0.5*df,0.5,df/float(df+t*t)) return r, prob @@ -864,7 +866,7 @@ covar = lcov(x,y)*(len(x)-1)/float(len(x)) # correct denom to n xvar = lvar(x)*(len(x)-1)/float(len(x)) # correct denom to n yvar = lvar(y)*(len(y)-1)/float(len(y)) # correct denom to n - lincc = (2 * covar) / ((xvar+yvar) +((amean(x)-amean(y))**2)) + lincc = old_div(2 * covar, xvar + yvar + ((amean(x) - amean(y)) ** 2)) return lincc @@ -884,9 +886,9 @@ ranky = rankdata(y) dsq = sumdiffsquared(rankx,ranky) rs = 1 - 6*dsq / float(n*(n**2-1)) - t = rs * math.sqrt((n-2) / ((rs+1.0)*(1.0-rs))) + t = rs * math.sqrt(old_div(n - 2, (rs + 1.0) * (1.0 - rs))) df = n-2 - probrs = betai(0.5*df,0.5,df/(df+t*t)) # t already a float + probrs = betai(0.5 * df, 0.5, old_div(df, df + t * t)) # t already a float # probability values for rs are from part 2 of the spearman function in # Numerical Recipies, p.510. They are close to tables, but not exact. (?) return rs, probrs @@ -917,10 +919,12 @@ ymean = mean(pstat.colex(y,1)) n = len(data) adjust = math.sqrt((len(x)/float(n))*(len(y)/float(n))) - rpb = (ymean - xmean)/samplestdev(pstat.colex(data,1))*adjust + rpb = (old_div(ymean - xmean, samplestdev(pstat.colex(data, 1))) + * adjust) df = n-2 - t = rpb*math.sqrt(df/((1.0-rpb+TINY)*(1.0+rpb+TINY))) - prob = betai(0.5*df,0.5,df/(df+t*t)) # t already a float + t = rpb * math.sqrt(old_div(df, (1.0 - rpb + TINY) + * (1.0 + rpb + TINY))) + prob = betai(0.5 * df, 0.5, old_div(df, df + t * t)) # t already a float return rpb, prob @@ -952,9 +956,9 @@ n1 = n1 + 1 else: n2 = n2 + 1 - tau = iss / math.sqrt(n1*n2) - svar = (4.0*len(x)+10.0) / (9.0*len(x)*(len(x)-1)) - z = tau / math.sqrt(svar) + tau = old_div(iss, math.sqrt(n1 * n2)) + svar = old_div(4.0 * len(x) + 10.0, 9.0 * len(x) * (len(x) - 1)) + z = old_div(tau, math.sqrt(svar)) prob = erfcc(abs(z)/1.4142136) return tau, prob @@ -976,11 +980,11 @@ ymean = mean(y) r_num = float(n*(summult(x,y)) - sum(x)*sum(y)) r_den = math.sqrt((n*ss(x) - square_of_sums(x))*(n*ss(y)-square_of_sums(y))) - r = r_num / r_den - z = 0.5*math.log((1.0+r+TINY)/(1.0-r+TINY)) + r = old_div(r_num, r_den) + z = 0.5 * math.log(old_div(1.0 + r + TINY, 1.0 - r + TINY)) df = n-2 - t = r*math.sqrt(df/((1.0-r+TINY)*(1.0+r+TINY))) - prob = betai(0.5*df,0.5,df/(df+t*t)) + t = r * math.sqrt(old_div(df, (1.0 - r + TINY) * (1.0 + r + TINY))) + prob = betai(0.5 * df, 0.5, old_div(df, df + t * t)) slope = r_num / float(n*ss(x) - square_of_sums(x)) intercept = ymean - slope*xmean sterrest = math.sqrt(1-r*r)*samplestdev(y) @@ -1006,7 +1010,7 @@ n = len(a) df = n-1 svar = ((n-1)*v)/float(df) - t = (x-popmean)/math.sqrt(svar*(1.0/n)) + t = old_div(x - popmean, math.sqrt(svar * (1.0 / n))) prob = betai(0.5*df,0.5,float(df)/(df+t*t)) if printit != 0: @@ -1037,8 +1041,8 @@ n2 = len(b) df = n1+n2-2 svar = ((n1-1)*v1+(n2-1)*v2)/float(df) - t = (x1-x2)/math.sqrt(svar*(1.0/n1 + 1.0/n2)) - prob = betai(0.5*df,0.5,df/(df+t*t)) + t = old_div(x1 - x2, math.sqrt(svar * (1.0 / n1 + 1.0 / n2))) + prob = betai(0.5 * df, 0.5, old_div(df, df + t * t)) if printit != 0: statname = 'Independent samples T-test.' @@ -1073,8 +1077,8 @@ df = n-1 cov = cov / float(df) sd = math.sqrt((v1+v2 - 2.0*cov)/float(n)) - t = (x1-x2)/sd - prob = betai(0.5*df,0.5,df/(df+t*t)) + t = old_div(x1 - x2, sd) + prob = betai(0.5 * df, 0.5, old_div(df, df + t * t)) if printit != 0: statname = 'Related samples T-test.' @@ -1167,7 +1171,7 @@ if T == 0: raise ValueError('All numbers are identical in lmannwhitneyu') sd = math.sqrt(T*n1*n2*(n1+n2+1)/12.0) - z = abs((bigu-n1*n2/2.0) / sd) # normal approximation for prob calc + z = abs(old_div(bigu - n1 * n2 / 2.0, sd)) # normal approximation for prob calc return smallu, 1.0 - zprob(z) @@ -1213,7 +1217,7 @@ y = ranked[n1:] s = sum(x) expected = n1*(n1+n2+1) / 2.0 - z = (s - expected) / math.sqrt(n1*n2*(n1+n2+1)/12.0) + z = old_div(s - expected, math.sqrt(n1 * n2 * (n1 + n2 + 1) / 12.0)) prob = 2*(1.0 -zprob(abs(z))) return z, prob @@ -1246,7 +1250,7 @@ wt = min(r_plus, r_minus) mn = count * (count+1) * 0.25 se = math.sqrt(count*(count+1)*(2.0*count+1.0)/24.0) - z = math.fabs(wt-mn) / se + z = old_div(math.fabs(wt - mn), se) prob = 2*(1.0 -zprob(abs(z))) return wt, prob @@ -1481,20 +1485,20 @@ qab = a+b qap = a+1.0 qam = a-1.0 - bz = 1.0-qab*x/qap + bz = 1.0 - old_div(qab * x, qap) for i in range(ITMAX+1): em = float(i+1) tem = em + em - d = em*(b-em)*x/((qam+tem)*(a+tem)) + d = old_div(em * (b - em) * x, (qam + tem) * (a + tem)) ap = az + d*am bp = bz+d*bm - d = -(a+em)*(qab+em)*x/((qap+tem)*(a+tem)) + d = old_div(-(a + em) * (qab + em) * x, (qap + tem) * (a + tem)) app = ap+d*az bpp = bp+d*bz aold = az - am = ap/bpp - bm = bp/bpp - az = app/bpp + am = old_div(ap, bpp) + bm = old_div(bp, bpp) + az = old_div(app, bpp) bz = 1.0 if (abs(az-aold)<(EPS*abs(az))): return az @@ -1518,7 +1522,7 @@ ser = 1.0 for j in range(len(coeff)): x = x + 1 - ser = ser + coeff[j]/x + ser = ser + old_div(coeff[j], x) return -tmp + math.log(2.50662827465*ser) @@ -1541,7 +1545,7 @@ else: bt = math.exp(gammln(a+b)-gammln(a)-gammln(b)+a*math.log(x)+b* math.log(1.0-x)) - if (x<(a+1.0)/(a+b+2.0)): + if (x < old_div(a + 1.0, a + b + 2.0)): return bt*betacf(a,b,x)/float(a) else: return 1.0-bt*betacf(b,a,1.0-x)/float(b) @@ -1583,7 +1587,7 @@ dfwn = bign - a msb = ssbn/float(dfbn) msw = sswn/float(dfwn) - f = msb/msw + f = old_div(msb, msw) prob = fprob(dfbn,dfwn,f) return f, prob @@ -1752,7 +1756,7 @@ n = len(inlist) svec = copy.deepcopy(inlist) ivec = range(n) - gap = n/2 # integer division needed + gap = old_div(n, 2) # integer division needed while gap >0: for i in range(gap,n): for j in range(i-gap,-1,-gap): @@ -1763,7 +1767,7 @@ itemp = ivec[j] ivec[j] = ivec[j+gap] ivec[j+gap] = itemp - gap = gap / 2 # integer division needed + gap = old_div(gap, 2) # integer division needed # svec is now sorted inlist, and ivec has the order svec[i] = vec[ivec[i]] return svec, ivec @@ -2088,7 +2092,7 @@ for dim in dims: shp[dim] = 1 s = N.reshape(s,shp) - return size / s + return old_div(size, s) def amean (inarray,dimension=None,keepdims=0): @@ -2129,7 +2133,7 @@ for dim in dims: shp[dim] = 1 sum = N.reshape(sum,shp) - return sum/denom + return old_div(sum, denom) def amedian (inarray,numbins=1000): @@ -2171,10 +2175,10 @@ dimension = 0 inarray = N.sort(inarray,dimension) if inarray.shape[dimension] % 2 == 0: # if even number of elements - indx = inarray.shape[dimension]/2 # integer division correct + indx = old_div(inarray.shape[dimension], 2) # integer division correct median = N.asarray(inarray[indx]+inarray[indx-1]) / 2.0 else: - indx = inarray.shape[dimension] / 2 # integer division correct + indx = old_div(inarray.shape[dimension], 2) # integer division correct median = N.take(inarray,[indx],dimension) if median.shape == (1,): median = median[0] @@ -2238,7 +2242,7 @@ mask = lowerfcn(a,limits[0])*upperfcn(a,limits[1]) s = float(N.add.reduce(N.ravel(a*mask))) n = float(N.add.reduce(N.ravel(mask))) - return s/n + return old_div(s, n) def atvar(a,limits=None,inclusive=(1,1)): @@ -2356,7 +2360,7 @@ mask = lowerfcn(a,limits[0])*upperfcn(a,limits[1]) term1 = N.add.reduce(N.ravel(a*a*mask)) n = float(N.add.reduce(N.ravel(mask))) - return sd/math.sqrt(n) + return old_div(sd, math.sqrt(n)) ##################################### @@ -2413,7 +2417,7 @@ if isinstance(denom, N.ndarray) and asum(zero) != 0: print("Number of zeros in askew: ", asum(zero)) denom = denom + zero # prevent divide-by-zero - return N.where(zero, 0, amoment(a,3,dimension)/denom) + return N.where(zero, 0, old_div(amoment(a, 3, dimension), denom)) def akurtosis(a,dimension=None): @@ -2432,7 +2436,7 @@ if isinstance(denom, N.ndarray) and asum(zero) != 0: print("Number of zeros in akurtosis: ", asum(zero)) denom = denom + zero # prevent divide-by-zero - return N.where(zero,0,amoment(a,4,dimension)/denom) + return N.where(zero, 0, old_div(amoment(a, 4, dimension), denom)) def adescribe(inarray,dimension=None): @@ -2475,13 +2479,14 @@ dimension = 0 b2 = askew(a,dimension) n = float(a.shape[dimension]) - y = b2 * N.sqrt(((n+1)*(n+3)) / (6.0*(n-2)) ) - beta2 = ( 3.0*(n*n+27*n-70)*(n+1)*(n+3) ) / ( (n-2.0)*(n+5)*(n+7)*(n+9) ) + y = b2 * N.sqrt(old_div((n + 1) * (n + 3), 6.0 * (n - 2))) + beta2 = old_div(3.0 * (n * n + 27 * n - 70) * (n + 1) * (n + 3), + (n - 2.0) * (n + 5) * (n + 7) * (n + 9)) W2 = -1 + N.sqrt(2*(beta2-1)) - delta = 1/N.sqrt(N.log(N.sqrt(W2))) - alpha = N.sqrt(2/(W2-1)) + delta = old_div(1, N.sqrt(N.log(N.sqrt(W2)))) + alpha = N.sqrt(old_div(2, W2 - 1)) y = N.where(y==0,1,y) - Z = delta*N.log(y/alpha + N.sqrt((y/alpha)**2+1)) + Z = delta * N.log(old_div(y, alpha) + N.sqrt(old_div(y, alpha) ** 2 + 1)) return Z, (1.0-zprob(Z))*2 @@ -2504,15 +2509,19 @@ b2 = akurtosis(a,dimension) E = 3.0*(n-1) /(n+1) varb2 = 24.0*n*(n-2)*(n-3) / ((n+1)*(n+1)*(n+3)*(n+5)) - x = (b2-E)/N.sqrt(varb2) - sqrtbeta1 = 6.0*(n*n-5*n+2)/((n+7)*(n+9)) * N.sqrt((6.0*(n+3)*(n+5))/ - (n*(n-2)*(n-3))) + x = old_div(b2 - E, N.sqrt(varb2)) + sqrtbeta1 = (6.0 + * (n * n - 5 * n + 2) + / ((n + 7) * (n + 9)) + * N.sqrt(old_div(6.0 * (n + 3) * (n + 5), + n * (n - 2) * (n - 3)))) A = 6.0 + 8.0/sqrtbeta1 *(2.0/sqrtbeta1 + N.sqrt(1+4.0/(sqrtbeta1**2))) - term1 = 1 -2/(9.0*A) - denom = 1 +x*N.sqrt(2/(A-4.0)) + term1 = 1 - old_div(2, 9.0 * A) + denom = 1 + x * N.sqrt(old_div(2, A - 4.0)) denom = N.where(N.less(denom,0), 99, denom) - term2 = N.where(N.equal(denom,0), term1, N.power((1-2.0/A)/denom,1/3.0)) - Z = ( term1 - term2 ) / N.sqrt(2/(9.0*A)) + term2 = N.where(N.equal(denom, 0), term1, + N.power(old_div(1 - 2.0 / A, denom), 1 / 3.0)) + Z = old_div(term1 - term2, N.sqrt(old_div(2, (9.0 * A)))) Z = N.where(N.equal(denom,99), 0, Z) return Z, (1.0-zprob(Z))*2 @@ -2750,7 +2759,7 @@ """ m = mean(instack,dimension) sd = stdev(instack,dimension) - return N.where(sd==0,0,m/sd) + return N.where(sd == 0, 0, old_div(m, sd)) def acov (x,y, dimension=None,keepdims=0): @@ -2854,7 +2863,7 @@ n = n*inarray.shape[d] else: n = inarray.shape[dimension] - s = asamplestdev(inarray,dimension,keepdims) / N.sqrt(n-1) + s = old_div(asamplestdev(inarray, dimension, keepdims), N.sqrt(n - 1)) return s @@ -2866,7 +2875,7 @@ Usage: az(a, score) """ - z = (score-amean(a)) / asamplestdev(a) + z = old_div(score - amean(a), asamplestdev(a)) return z @@ -2893,7 +2902,7 @@ """ mns = amean(compare,dimension) sstd = asamplestdev(compare,0) - return (scores - mns) / sstd + return old_div(scores - mns, sstd) ##################################### @@ -2982,7 +2991,7 @@ """ C = acovariance(X) V = N.diagonal(C) - return C / N.sqrt(N.multiply.outer(V,V)) + return old_div(C, N.sqrt(N.multiply.outer(V, V))) def apaired(x,y): @@ -3061,7 +3070,7 @@ y = sets.Set(y) common = len(x.intersection(y)) total = float(len(x) + len(y)) - return 2*common/total + return old_div(2 * common, total) def icc(x,y=None,verbose=0): @@ -3084,11 +3093,12 @@ withinss = ass(x-pairmeans) + ass(y-pairmeans) withindf = float(len(x)) betwdf = float(len(x)-1) - withinms = withinss / withindf - betweenms = (totalss-withinss) / betwdf - rho = (betweenms-withinms)/(withinms+betweenms) - t = rho*math.sqrt(betwdf/((1.0-rho+TINY)*(1.0+rho+TINY))) - prob = abetai(0.5*betwdf,0.5,betwdf/(betwdf+t*t),verbose) + withinms = old_div(withinss, withindf) + betweenms = old_div(totalss - withinss, betwdf) + rho = old_div(betweenms - withinms, withinms + betweenms) + t = rho * math.sqrt(old_div(betwdf, + (1.0 - rho + TINY) * (1.0 + rho + TINY))) + prob = abetai(0.5 * betwdf, 0.5, old_div(betwdf, betwdf + t * t), verbose) return rho, prob @@ -3104,7 +3114,7 @@ covar = acov(x,y)*(len(x)-1)/float(len(x)) # correct denom to n xvar = avar(x)*(len(x)-1)/float(len(x)) # correct denom to n yvar = avar(y)*(len(y)-1)/float(len(y)) # correct denom to n - lincc = (2 * covar) / ((xvar+yvar) +((amean(x)-amean(y))**2)) + lincc = old_div(2 * covar, xvar + yvar + ((amean(x) - amean(y)) ** 2)) return lincc @@ -3122,10 +3132,10 @@ ymean = amean(y) r_num = n*(N.add.reduce(x*y)) - N.add.reduce(x)*N.add.reduce(y) r_den = math.sqrt((n*ass(x) - asquare_of_sums(x))*(n*ass(y)-asquare_of_sums(y))) - r = (r_num / r_den) + r = old_div(r_num, r_den) df = n-2 - t = r*math.sqrt(df/((1.0-r+TINY)*(1.0+r+TINY))) - prob = abetai(0.5*df,0.5,df/(df+t*t),verbose) + t = r * math.sqrt(old_div(df, (1.0 - r + TINY) * (1.0 + r + TINY))) + prob = abetai(0.5 * df, 0.5, old_div(df, df + t * t), verbose) return r,prob @@ -3143,9 +3153,9 @@ ranky = rankdata(y) dsq = N.add.reduce((rankx-ranky)**2) rs = 1 - 6*dsq / float(n*(n**2-1)) - t = rs * math.sqrt((n-2) / ((rs+1.0)*(1.0-rs))) + t = rs * math.sqrt(old_div(n - 2, (rs + 1.0) * (1.0 - rs))) df = n-2 - probrs = abetai(0.5*df,0.5,df/(df+t*t)) + probrs = abetai(0.5 * df, 0.5, old_div(df, df + t * t)) # probability values for rs are from part 2 of the spearman function in # Numerical Recipies, p.510. They close to tables, but not exact.(?) return rs, probrs @@ -3174,10 +3184,12 @@ ymean = amean(pstat.acolex(y,1)) n = len(data) adjust = math.sqrt((len(x)/float(n))*(len(y)/float(n))) - rpb = (ymean - xmean)/asamplestdev(pstat.acolex(data,1))*adjust + rpb = (old_div(ymean - xmean, asamplestdev(pstat.acolex(data, 1))) + * adjust) df = n-2 - t = rpb*math.sqrt(df/((1.0-rpb+TINY)*(1.0+rpb+TINY))) - prob = abetai(0.5*df,0.5,df/(df+t*t)) + t = rpb * math.sqrt(old_div(df, (1.0 - rpb + TINY) + * (1.0 + rpb + TINY))) + prob = abetai(0.5 * df, 0.5, old_div(df, df + t * t)) return rpb, prob @@ -3209,9 +3221,9 @@ n1 = n1 + 1 else: n2 = n2 + 1 - tau = iss / math.sqrt(n1*n2) - svar = (4.0*len(x)+10.0) / (9.0*len(x)*(len(x)-1)) - z = tau / math.sqrt(svar) + tau = old_div(iss, math.sqrt(n1 * n2)) + svar = old_div(4.0 * len(x) + 10.0, 9.0 * len(x) * (len(x) - 1)) + z = old_div(tau, math.sqrt(svar)) prob = erfcc(abs(z)/1.4142136) return tau, prob @@ -3242,12 +3254,12 @@ ymean = amean(y) r_num = n*(N.add.reduce(x*y)) - N.add.reduce(x)*N.add.reduce(y) r_den = math.sqrt((n*ass(x) - asquare_of_sums(x))*(n*ass(y)-asquare_of_sums(y))) - r = r_num / r_den - z = 0.5*math.log((1.0+r+TINY)/(1.0-r+TINY)) + r = old_div(r_num, r_den) + z = 0.5 * math.log(old_div(1.0 + r + TINY, 1.0 - r + TINY)) df = n-2 - t = r*math.sqrt(df/((1.0-r+TINY)*(1.0+r+TINY))) - prob = abetai(0.5*df,0.5,df/(df+t*t)) - slope = r_num / (float(n)*ass(x) - asquare_of_sums(x)) + t = r * math.sqrt(old_div(df, (1.0 - r + TINY) * (1.0 + r + TINY))) + prob = abetai(0.5 * df, 0.5, old_div(df, df + t * t)) + slope = old_div(r_num, float(n) * ass(x) - asquare_of_sums(x)) intercept = ymean - slope*xmean sterrest = math.sqrt(1-r*r)*asamplestdev(y) return slope, intercept, r, prob, sterrest, n @@ -3283,16 +3295,16 @@ r_den = N.sqrt((n*ass(x) - asquare_of_sums(x))*(n*ass(y,0)-asquare_of_sums(y,0))) zerodivproblem = N.equal(r_den,0) r_den = N.where(zerodivproblem,1,r_den) # avoid zero-division in 1st place - r = r_num / r_den # need to do this nicely for matrix division + r = old_div(r_num, r_den) # need to do this nicely for matrix division r = N.where(zerodivproblem,0.0,r) - z = 0.5*N.log((1.0+r+TINY)/(1.0-r+TINY)) + z = 0.5 * N.log(old_div(1.0 + r + TINY, 1.0 - r + TINY)) df = n-2 - t = r*N.sqrt(df/((1.0-r+TINY)*(1.0+r+TINY))) - prob = abetai(0.5*df,0.5,df/(df+t*t)) + t = r * N.sqrt(old_div(df, (1.0 - r + TINY) * (1.0 + r + TINY))) + prob = abetai(0.5 * df, 0.5, old_div(df, df + t * t)) ss = float(n)*ass(x)-asquare_of_sums(x) s_den = N.where(ss==0,1,ss) # avoid zero-division in 1st place - slope = r_num / s_den + slope = old_div(r_num, s_den) intercept = ymean - slope*xmean sterrest = N.sqrt(1-r*r)*asamplestdev(y,0) return slope, intercept, r, prob, sterrest, n @@ -3319,8 +3331,8 @@ n = len(a) df = n-1 svar = ((n-1)*v) / float(df) - t = (x-popmean)/math.sqrt(svar*(1.0/n)) - prob = abetai(0.5*df,0.5,df/(df+t*t)) + t = old_div(x - popmean, math.sqrt(svar * (1.0 / n))) + prob = abetai(0.5 * df, 0.5, old_div(df, df + t * t)) if printit != 0: statname = 'Single-sample T-test.' @@ -3359,7 +3371,7 @@ svar = ((n1-1)*v1+(n2-1)*v2) / float(df) zerodivproblem = N.equal(svar,0) svar = N.where(zerodivproblem,1,svar) # avoid zero-division in 1st place - t = (x1-x2)/N.sqrt(svar*(1.0/n1 + 1.0/n2)) # N-D COMPUTATION HERE!!!!!! + t = old_div(x1 - x2, N.sqrt(svar * (1.0 / n1 + 1.0 / n2))) # N-D COMPUTATION HERE!!!!!! t = N.where(zerodivproblem,1.0,t) # replace NaN/wrong t-values with 1.0 probs = abetai(0.5*df,0.5,float(df)/(df+t*t)) @@ -3405,7 +3417,7 @@ print(i, ' ', end=' ') t = N.where(pval99.9,1000,t) # hit upper-boundary @@ -3440,10 +3452,11 @@ df = float(n-1) d = (a-b).astype('d') - denom = N.sqrt((n*N.add.reduce(d*d,dimension) - N.add.reduce(d,dimension)**2) /df) + denom = N.sqrt(old_div(n * N.add.reduce(d * d, dimension) + - N.add.reduce(d, dimension) ** 2, df)) zerodivproblem = N.equal(denom,0) denom = N.where(zerodivproblem,1,denom) # avoid zero-division in 1st place - t = N.add.reduce(d,dimension) / denom # N-D COMPUTATION HERE!!!!!! + t = old_div(N.add.reduce(d, dimension), denom) # N-D COMPUTATION HERE!!!!!! t = N.where(zerodivproblem,1.0,t) # replace NaN/wrong t-values with 1.0 probs = abetai(0.5*df,0.5,float(df)/(df+t*t)) if isinstance(t, N.ndarray): @@ -3478,7 +3491,7 @@ if f_exp is None: f_exp = N.array([sum(f_obs)/float(k)] * len(f_obs),N.float_) f_exp = f_exp.astype(N.float_) - chisq = N.add.reduce((f_obs-f_exp)**2 / f_exp) + chisq = N.add.reduce(old_div((f_obs - f_exp) ** 2, f_exp)) return chisq, achisqprob(chisq, k-1) @@ -3546,7 +3559,7 @@ if T == 0: raise ValueError('All numbers are identical in amannwhitneyu') sd = math.sqrt(T*n1*n2*(n1+n2+1)/12.0) - z = abs((bigu-n1*n2/2.0) / sd) # normal approximation for prob calc + z = abs(old_div(bigu - n1 * n2 / 2.0, sd)) # normal approximation for prob calc return smallu, 1.0 - azprob(z) @@ -3592,7 +3605,7 @@ y = ranked[n1:] s = sum(x) expected = n1*(n1+n2+1) / 2.0 - z = (s - expected) / math.sqrt(n1*n2*(n1+n2+1)/12.0) + z = old_div(s - expected, math.sqrt(n1 * n2 * (n1 + n2 + 1) / 12.0)) prob = 2*(1.0 - azprob(abs(z))) return z, prob @@ -3622,8 +3635,8 @@ wt = min(r_plus, r_minus) mn = count * (count+1) * 0.25 se = math.sqrt(count*(count+1)*(2.0*count+1.0)/24.0) - z = math.fabs(wt-mn) / se - z = math.fabs(wt-mn) / se + z = old_div(math.fabs(wt - mn), se) + z = old_div(math.fabs(wt - mn), se) prob = 2*(1.0 -zprob(abs(z))) return wt, prob @@ -3760,7 +3773,7 @@ mask = N.zeros(probs.shape) a_notbig_frozen = -1 *N.ones(probs.shape,N.float_) while asum(mask) != totalelements: - e = e * (a/z.astype(N.float_)) + e = e * old_div(a, z.astype(N.float_)) c = c + e z = z + 1.0 # print '#2', z, e, c, s, c*y+s2 @@ -3879,7 +3892,8 @@ Usage: afprob(dfnum, dfden, F) where usually dfnum=dfbn, dfden=dfwn """ if isinstance(F, N.ndarray): - return abetai(0.5*dfden, 0.5*dfnum, dfden/(1.0*dfden+dfnum*F)) + return abetai(0.5 * dfden, 0.5 * dfnum, + old_div(dfden, 1.0 * dfden + dfnum * F)) else: return abetai(0.5*dfden, 0.5*dfnum, dfden/float(dfden+dfnum*F)) @@ -3907,22 +3921,22 @@ qab = a+b qap = a+1.0 qam = a-1.0 - bz = 1.0-qab*x/qap + bz = 1.0 - old_div(qab * x, qap) for i in range(ITMAX+1): if N.sum(N.ravel(N.equal(frozen,-1)))==0: break em = float(i+1) tem = em + em - d = em*(b-em)*x/((qam+tem)*(a+tem)) + d = old_div(em * (b - em) * x, (qam + tem) * (a + tem)) ap = az + d*am bp = bz+d*bm - d = -(a+em)*(qab+em)*x/((qap+tem)*(a+tem)) + d = old_div(-(a + em) * (qab + em) * x, (qap + tem) * (a + tem)) app = ap+d*az bpp = bp+d*bz aold = az*1 - am = ap/bpp - bm = bp/bpp - az = app/bpp + am = old_div(ap, bpp) + bm = old_div(bp, bpp) + az = old_div(app, bpp) bz = 1.0 newmask = N.less(abs(az-aold),EPS*abs(az)) frozen = N.where(newmask*N.equal(mask,0), az, frozen) @@ -3953,7 +3967,7 @@ ser = 1.0 for j in range(len(coeff)): x = x + 1 - ser = ser + coeff[j]/x + ser = ser + old_div(coeff[j], x) return -tmp + N.log(2.50662827465*ser) @@ -3984,11 +3998,11 @@ exponents = N.where(N.less(exponents,-740),-740,exponents) bt = N.exp(exponents) if isinstance(x, N.ndarray): - ans = N.where(N.less(x,(a+1)/(a+b+2.0)), - bt*abetacf(a,b,x,verbose)/float(a), - 1.0-bt*abetacf(b,a,1.0-x,verbose)/float(b)) + ans = N.where(N.less(x, old_div(a + 1, a + b + 2.0)), + bt * abetacf(a, b, x, verbose) / float(a), + 1.0 - bt * abetacf(b, a, 1.0 - x, verbose) / float(b)) else: - if x<(a+1)/(a+b+2.0): + if x < old_div(a + 1, a + b + 2.0): ans = bt*abetacf(a,b,x,verbose)/float(a) else: ans = 1.0-bt*abetacf(b,a,1.0-x,verbose)/float(b) @@ -4031,7 +4045,7 @@ c = N.array([1,-1]) df = n-2 fact = asum(1.0/asum(x,0)) # i.e., 1/n1 + 1/n2 + 1/n3 ... - t = N.dot(c,b) / N.sqrt(s_sq*fact) + t = old_div(N.dot(c, b), N.sqrt(s_sq * fact)) probs = abetai(0.5*df,0.5,float(df)/(df+t*t)) return t, probs @@ -4066,7 +4080,7 @@ dfwn = bign - na msb = ssbn/float(dfbn) msw = sswn/float(dfwn) - f = msb/msw + f = old_div(msb, msw) prob = fprob(dfbn,dfwn,f) return f, prob @@ -4115,7 +4129,7 @@ EF = N.array([[EF]]) n_um = (LA.det(ER) - LA.det(EF)) / float(dfnum) d_en = LA.det(EF) / float(dfden) - return n_um / d_en + return old_div(n_um, d_en) ##################################### @@ -4276,7 +4290,7 @@ n = len(inarray) svec = inarray *1.0 ivec = range(n) - gap = n/2 # integer division needed + gap = old_div(n, 2) # integer division needed while gap >0: for i in range(gap,n): for j in range(i-gap,-1,-gap): @@ -4287,7 +4301,7 @@ itemp = ivec[j] ivec[j] = ivec[j+gap] ivec[j+gap] = itemp - gap = gap / 2 # integer division needed + gap = old_div(gap, 2) # integer division needed # svec is now sorted input vector, ivec has the order svec[i] = vec[ivec[i]] return svec, ivec Index: lnt/server/db/rules/rule_update_profile_stats.py =================================================================== --- lnt/server/db/rules/rule_update_profile_stats.py +++ lnt/server/db/rules/rule_update_profile_stats.py @@ -2,6 +2,8 @@ Post submission hook to write the current state of the profiles directory. This gets fed into the profile/admin page. """ +from __future__ import division +from past.utils import old_div import datetime import glob import json @@ -35,7 +37,7 @@ for f in glob.glob('%s/*.lntprof' % profile_path): mtime = os.stat(f).st_mtime - sz = os.stat(f).st_size / 1000 + sz = old_div(os.stat(f).st_size, 1000) age.append([mtime, sz]) open(history_path, 'w').write(json.dumps(history)) Index: lnt/server/reporting/analysis.py =================================================================== --- lnt/server/reporting/analysis.py +++ lnt/server/reporting/analysis.py @@ -1,6 +1,8 @@ """ Utilities for helping with the analysis of data, for reporting purposes. """ +from __future__ import division +from past.utils import old_div from lnt.testing import FAIL from lnt.util import logger from lnt.util import multidict @@ -80,7 +82,7 @@ if self.current and prev_samples: self.delta, value = absmin_diff(self.current, prev_samples) if value != 0: - self.pct_delta = self.delta / value + self.pct_delta = old_div(self.delta, value) self.previous = value # If we have multiple values for this run, use that to estimate the Index: lnt/server/reporting/dailyreport.py =================================================================== --- lnt/server/reporting/dailyreport.py +++ lnt/server/reporting/dailyreport.py @@ -1,3 +1,5 @@ +from __future__ import division +from past.utils import old_div from lnt.server.reporting.analysis import REGRESSED, UNCHANGED_FAIL from lnt.server.reporting.report import RunResult, RunResults, report_css_styles, pairs, OrderAndHistory from lnt.util import multidict @@ -46,7 +48,7 @@ "{}={}".format( urllib.quote_plus(query_param), urllib.quote_plus(str(value))) for query_param, value in ( - ("day_start", self.day_start_offset.seconds / 3600), + ("day_start", old_div(self.day_start_offset.seconds, 3600)), ("num_days", self.num_prior_days_to_include), ("filter-machine-regex", self.filter_machine_regex_str),) if value is not None] Index: lnt/server/reporting/summaryreport.py =================================================================== --- lnt/server/reporting/summaryreport.py +++ lnt/server/reporting/summaryreport.py @@ -1,3 +1,5 @@ +from __future__ import division +from past.utils import old_div import re import lnt.testing @@ -47,7 +49,7 @@ self.sum = None def getvalue(self): - return [value/self.count for value in self.sum] + return [old_div(value, self.count) for value in self.sum] def _initialize(self, values): self.sum = [0.] * len(values) @@ -65,7 +67,7 @@ self.product = None def getvalue(self): - return [value ** 1.0/self.count for value in self.product] + return [old_div(value ** 1.0, self.count) for value in self.product] def __repr__(self): return repr(self.geometric_mean) @@ -82,7 +84,7 @@ class NormalizedMean(Mean): def _append(self, values): baseline = values[0] - Mean._append(self, [v/baseline + Mean._append(self, [old_div(v, baseline) for v in values]) ### @@ -502,4 +504,4 @@ values = normalized_value.getvalue() baseline = values[0] items.append(('Single File Tests', arch, - [v/baseline for v in values])) + [old_div(v, baseline) for v in values])) Index: lnt/server/ui/util.py =================================================================== --- lnt/server/ui/util.py +++ lnt/server/ui/util.py @@ -1,3 +1,5 @@ +from __future__ import division +from past.utils import old_div import colorsys import math import re @@ -14,7 +16,7 @@ def safediv(a, b, default=None): try: - return a / b + return old_div(a, b) except ZeroDivisionError: return default @@ -70,7 +72,7 @@ def mean(values): - return sum(values) / len(values) + return old_div(sum(values), len(values)) def median(values): @@ -312,7 +314,7 @@ self.previous = old self.current = new self.delta = new - old - self.pct_delta = self.delta / old + self.pct_delta = old_div(self.delta, old) def get_test_status(self): return True Index: lnt/server/ui/views.py =================================================================== --- lnt/server/ui/views.py +++ lnt/server/ui/views.py @@ -1,3 +1,5 @@ +from __future__ import division +from past.utils import old_div import datetime import json import os @@ -978,11 +980,11 @@ # Skip this baseline if there is no data. if not samples: continue - mean = sum(samples)/len(samples) + mean = old_div(sum(samples), len(samples)) # Darken the baseline color distinguish from non-baselines. # Make a color closer to the sample than its neighbour. color_offset = float(baseline_id) / num_baselines / 2 - my_color = (i + color_offset) / num_plots + my_color = old_div(i + color_offset, num_plots) dark_col = list(util.makeDarkerColor(my_color)) str_dark_col = util.toColorString(dark_col) baseline_plots.append({ @@ -1150,7 +1152,7 @@ # We compute the regression line in terms of a normalized X scale. x_min, x_max = min(xs), max(xs) try: - norm_xs = [(x - x_min) / (x_max - x_min) + norm_xs = [old_div(x - x_min, x_max - x_min) for x in xs] except ZeroDivisionError: norm_xs = xs @@ -1895,7 +1897,7 @@ @frontend.route("/explode") def explode(): """This route is going to exception. Used for testing 500 page.""" - return 1/0 + return old_div(1, 0) @frontend.route("/gone") Index: requirements.client.txt =================================================================== --- requirements.client.txt +++ requirements.client.txt @@ -17,4 +17,5 @@ click==6.7 pyyaml==3.12 requests +future -e svn+https://llvm.org/svn/llvm-project/llvm/trunk/utils/lit/#egg=lit