提交 691bfddf authored 作者: Razvan Pascanu's avatar Razvan Pascanu

Revised version of optimization to remove useless subtensors. Enhanced to

include the length of the tensor as possible ``stop`` for a useless subtensor.
上级 0958ff90
......@@ -1095,13 +1095,22 @@ def local_useless_subtensor(node):
"""
Remove Subtensor if it take the full input
"""
if (isinstance(node.op, T.Subtensor) and
all([isinstance(idx, slice) and
idx.start in [0, None] and
idx.stop in [sys.maxint, None]
and idx.step in [1, None] for idx in node.op.idx_list])):
x = node.inputs[0]
return [x]
shape_of = node.env.shape_feature.shape_of
if isinstance(node.op, T.Subtensor):
for pos, idx in enumerate(node.op.idx_list):
try:
length_pos = shape_i(node.inputs[0])[pos]
except:
length_pos = None
if ( isinstance(idx,slice) and
idx.start in [0,None] and
idx.step in [1,None] and
idx.stop in [sys.maxint, None, length_pos]):
pass
else:
return False
return [node.inputs[0]]
@register_canonicalize
@gof.local_optimizer([])
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论