[PATCH] D67821: [LNT] Python 3 support: use Python 2's division behavior

Thomas Preud'homme via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 26 12:28:14 PDT 2019


thopre added inline comments.

(Showing first 100 of 113 inline comments.)

================
Comment at: examples/functions.py:31
 
-    offset = math.pi/5
     delay = 120.
----------------
math.pi is float as pointed out by Hubert and thus this is float division


================
Comment at: examples/functions.py:42
     tests = [TestSamples('simple.%s' % name,
-                         [fn(start*2*math.pi / delay + j * offset)],
                          info={'offset': j})
----------------
math.pi is float as pointed out by Hubert and thus this is float division


================
Comment at: lnt/external/stats/pstat.py:140
             if len(source) % len(addon) == 0:        # are they integer multiples?
-                repeats = len(source)/len(addon)    # repeat addon n times
                 origadd = copy.deepcopy(addon)
----------------
len returns an integer as pointed out by Hubert so this is a floor division


================
Comment at: lnt/external/stats/pstat.py:145
             else:
-                repeats = len(source)/len(addon)+1  # repeat addon x times,
                 origadd = copy.deepcopy(addon)      #    x is NOT an integer
----------------
len returns an integer as pointed out by Hubert so this is a floor division


================
Comment at: lnt/external/stats/pstat.py:152
             if len(addon) % len(source) == 0:        # are they integer multiples?
-                repeats = len(addon)/len(source)    # repeat source n times
                 origsour = copy.deepcopy(source)
----------------
len returns an integer as pointed out by Hubert so this is a floor division


================
Comment at: lnt/external/stats/pstat.py:157
             else:
-                repeats = len(addon)/len(source)+1  # repeat source x times,
                 origsour = copy.deepcopy(source)    #   x is NOT an integer
----------------
len returns an integer as pointed out by Hubert so this is a floor division


================
Comment at: lnt/external/stats/stats.py:293
         sum = sum + 1.0/item
-    return len(inlist) / sum
 
----------------
As pointed by Hubert, either sum is 0 and thus both divisions give the same result, or sum is float by virtue of the 1.0/item and thus this should be float division.


================
Comment at: lnt/external/stats/stats.py:341
     if len(newlist) % 2 == 0:   # if even number of scores, average middle 2
-        index = len(newlist)/2  # integer division correct
         median = float(newlist[index] + newlist[index-1]) /2
----------------
len returns an int, therefore this is a floor division.


================
Comment at: lnt/external/stats/stats.py:417
 """
-    return moment(inlist,3)/pow(moment(inlist,2),1.5)
 
----------------
Second operand is a float due to being a number to the power 1.5, therefore this is a float division.


================
Comment at: lnt/external/stats/stats.py:427
 """
-    return moment(inlist,4)/pow(moment(inlist,2),2.0)
 
----------------
Denominator is a float due to being a number to the power 1.5, therefore this is a float division.


================
Comment at: lnt/external/stats/stats.py:522
         binsize = ((max(inlist)-min(inlist)+estbinwidth))/float(numbins)
-        lowerreallimit = min(inlist) - binsize/2 #lower real limit,1st bin
     bins = [0]*(numbins)
----------------
binsize is obtained by float division, therefore this is a float division.


================
Comment at: lnt/external/stats/stats.py:698
     n = len(inlist)
-    return sd/math.sqrt(n)
 
----------------
math.sqrt returns a float so this is a float division.


================
Comment at: lnt/external/stats/stats.py:708
 """
-    z = (score-mean(inlist))/samplestdev(inlist)
     return z
----------------
mean refers to lmean in the same module which returns a float so this is a float division.


================
Comment at: lnt/external/stats/stats.py:850
     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
     df = n-2
----------------
As pointed out by the comment, r_den is a float (at least due to the call to math.sqrt) and thus this is a float division.


================
Comment at: lnt/external/stats/stats.py:852
     df = n-2
-    t = r*math.sqrt(df/((1.0-r+TINY)*(1.0+r+TINY)))
     prob = betai(0.5*df,0.5,df/float(df+t*t))
----------------
Denominator contains float operand and is thus float, this is a float division.


================
Comment at: lnt/external/stats/stats.py:867
     yvar = lvar(y)*(len(y)-1)/float(len(y))  # correct denom to n
-    lincc = (2 * covar) / ((xvar+yvar) +((amean(x)-amean(y))**2))
     return lincc
----------------
All variables involved are computed with float operations, this is thus a float division.


================
Comment at: lnt/external/stats/stats.py:887
     rs = 1 - 6*dsq / float(n*(n**2-1))
-    t = rs * math.sqrt((n-2) / ((rs+1.0)*(1.0-rs)))
     df = n-2
----------------
rs is computed with a float operand, it is therefore a float and this is a float division.


================
Comment at: lnt/external/stats/stats.py:889
     df = n-2
-    probrs = betai(0.5*df,0.5,df/(df+t*t))  # t already a float
 # probability values for rs are from part 2 of the spearman function in
----------------
As mentioned in the comment, t is a float (bein computed from a sqrt call) and this is thus a float division.


================
Comment at: lnt/external/stats/stats.py:920
         adjust = math.sqrt((len(x)/float(n))*(len(y)/float(n)))
-        rpb = (ymean - xmean)/samplestdev(pstat.colex(data,1))*adjust
         df = n-2
----------------
xmean and ymean are float by virtue of being the result of a call to mean. This is a float division.


================
Comment at: lnt/external/stats/stats.py:922-923
         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
         return rpb, prob
----------------
Denominator for the first line has some float operations, this is a float division and thus the line below too.


================
Comment at: lnt/external/stats/stats.py:955-957
-    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)
----------------
All divisions involve calls to sqrt or floating-point operands, these are float divisions.


================
Comment at: lnt/external/stats/stats.py:979
     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_num involves a float operand so this is a float division.


================
Comment at: lnt/external/stats/stats.py:980
-    r = r_num / r_den
-    z = 0.5*math.log((1.0+r+TINY)/(1.0-r+TINY))
     df = n-2
----------------
Float operands => float division.


================
Comment at: lnt/external/stats/stats.py:982-983
     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))
     slope = r_num / float(n*ss(x) - square_of_sums(x))
----------------
float operand => first line uses a float division and thus the second line as well.


================
Comment at: lnt/external/stats/stats.py:1009
     svar = ((n-1)*v)/float(df)
-    t = (x-popmean)/math.sqrt(svar*(1.0/n))
     prob = betai(0.5*df,0.5,float(df)/(df+t*t))
----------------
Denominator is a sqrt return value, this is a float division


================
Comment at: lnt/external/stats/stats.py:1040-1041
     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))
 
----------------
Denominator in first line is a sqrt return value, so it is a float division and therefore the second line as well.


================
Comment at: lnt/external/stats/stats.py:1076-1077
     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))
 
----------------
denominator in first line is the return value of a sqrt call and so division on that line is a float division and thus the second line too


================
Comment at: lnt/external/stats/stats.py:1170
     sd = math.sqrt(T*n1*n2*(n1+n2+1)/12.0)
-    z = abs((bigu-n1*n2/2.0) / sd)  # normal approximation for prob calc
     return smallu, 1.0 - zprob(z)
----------------
sd is a sqrt return value, numerator has float operators => float division


================
Comment at: lnt/external/stats/stats.py:1216
     expected = n1*(n1+n2+1) / 2.0
-    z = (s - expected) / math.sqrt(n1*n2*(n1+n2+1)/12.0)
     prob = 2*(1.0 -zprob(abs(z)))
----------------
sqrt return value as denominator => float division


================
Comment at: lnt/external/stats/stats.py:1249
     se =  math.sqrt(count*(count+1)*(2.0*count+1.0)/24.0)
-    z = math.fabs(wt-mn) / se
     prob = 2*(1.0 -zprob(abs(z)))
----------------
se = sqrt return val => float division


================
Comment at: lnt/external/stats/stats.py:1484
     qam = a-1.0
-    bz = 1.0-qab*x/qap
     for i in range(ITMAX+1):
----------------
qap has float operands => float division


================
Comment at: lnt/external/stats/stats.py:1488
         tem = em + em
-        d = em*(b-em)*x/((qam+tem)*(a+tem))
         ap = az + d*am
----------------
em = float => float division


================
Comment at: lnt/external/stats/stats.py:1491
         bp = bz+d*bm
-        d = -(a+em)*(qab+em)*x/((qap+tem)*(a+tem))
         app = ap+d*az
----------------
Likewise.


================
Comment at: lnt/external/stats/stats.py:1495-1497
-        am = ap/bpp
-        bm = bp/bpp
-        az = app/bpp
----------------
ap, bp and app are constructed with the d values above which are float => float division


================
Comment at: lnt/external/stats/stats.py:1521
         x = x + 1
-        ser = ser + coeff[j]/x
     return -tmp + math.log(2.50662827465*ser)
----------------
coeff contains float numbers => float division


================
Comment at: lnt/external/stats/stats.py:1544
                       math.log(1.0-x))
-    if (x<(a+1.0)/(a+b+2.0)):
         return bt*betacf(a,b,x)/float(a)
----------------
Float operands in both numerator and denominator => float division


================
Comment at: lnt/external/stats/stats.py:1586
     msw = sswn/float(dfwn)
-    f = msb/msw
     prob = fprob(dfbn,dfwn,f)
----------------
Numerator and denominator formed from float division => float division


================
Comment at: lnt/external/stats/stats.py:1755
     ivec = range(n)
-    gap = n/2   # integer division needed
     while gap >0:
----------------
As per comment, n is return value from len so this is integer division


================
Comment at: lnt/external/stats/stats.py:1766
                     ivec[j+gap] = itemp
-        gap = gap / 2  # integer division needed
 # svec is now sorted inlist, and ivec has the order svec[i] = vec[ivec[i]]
----------------
gap initialized to integer (see above) => integer division


================
Comment at: lnt/external/stats/stats.py:2091
                 s = N.reshape(s,shp)
-    return size / s
 
----------------
- 1st outermost if: s is float from the reduce parameter => float division
- 2nd outermost if: size is float => float division
- outermost else:
   - 1st   2nd-level if: s initialized from float and is thus going to be a float at the end
   - 2nd-level else: s initialized from float with some entries replaced by float as well and potentially reshaped => float division

All cases are float division


================
Comment at: lnt/external/stats/stats.py:2132
             sum = N.reshape(sum,shp)
-    return sum/denom
 
----------------
Denom always a float or float array (outermost else) => float division.


================
Comment at: lnt/external/stats/stats.py:2174
     if inarray.shape[dimension] % 2 == 0:   # if even number of elements
-        indx = inarray.shape[dimension]/2   # integer division correct
         median = N.asarray(inarray[indx]+inarray[indx-1]) / 2.0
----------------
shape contains integer and result of division used for indexing => integer division


================
Comment at: lnt/external/stats/stats.py:2177
     else:
-        indx = inarray.shape[dimension] / 2 # integer division correct
         median = N.take(inarray,[indx],dimension)
----------------
Likewise, not sure why the indx assignment is not hoisted out of the if but anyway, this is a float division


================
Comment at: lnt/external/stats/stats.py:2241
      n = float(N.add.reduce(N.ravel(mask)))
-     return s/n
 
----------------
Obviously float division


================
Comment at: lnt/external/stats/stats.py:2359
      n = float(N.add.reduce(N.ravel(mask)))
-     return sd/math.sqrt(n)
 
----------------
sqrt => float division


================
Comment at: lnt/external/stats/stats.py:2416
     denom = denom + zero  # prevent divide-by-zero
-    return N.where(zero, 0, amoment(a,3,dimension)/denom)
 
----------------
denom initialized with something to the power 1.5 => float division


================
Comment at: lnt/external/stats/stats.py:2435
     denom = denom + zero  # prevent divide-by-zero
-    return N.where(zero,0,amoment(a,4,dimension)/denom)
 
----------------
amoment returns a float => float division


================
Comment at: lnt/external/stats/stats.py:2478-2479
     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) )
     W2 = -1 + N.sqrt(2*(beta2-1))
----------------
Both lines involve float literals => float division


================
Comment at: lnt/external/stats/stats.py:2481-2482
     W2 = -1 + N.sqrt(2*(beta2-1))
-    delta = 1/N.sqrt(N.log(N.sqrt(W2)))
-    alpha = N.sqrt(2/(W2-1))
     y = N.where(y==0,1,y)
----------------
Involve numpy's sqrt => float division


================
Comment at: lnt/external/stats/stats.py:2484
     y = N.where(y==0,1,y)
-    Z = delta*N.log(y/alpha + N.sqrt((y/alpha)**2+1))
     return Z, (1.0-zprob(Z))*2
----------------
alpha and delta produced by float division => float division


================
Comment at: lnt/external/stats/stats.py:2507
     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))/
----------------
Uses result of numpy's sqrt => float division


================
Comment at: lnt/external/stats/stats.py:2508-2509
-    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)))
     A = 6.0 + 8.0/sqrtbeta1 *(2.0/sqrtbeta1 + N.sqrt(1+4.0/(sqrtbeta1**2)))
----------------
numerator has a float literal => float division


================
Comment at: lnt/external/stats/stats.py:2511-2512
     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))
     denom = N.where(N.less(denom,0), 99, denom)
----------------
Float literals => float division


================
Comment at: lnt/external/stats/stats.py:2514
     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))
----------------
Numerator involves float division => float division


================
Comment at: lnt/external/stats/stats.py:2515
-    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))
     Z = N.where(N.equal(denom,99), 0, Z)
----------------
innermost division: float literal => float division
outermost division: numpy's sqrt => float division


================
Comment at: lnt/external/stats/stats.py:2753
     sd = stdev(instack,dimension)
-    return N.where(sd==0,0,m/sd)
 
----------------
mean returns a float so m is a float and thus this is a float division


================
Comment at: lnt/external/stats/stats.py:2857
         n = inarray.shape[dimension]
-    s = asamplestdev(inarray,dimension,keepdims) / N.sqrt(n-1)
     return s
----------------
sqrt denominator => float division


================
Comment at: lnt/external/stats/stats.py:2869
 """
-    z = (score-amean(a)) / asamplestdev(a)
     return z
----------------
amean returns a float => float division


================
Comment at: lnt/external/stats/stats.py:2896
     sstd = asamplestdev(compare,0)
-    return (scores - mns) / sstd
 
----------------
mns is the result of amean which is of type float => float division


================
Comment at: lnt/external/stats/stats.py:2985
     V = N.diagonal(C)
-    return C / N.sqrt(N.multiply.outer(V,V))
 
----------------
denominator = numpy's sqrt => float division


================
Comment at: lnt/external/stats/stats.py:3064
     total = float(len(x) + len(y))
-    return 2*common/total
 
----------------
total is float => float division


================
Comment at: lnt/external/stats/stats.py:3087-3091
-    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)
----------------
withindf and betwdf are float => withinms and betweenms use float division => rho, t and prob use float division


