From 560950466d63eaa7b78d8a8215bdb8f5e228b818 Mon Sep 17 00:00:00 2001 From: Mike Croucher Date: Sun, 1 Mar 2015 09:24:22 +0000 Subject: [PATCH] itertools fixes from 2to3 --- GPy/core/model.py | 2 +- GPy/core/parameterization/param.py | 14 +++++++------- GPy/core/parameterization/parameterized.py | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/GPy/core/model.py b/GPy/core/model.py index 08a4ea25..9521733c 100644 --- a/GPy/core/model.py +++ b/GPy/core/model.py @@ -364,7 +364,7 @@ class Model(Parameterized): gradient = self._grads(x).copy() np.where(gradient == 0, 1e-312, gradient) ret = True - for nind, xind in itertools.izip(param_index, transformed_index): + for nind, xind in zip(param_index, transformed_index): xx = x.copy() xx[xind] += step f1 = self._objective(xx) diff --git a/GPy/core/parameterization/param.py b/GPy/core/parameterization/param.py index fbbb59ed..c7e76c98 100644 --- a/GPy/core/parameterization/param.py +++ b/GPy/core/parameterization/param.py @@ -279,7 +279,7 @@ class Param(Parameterizable, ObsAr): .tg th{font-family:"Courier New", Courier, monospace !important;font-weight:normal;color:#fff;background-color:#26ADE4;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:#DCDCDC;} .tg .tg-left{font-family:"Courier New", Courier, monospace !important;font-weight:normal;text-align:left;} .tg .tg-right{font-family:"Courier New", Courier, monospace !important;font-weight:normal;text-align:right;} -"""] + [''] + [header] + ["".format(x=x, c=" ".join(map(str, c)), p=" ".join(map(str, p)), t=(t or ''), i=i) for i, x, c, t, p in itertools.izip(indices, vals, constr_matrix, ties, prirs)] + ["
{i}{x}{c}{p}{t}
"]) +"""] + [''] + [header] + ["".format(x=x, c=" ".join(map(str, c)), p=" ".join(map(str, p)), t=(t or ''), i=i) for i, x, c, t, p in zip(indices, vals, constr_matrix, ties, prirs)] + ["
{i}{x}{c}{p}{t}
"]) def __str__(self, constr_matrix=None, indices=None, prirs=None, ties=None, lc=None, lx=None, li=None, lp=None, lt=None, only_name=False): filter_ = self._current_slice_ @@ -300,7 +300,7 @@ class Param(Parameterizable, ObsAr): if only_name: header = header_format.format(lc, lx, li, lt, lp, ' ', x=self.hierarchy_name(), c=sep*lc, i=sep*li, t=sep*lt, p=sep*lp) # nice header for printing else: header = header_format.format(lc, lx, li, lt, lp, ' ', x=self.hierarchy_name(), c=__constraints_name__, i=__index_name__, t=__tie_name__, p=__priors_name__) # nice header for printing if not ties: ties = itertools.cycle(['']) - return "\n".join([header] + [" {i!s:^{3}s} | {x: >{1}.{2}g} | {c:^{0}s} | {p:^{5}s} | {t:^{4}s} ".format(lc, lx, __precision__, li, lt, lp, x=x, c=" ".join(map(str, c)), p=" ".join(map(str, p)), t=(t or ''), i=i) for i, x, c, t, p in itertools.izip(indices, vals, constr_matrix, ties, prirs)]) # return all the constraints with right indices + return "\n".join([header] + [" {i!s:^{3}s} | {x: >{1}.{2}g} | {c:^{0}s} | {p:^{5}s} | {t:^{4}s} ".format(lc, lx, __precision__, li, lt, lp, x=x, c=" ".join(map(str, c)), p=" ".join(map(str, p)), t=(t or ''), i=i) for i, x, c, t, p in zip(indices, vals, constr_matrix, ties, prirs)]) # return all the constraints with right indices # except: return super(Param, self).__str__() class ParamConcatenation(object): @@ -429,14 +429,14 @@ class ParamConcatenation(object): params = self.params constr_matrices, ties_matrices, prior_matrices = zip(*map(f, params)) indices = [p._indices() for p in params] - lc = max([p._max_len_names(cm, __constraints_name__) for p, cm in itertools.izip(params, constr_matrices)]) + lc = max([p._max_len_names(cm, __constraints_name__) for p, cm in zip(params, constr_matrices)]) lx = max([p._max_len_values() for p in params]) - li = max([p._max_len_index(i) for p, i in itertools.izip(params, indices)]) - lt = max([p._max_len_names(tm, __tie_name__) for p, tm in itertools.izip(params, ties_matrices)]) - lp = max([p._max_len_names(pm, __constraints_name__) for p, pm in itertools.izip(params, prior_matrices)]) + li = max([p._max_len_index(i) for p, i in zip(params, indices)]) + lt = max([p._max_len_names(tm, __tie_name__) for p, tm in zip(params, ties_matrices)]) + lp = max([p._max_len_names(pm, __constraints_name__) for p, pm in zip(params, prior_matrices)]) strings = [] start = True - for p, cm, i, tm, pm in itertools.izip(params,constr_matrices,indices,ties_matrices,prior_matrices): + for p, cm, i, tm, pm in zip(params,constr_matrices,indices,ties_matrices,prior_matrices): strings.append(p.__str__(constr_matrix=cm, indices=i, prirs=pm, ties=tm, lc=lc, lx=lx, li=li, lp=lp, lt=lt, only_name=(1-start))) start = False return "\n".join(strings) diff --git a/GPy/core/parameterization/parameterized.py b/GPy/core/parameterization/parameterized.py index db945016..27ecbc1c 100644 --- a/GPy/core/parameterization/parameterized.py +++ b/GPy/core/parameterization/parameterized.py @@ -269,7 +269,7 @@ class Parameterized(Parameterizable,metaclass=ParametersChangedMeta): """ if not isinstance(regexp, _pattern_type): regexp = compile(regexp) found_params = [] - for n, p in itertools.izip(self.parameter_names(False, False, True), self.flattened_parameters): + for n, p in zip(self.parameter_names(False, False, True), self.flattened_parameters): if regexp.match(n) is not None: found_params.append(p) return found_params @@ -380,7 +380,7 @@ class Parameterized(Parameterizable,metaclass=ParametersChangedMeta): pl = max([len(str(x)) if x else 0 for x in prirs + ["Prior"]]) format_spec = "{{name:<{0}s}}{{desc:>{1}s}}{{const:^{2}s}}{{pri:^{3}s}}{{t:^{4}s}}".format(nl, sl, cl, pl, tl) to_print = [] - for n, d, c, t, p in itertools.izip(names, desc, constrs, ts, prirs): + for n, d, c, t, p in zip(names, desc, constrs, ts, prirs): to_print.append(format_spec.format(name=n, desc=d, const=c, t=t, pri=p)) sep = '-' * (nl + sl + cl + + pl + tl + 8 * 2 + 3) if header: @@ -415,7 +415,7 @@ class Parameterized(Parameterizable,metaclass=ParametersChangedMeta): pl = max([len(str(x)) if x else 0 for x in prirs + ["Prior"]]) format_spec = " \033[1m{{name:<{0}s}}\033[0;0m | {{desc:>{1}s}} | {{const:^{2}s}} | {{pri:^{3}s}} | {{t:^{4}s}}".format(nl, sl, cl, pl, tl) to_print = [] - for n, d, c, t, p in itertools.izip(names, desc, constrs, ts, prirs): + for n, d, c, t, p in zip(names, desc, constrs, ts, prirs): to_print.append(format_spec.format(name=n, desc=d, const=c, t=t, pri=p)) sep = '-' * (nl + sl + cl + + pl + tl + 8 * 2 + 3) if header: