[LNT] r372821 - [LNT] Python 3 support: adapt to map returning an iterator

Thomas Preud'homme via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 25 00:58:52 PDT 2019


Author: thopre
Date: Wed Sep 25 00:58:52 2019
New Revision: 372821

URL: http://llvm.org/viewvc/llvm-project?rev=372821&view=rev
Log:
[LNT] Python 3 support: adapt to map returning an iterator

Adapt calls to map() to the fact it returns an iterator in Python 3 when
necessary. This was produced by running futurize's stage2
lib2to3.fixes.fix_map, with manual clean up to remove unecessary list
wrapping and simplify the code.

Reviewers: cmatthews, hubert.reinterpretcast, kristof.beyls

Reviewed By: hubert.reinterpretcast

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D67817

Modified:
    lnt/trunk/lnt/external/stats/pstat.py
    lnt/trunk/lnt/external/stats/stats.py
    lnt/trunk/lnt/server/ui/views.py
    lnt/trunk/lnt/testing/__init__.py
    lnt/trunk/lnt/testing/util/valgrind.py
    lnt/trunk/lnt/tests/nt.py

Modified: lnt/trunk/lnt/external/stats/pstat.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/external/stats/pstat.py?rev=372821&r1=372820&r2=372821&view=diff
==============================================================================
--- lnt/trunk/lnt/external/stats/pstat.py (original)
+++ lnt/trunk/lnt/external/stats/pstat.py Wed Sep 25 00:58:52 2019
@@ -216,16 +216,16 @@ Returns: a list-of-lists corresponding t
     column = 0
     if isinstance(cnums, (list, tuple)):   # if multiple columns to get
         index = cnums[0]
-        column = map(lambda x: x[index], listoflists)
+        column = [x[index] for x in listoflists]
         for col in cnums[1:]:
             index = col
-            column = abut(column,map(lambda x: x[index], listoflists))
+            column = abut(column, [x[index] for x in listoflists])
     elif isinstance(cnums, str):              # if an 'x[3:]' type expr.
-        evalstring = 'map(lambda x: x'+cnums+', listoflists)'
+        evalstring = 'list(map(lambda x: x'+cnums+', listoflists))'
         column = eval(evalstring)
     else:                                     # else it's just 1 col to get
         index = cnums
-        column = map(lambda x: x[index], listoflists)
+        column = [x[index] for x in listoflists]
     return column
 
 
@@ -463,8 +463,8 @@ the string.join function.
 Usage:   list2string (inlist,delimit=' ')
 Returns: the string created from inlist
 """
-    stringlist = map(makestr,inlist)
-    return string.join(stringlist,delimit)
+    stringlist = map(makestr, inlist)
+    return delimit.join(stringlist)
 
 
 def makelol(inlist):
@@ -510,8 +510,7 @@ Returns: None
     maxsize = [0]*len(list2print[0])
     for col in range(len(list2print[0])):
         items = colex(list2print,col)
-        items = map(makestr,items)
-        maxsize[col] = max(map(len,items)) + extra
+        maxsize[col] = max(map(lambda item: len(makestr(item)), items)) + extra
     for row in lst:
         if row == ['\n'] or row == '\n' or row == '' or row == ['']:
             print()
@@ -614,7 +613,7 @@ returned ... map(lambda x: 'criterion',l
 Usage:   remap(listoflists,criterion)    criterion=string
 Returns: remapped version of listoflists
 """
-    function = 'map(lambda x: '+criterion+',listoflists)'
+    function = 'list(map(lambda x: '+criterion+',listoflists))'
     lines = eval(function)
     return lines
 