================
Comment at: lnt/external/stats/stats.py:3107
     yvar = avar(y)*(len(y)-1)/float(len(y))  # correct denom to n
-    lincc = (2 * covar) / ((xvar+yvar) +((amean(x)-amean(y))**2))
     return lincc
----------------
covar is the result of float division => float division


================
Comment at: lnt/external/stats/stats.py:3125
     r_den = math.sqrt((n*ass(x) - asquare_of_sums(x))*(n*ass(y)-asquare_of_sums(y)))
-    r = (r_num / r_den)
     df = n-2
----------------
r_den is the result of sqrt => float division


================
Comment at: lnt/external/stats/stats.py:3127-3128
     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)
     return r,prob
----------------
Division on 1st line involves float literals => float division
Division on 2nd line involves t which involves sqrt => float division


================
Comment at: lnt/external/stats/stats.py:3146
     rs = 1 - 6*dsq / float(n*(n**2-1))
-    t = rs * math.sqrt((n-2) / ((rs+1.0)*(1.0-rs)))
     df = n-2
----------------
Involves float literals => float division


================
Comment at: lnt/external/stats/stats.py:3148
     df = n-2
-    probrs = abetai(0.5*df,0.5,df/(df+t*t))
 # probability values for rs are from part 2 of the spearman function in
