提交 87d0ddc3 authored 作者: Olivier Delalleau's avatar Olivier Delalleau

zip -> izip

上级 3825925b
...@@ -15,6 +15,7 @@ __contact__ = "Razvan Pascanu <r.pascanu@gmail>" ...@@ -15,6 +15,7 @@ __contact__ = "Razvan Pascanu <r.pascanu@gmail>"
import copy import copy
import logging import logging
from itertools import izip
import numpy import numpy
...@@ -291,7 +292,7 @@ def equal_computations(xs, ys, in_xs=None, in_ys=None): ...@@ -291,7 +292,7 @@ def equal_computations(xs, ys, in_xs=None, in_ys=None):
if in_ys is None: if in_ys is None:
in_ys = [] in_ys = []
for x, y in zip(xs, ys): for x, y in izip(xs, ys):
if x.owner and not y.owner: if x.owner and not y.owner:
return False return False
if y.owner and not x.owner: if y.owner and not x.owner:
...@@ -301,7 +302,7 @@ def equal_computations(xs, ys, in_xs=None, in_ys=None): ...@@ -301,7 +302,7 @@ def equal_computations(xs, ys, in_xs=None, in_ys=None):
return False return False
if len(in_xs) != len(in_ys): if len(in_xs) != len(in_ys):
return False return False
for _x, _y in zip(in_xs, in_ys): for _x, _y in izip(in_xs, in_ys):
if _x.type != _y.type: if _x.type != _y.type:
return False return False
...@@ -313,7 +314,7 @@ def equal_computations(xs, ys, in_xs=None, in_ys=None): ...@@ -313,7 +314,7 @@ def equal_computations(xs, ys, in_xs=None, in_ys=None):
n_nodes = len(nds_x) n_nodes = len(nds_x)
cont = True cont = True
idx = 0 idx = 0
for dx, dy in zip(xs, ys): for dx, dy in izip(xs, ys):
if not dx.owner or not dy.owner: if not dx.owner or not dy.owner:
if dy.owner or dx.owner: if dy.owner or dx.owner:
return False return False
...@@ -338,7 +339,7 @@ def equal_computations(xs, ys, in_xs=None, in_ys=None): ...@@ -338,7 +339,7 @@ def equal_computations(xs, ys, in_xs=None, in_ys=None):
elif len(nd_x.outputs) != len(nd_y.outputs): elif len(nd_x.outputs) != len(nd_y.outputs):
cont = False cont = False
else: else:
for dx, dy in zip(nd_x.inputs, nd_y.inputs): for dx, dy in izip(nd_x.inputs, nd_y.inputs):
if (dx, dy) not in common: if (dx, dy) not in common:
if dx != dy: if dx != dy:
if (isinstance(dx, tensor.Constant) and if (isinstance(dx, tensor.Constant) and
...@@ -353,7 +354,7 @@ def equal_computations(xs, ys, in_xs=None, in_ys=None): ...@@ -353,7 +354,7 @@ def equal_computations(xs, ys, in_xs=None, in_ys=None):
cont = False cont = False
if cont: if cont:
for dx, dy in zip(nd_x.outputs, nd_y.outputs): for dx, dy in izip(nd_x.outputs, nd_y.outputs):
common.add((dx, dy)) common.add((dx, dy))
idx += 1 idx += 1
...@@ -372,7 +373,7 @@ def infer_shape(outs, inputs, input_shapes): ...@@ -372,7 +373,7 @@ def infer_shape(outs, inputs, input_shapes):
# inside. We don't use the full ShapeFeature interface, but we # inside. We don't use the full ShapeFeature interface, but we
# let it initialize itself with an empty env, otherwise we will # let it initialize itself with an empty env, otherwise we will
# need to do it manually # need to do it manually
for inp, inp_shp in zip(inputs, input_shapes): for inp, inp_shp in izip(inputs, input_shapes):
if inp_shp is not None and len(inp_shp) != inp.ndim: if inp_shp is not None and len(inp_shp) != inp.ndim:
assert len(inp_shp) == inp.ndim assert len(inp_shp) == inp.ndim
...@@ -380,7 +381,7 @@ def infer_shape(outs, inputs, input_shapes): ...@@ -380,7 +381,7 @@ def infer_shape(outs, inputs, input_shapes):
shape_feature.on_attach(theano.gof.Env([], [])) shape_feature.on_attach(theano.gof.Env([], []))
# Initialize shape_of with the input shapes # Initialize shape_of with the input shapes
for inp, inp_shp in zip(inputs, input_shapes): for inp, inp_shp in izip(inputs, input_shapes):
shape_feature.set_shape(inp, inp_shp) shape_feature.set_shape(inp, inp_shp)
def local_traverse(out): def local_traverse(out):
...@@ -689,7 +690,7 @@ def reconstruct_graph(inputs, outputs, tag=None): ...@@ -689,7 +690,7 @@ def reconstruct_graph(inputs, outputs, tag=None):
tag = '' tag = ''
nw_inputs = [safe_new(x, tag) for x in inputs] nw_inputs = [safe_new(x, tag) for x in inputs]
givens = {} givens = {}
for nw_x, x in zip(nw_inputs, inputs): for nw_x, x in izip(nw_inputs, inputs):
givens[x] = nw_x givens[x] = nw_x
allinputs = theano.gof.graph.inputs(outputs) allinputs = theano.gof.graph.inputs(outputs)
for inp in allinputs: for inp in allinputs:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论