diff options
author | Thomas Preud'homme <thomasp@graphcore.ai> | 2019-09-25 07:58:52 +0000 |
---|---|---|
committer | Thomas Preud'homme <thomasp@graphcore.ai> | 2019-09-25 07:58:52 +0000 |
commit | 99f5df118a790da133f33965cc5f6590285b8b39 (patch) | |
tree | 6b2aae36524d2d263a84a57c833de2d02da3f5da | |
parent | 65d5ffa9872da4a2800fe3ec098b084363321c60 (diff) |
[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
git-svn-id: https://llvm.org/svn/llvm-project/lnt/trunk@372821 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lnt/external/stats/pstat.py | 21 | ||||
-rw-r--r-- | lnt/external/stats/stats.py | 32 | ||||
-rw-r--r-- | lnt/server/ui/views.py | 2 | ||||
-rw-r--r-- | lnt/testing/__init__.py | 2 | ||||
-rw-r--r-- | lnt/testing/util/valgrind.py | 4 | ||||
-rw-r--r-- | lnt/tests/nt.py | 2 |
6 files changed, 24 insertions, 39 deletions
diff --git a/lnt/external/stats/pstat.py b/lnt/external/stats/pstat.py index 2beb130..46237f4 100644 --- a/lnt/external/stats/pstat.py +++ b/lnt/external/stats/pstat.py @@ -216,16 +216,16 @@ Returns: a list-of-lists corresponding to the columns from listoflists 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',listoflists). 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 containing 1s where the two rows had """ 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 diff --git a/lnt/external/stats/stats.py b/lnt/external/stats/stats.py index baa4a89..89ecf9d 100644 --- a/lnt/external/stats/stats.py +++ b/lnt/external/stats/stats.py @@ -842,8 +842,8 @@ Returns: Pearson's r value, two-tailed p-value 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 prob, sterr-of-estimate 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 probability estimate 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), associated p-value 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 *lists is any number of lists, one per 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), associated p-value 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 *args is 2 or more arrays, one per 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)) diff --git a/lnt/server/ui/views.py b/lnt/server/ui/views.py index a94577a..40a7786 100644 --- a/lnt/server/ui/views.py +++ b/lnt/server/ui/views.py @@ -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 diff --git a/lnt/testing/__init__.py b/lnt/testing/__init__.py index 5161eb4..f82eb7f 100644 --- a/lnt/testing/__init__.py +++ b/lnt/testing/__init__.py @@ -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 diff --git a/lnt/testing/util/valgrind.py b/lnt/testing/util/valgrind.py index 65e7c71..51414be 100644 --- a/lnt/testing/util/valgrind.py +++ b/lnt/testing/util/valgrind.py @@ -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") diff --git a/lnt/tests/nt.py b/lnt/tests/nt.py index 3eac505..cf4d634 100644 --- a/lnt/tests/nt.py +++ b/lnt/tests/nt.py @@ -1305,7 +1305,7 @@ def _execute_test_again(config, test_name, test_path, test_relative_path, 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. |