----------------
involves t which involves sqrt => float division


================
Comment at: lnt/external/stats/stats.py:3177
         adjust = math.sqrt((len(x)/float(n))*(len(y)/float(n)))
-        rpb = (ymean - xmean)/asamplestdev(pstat.acolex(data,1))*adjust
         df = n-2
----------------
numerator's operands are the result of amean, thus float => float division


================
Comment at: lnt/external/stats/stats.py:3179-3180
         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))
         return rpb, prob
----------------
1st line: float literals => float division
2nd line: t involves sqrt, thus float => float division


================
Comment at: lnt/external/stats/stats.py:3212-3214
-    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)
----------------
involves sqrt or float iterals => float division


================
Comment at: lnt/external/stats/stats.py:3245-3246
     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))
     df = n-2
----------------
1st line: r_den involves sqrt => float division
2nd line: float literals => float division


================
Comment at: lnt/external/stats/stats.py:3248-3250
-    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))
----------------
1st line: involves float literals => float division
2nd line: involves t which involves sqrt => float division
3rd line: involves float value => float division


================
Comment at: lnt/external/stats/stats.py:3286
     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 = N.where(zerodivproblem,0.0,r)
----------------
x & y are made of floats => r_num is float => float division


================
Comment at: lnt/external/stats/stats.py:3288
     r = N.where(zerodivproblem,0.0,r)