@@ -963,7 +962,7 @@ Returns: an array of equal length contai
 """
     return 
     if row1.dtype.char=='O' or row2.dtype=='O':
-        cmpvect = N.logical_not(abs(N.array(map(cmp,row1,row2)))) # cmp fcn gives -1,0,1
+        cmpvect = N.logical_not(abs(N.array(list(map(cmp, row1, row2))))) # cmp fcn gives -1,0,1
     else:
         cmpvect = N.equal(row1,row2)
     return cmpvect
@@ -1023,7 +1022,7 @@ Usage:   aunique (inarray)
             for item in inarray[1:]:
                 newflag = 1
                 for unq in uniques:  # NOTE: cmp --> 0=same, -1=<, 1=>
-                    test = N.sum(abs(N.array(map(cmp,item,unq))))
+                    test = N.sum(abs(N.array(list(map(cmp, item, unq)))))
                     if test == 0:   # if item identical to any 1 row in uniques
                         newflag = 0 # then not a novel item to add
                         break

Modified: lnt/trunk/lnt/external/stats/stats.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/external/stats/stats.py?rev=372821&r1=372820&r2=372821&view=diff
==============================================================================
--- lnt/trunk/lnt/external/stats/stats.py (original)
+++ lnt/trunk/lnt/external/stats/stats.py Wed Sep 25 00:58:52 2019
@@ -842,8 +842,8 @@ Returns: Pearson's r value, two-tailed p
     if len(x) != len(y):
         raise ValueError('Input values not paired in pearsonr.  Aborting.')
     n = len(x)
-    x = map(float,x)
-    y = map(float,y)
+    x = list(map(float, x))
+    y = list(map(float, y))
     xmean = mean(x)
     ymean = mean(y)
     r_num = n*(summult(x,y)) - sum(x)*sum(y)
@@ -971,8 +971,8 @@ Returns: slope, intercept, r, two-tailed
     if len(x) != len(y):
         raise ValueError('Input values not paired in linregress.  Aborting.')
     n = len(x)
-    x = map(float,x)
-    y = map(float,y)
+    x = list(map(float, x))
+    y = list(map(float, y))
     xmean = mean(x)
     ymean = mean(y)
     r_num = float(n*(summult(x,y)) - sum(x)*sum(y))
@@ -1235,7 +1235,7 @@ Returns: a t-statistic, two-tail probabi
         if diff != 0:
             d.append(diff)
     count = len(d)
-    absd = map(abs,d)
+    absd = list(map(abs, d))
     absranked = rankdata(absd)
     r_plus = 0.0
     r_minus = 0.0
@@ -1265,7 +1265,7 @@ Returns: H-statistic (corrected for ties
     args = list(args)
     n = [0]*len(args)
     all = []
-    n = map(len,args)
+    n = list(map(len, args))
     for i in range(len(args)):
         all = all + args[i]
     ranked = rankdata(all)
@@ -1562,14 +1562,7 @@ Usage:   F_oneway(*lists)    where *list
 Returns: F value, one-tailed p-value
 """
     a = len(lists)           # ANOVA on 'a' groups, each in it's own list
-    means = [0]*a
-    vars = [0]*a
-    ns = [0]*a
     alldata = []
-    tmp = map(N.array,lists)
-    means = map(amean,tmp)
-    vars = map(avar,tmp)
-    ns = map(len,lists)
     for i in range(len(lists)):
         alldata = alldata + lists[i]
     alldata = N.array(alldata)
@@ -1629,8 +1622,8 @@ Returns: None
     maxsize = [0]*len(list2print[0])
     for col in range(len(list2print[0])):
         items = pstat.colex(list2print,col)
-        items = map(pstat.makestr,items)
-        maxsize[col] = max(map(len,items)) + extra
+        maxsize[col] = (max(map(lambda item: len(pstat.makestr(item)), items))
+                        + extra)
     for row in listoflists:
         if row == ['\n'] or row == '\n':
             outfile.write('\n')