-    z = 0.5*N.log((1.0+r+TINY)/(1.0-r+TINY))
     df = n-2
----------------
float literals => float division


================
Comment at: lnt/external/stats/stats.py:3290-3291
     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))
 
----------------
1st line: float literals => float division
2nd line: t involves sqrt and thus float => float division


================
Comment at: lnt/external/stats/stats.py:3295
     s_den = N.where(ss==0,1,ss)  # avoid zero-division in 1st place
-    slope = r_num / s_den
     intercept = ymean - slope*xmean
----------------
r_num is float as per above => float division


================
Comment at: lnt/external/stats/stats.py:3322-3323
     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))
 
----------------
1st line: involves sqrt => float division
2nd line: involves result from 1st line => float division


================
Comment at: lnt/external/stats/stats.py:3362
     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 = N.where(zerodivproblem,1.0,t)     # replace NaN/wrong t-values with 1.0
----------------
Involves numpy's sqrt => float division


================
Comment at: lnt/external/stats/stats.py:3408
         prob = abetai(0.5*df,0.5,float(df)/(df+t*t))
-        step = step/2
     print()
----------------
step is made of floats => float division


================
Comment at: lnt/external/stats/stats.py:3443
 
-    denom = N.sqrt((n*N.add.reduce(d*d,dimension) - N.add.reduce(d,dimension)**2) /df)
     zerodivproblem = N.equal(denom,0)
----------------
df is float => float division


================
Comment at: lnt/external/stats/stats.py:3446
     denom = N.where(zerodivproblem,1,denom)  # avoid zero-division in 1st place
-    t = 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
----------------
denom is either 1 or float values from earlier float division and when it is 1 it is substituted by 1.0 below => float division gives same result


================
Comment at: lnt/external/stats/stats.py:3481
     f_exp = f_exp.astype(N.float_)
-    chisq = N.add.reduce((f_obs-f_exp)**2 / f_exp)
     return chisq, achisqprob(chisq, k-1)
----------------
f_exp is float => float division


================
Comment at: lnt/external/stats/stats.py:3549
     sd = math.sqrt(T*n1*n2*(n1+n2+1)/12.0)
-    z = abs((bigu-n1*n2/2.0) / sd)  # normal approximation for prob calc
     return smallu, 1.0 - azprob(z)
----------------
nominator involves float literals => float division


================
Comment at: lnt/external/stats/stats.py:3595
     expected = n1*(n1+n2+1) / 2.0
-    z = (s - expected) / math.sqrt(n1*n2*(n1+n2+1)/12.0)
     prob = 2*(1.0 - azprob(abs(z)))
----------------
sqrt => float division


================
Comment at: lnt/external/stats/stats.py:3625-3626
     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
     prob = 2*(1.0 -zprob(abs(z)))
----------------
se is result from sqrt => float division


================
Comment at: lnt/external/stats/stats.py:3763
         while asum(mask) != totalelements:
-            e = e * (a/z.astype(N.float_))
             c = c + e
----------------
z cast to float => float division


================
Comment at: lnt/server/db/rules/rule_update_profile_stats.py:38
         mtime = os.stat(f).st_mtime
-        sz = os.stat(f).st_size / 1000
         age.append([mtime, sz])
----------------
st_size being the size of f in bytes, it is an integer and thus this computes the floor.


================
Comment at: lnt/server/reporting/analysis.py:83
             if value != 0:
-                self.pct_delta = self.delta / value
             self.previous = value