@@ -3640,7 +3633,7 @@ Returns: H-statistic (corrected for ties
     assert len(args) == 3, "Need at least 3 groups in stats.akruskalwallish()"
     args = list(args)
     n = [0]*len(args)
-    n = map(len,args)
+    n = list(map(len, args))
     all = []
     for i in range(len(args)):
         all = all + args[i].tolist()
@@ -4045,14 +4038,7 @@ Usage:   aF_oneway (*args)    where *arg
 Returns: f-value, probability
 """
     na = len(args)            # ANOVA on 'na' groups, each in it's own array
-    means = [0]*na
-    vars = [0]*na
-    ns = [0]*na
     alldata = []
-    tmp = map(N.array,args)
-    means = map(amean,tmp)
-    vars = map(avar,tmp)
-    ns = map(len,args)
     alldata = N.concatenate(args)
     bign = len(alldata)
     sstot = ass(alldata)-(asquare_of_sums(alldata)/float(bign))

Modified: lnt/trunk/lnt/server/ui/views.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/server/ui/views.py?rev=372821&r1=372820&r2=372821&view=diff
==============================================================================
--- lnt/trunk/lnt/server/ui/views.py (original)
+++ lnt/trunk/lnt/server/ui/views.py Wed Sep 25 00:58:52 2019
@@ -1330,7 +1330,7 @@ def v4_global_status():
     def get_machine_keys(m):
         m.css_name = m.name.replace('.', '-')
         return m
-    recent_machines = map(get_machine_keys, recent_machines)
+    recent_machines = list(map(get_machine_keys, recent_machines))
 
     # For each machine, build a table of the machine, the baseline run, and the
     # most recent run. We also computed a list of all the runs we are reporting

Modified: lnt/trunk/lnt/testing/__init__.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/testing/__init__.py?rev=372821&r1=372820&r2=372821&view=diff
==============================================================================
--- lnt/trunk/lnt/testing/__init__.py (original)
+++ lnt/trunk/lnt/testing/__init__.py Wed Sep 25 00:58:52 2019
@@ -380,7 +380,7 @@ class MetricSamples:
         """Add samples for this metric, converted to float by calling
         function conv_f.
         """
-        self.data.extend(list(map(conv_f, new_samples)))
+        self.data.extend(map(conv_f, new_samples))
 
     def render(self):
         """Return info from this instance in a dictionary that respects

Modified: lnt/trunk/lnt/testing/util/valgrind.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/testing/util/valgrind.py?rev=372821&r1=372820&r2=372821&view=diff
==============================================================================
--- lnt/trunk/lnt/testing/util/valgrind.py (original)
+++ lnt/trunk/lnt/testing/util/valgrind.py Wed Sep 25 00:58:52 2019
@@ -74,7 +74,7 @@ class CalltreeData(object):
             # Check if this is the closing summary line.
             if ln.startswith('summary'):
                 key, value = ln.split(':', 1)
-                summary_samples = map(int, value.split())
+                summary_samples = list(map(int, value.split()))
                 break
 
             # Check if this is an update to the current file or function.
@@ -84,7 +84,7 @@ class CalltreeData(object):
                 current_function = ln[3:-1]
             else:
                 # Otherwise, this is a data record.
-                samples = map(int, ln.split())
+                samples = list(map(int, ln.split()))
                 if len(samples) != num_samples:
                     raise CalltreeParseError(
                         "invalid record line, unexpected sample count")

Modified: lnt/trunk/lnt/tests/nt.py
URL: http://llvm.org/viewvc/llvm-project/lnt/trunk/lnt/tests/nt.py?rev=372821&r1=372820&r2=372821&view=diff
==============================================================================
--- lnt/trunk/lnt/tests/nt.py (original)
+++ lnt/trunk/lnt/tests/nt.py Wed Sep 25 00:58:52 2019
@@ -1305,7 +1305,7 @@ def _execute_test_again(config, test_nam
 
 
 def _unix_quote_args(s):
-    return map(pipes.quote, shlex.split(s))
+    return list(map(pipes.quote, shlex.split(s)))
 
 
 # When set to true, all benchmarks will be rerun.




More information about the llvm-commits mailing list