----------------
This is float division:

    the only construction of ComparisonResult (the type of self) that can be the source of pct_delta uses in LNT seems to have samples and prev_samples (and thus ultimately self.delta and value) made of floats (samples or result of calling calc_geomean)
    the only uses of pct_delta are by flask (e.g. lnt/server/ui/templates/v4_global_status.html) and max, both of which are happy with float values
    pct_delta is set to 0.0 when the condition of the outermost "if" is false



================
Comment at: lnt/server/reporting/dailyreport.py:49
             for query_param, value in (
-                ("day_start", self.day_start_offset.seconds / 3600),
                 ("num_days", self.num_prior_days_to_include),
----------------
day_start_offset is of type datetime.timedelta whose second attribute is an integer, therefore this is computing the floor.


================
Comment at: lnt/server/reporting/summaryreport.py:50
     def getvalue(self):
-        return [value/self.count for value in self.sum]
 
----------------
self.sum elements are initialized by 0. in _initialize and only ever changed by adding a value to it. Therfore this is float division.


================
Comment at: lnt/server/reporting/summaryreport.py:68
     def getvalue(self):
-        return [value ** 1.0/self.count for value in self.product]
 
----------------
value ** 1.0 will yield a float, so this is clearly float division.


================
Comment at: lnt/server/reporting/summaryreport.py:85
         baseline = values[0]
-        Mean._append(self, [v/baseline
                             for v in values])
----------------
While uses of NormalizedMean seems have values all come from calling lnt.util.stats.median and thus be integer, this makes more sense to be a float division because:

    Mean._append uses the list elements in a float addition as explained above;
    the same data that gets appended to NormalizedMean also gets appended to Mean in some cases

This suggests that the intent is to have float division.


================
Comment at: lnt/server/reporting/summaryreport.py:505
                 items.append(('Single File Tests', arch,
-                              [v/baseline for v in values]))
----------------
values is constructed by calling getvalue and all aggregation functions have their value of type float. This is therefore a float division


================
Comment at: lnt/server/ui/util.py:15-19
 def safediv(a, b, default=None):
     try:
-        return a / b
+        return old_div(a, b)
     except ZeroDivisionError:
         return default
----------------
No use of safediv remains in LNT so this gets deleted in a separate patch.


================
Comment at: lnt/server/ui/util.py:73
 def mean(values):
-    return sum(values) / len(values)
 
----------------
This method is only referenced 3 times, all in lnt/server/ui/views.py where in all cases it ends up being called with data which can be either integer or float AFAIK ("column" field of SampleField):
- called once directly to fill the derived_stat attribute of the MatrixDataRequest which is not used anywhere
- as an aggregate function when constructing a ComparisonResult that is being used in get_cell_value macro in lnt/server/ui/templates/v4_matrix.html by printing it with the %.4f specifier

It should therefore be consider float division, which makes sense for a mean.


================
Comment at: lnt/server/ui/util.py:315
         self.delta = new - old
-        self.pct_delta = self.delta / old
 
----------------
Like for ComparisonResult. all uses of pct_delta are fine with float and the initialization of pct_delta above suggest this is the intent.


================
Comment at: lnt/server/ui/views.py:981
                 continue
-            mean = sum(samples)/len(samples)
             # Darken the baseline color distinguish from non-baselines.
----------------
values in samples comes from the column field of SampleField which it appears can be either integer or float. However this should be made a float division unconditionally IMHO. mean is used to mark the baseline line on the graph via the markings attribute of the grid attribute of the plot options passed to JQuery flot's plot function. This seems to be fine as a floating-point value and being a mean seems more sensible to be a floating-point value.


================
Comment at: lnt/server/ui/views.py:985
             color_offset = float(baseline_id) / num_baselines / 2
-            my_color = (i + color_offset) / num_plots
             dark_col = list(util.makeDarkerColor(my_color))
----------------
color_offset is float so this is float division.


================
Comment at: lnt/server/ui/views.py:1153
             try:
-                norm_xs = [(x - x_min) / (x_max - x_min)
                            for x in xs]
----------------
x iterate over elements of xs which is built from the first element in each tuple composing pts, which in turns is built by calling determine_x_value. Since that method return a float, this is a float division.


================
Comment at: lnt/server/ui/views.py:1898
     """This route is going to exception. Used for testing 500 page."""
-    return 1/0
 
----------------
Both floor and float divisions behave the same so choosing to keep the existing code to minimize the diff.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67821/new/

https://reviews.llvm.org/D67821





More information about the llvm-commits mailing list