提交 d4d91121 authored 作者: Frederic Bastien's avatar Frederic Bastien

call the Alloc instance don't return useless Alloc. This will be discussed in an…

call the Alloc instance don't return useless Alloc. This will be discussed in an email on the mailing list.
上级 ccb91d2b
...@@ -1848,6 +1848,17 @@ class Alloc(gof.Op): ...@@ -1848,6 +1848,17 @@ class Alloc(gof.Op):
def grad(self, inputs, (gout,)): def grad(self, inputs, (gout,)):
return [None for i in inputs] return [None for i in inputs]
def __call__(self, *inputs, **kwargs):
"""
Don't generate alloc that do nothing.
If you always want an Alloc node, call make_node.
"""
ret = super(Alloc,self).__call__(*inputs,**kwargs)
import pdb;pdb.set_trace()
if inputs[0].type == ret.type:
return inputs[0]
else: return ret
alloc = Alloc() alloc = Alloc()
pprint.assign(alloc, printing.FunctionPrinter('alloc')) pprint.assign(alloc, printing.FunctionPrinter('alloc'))
......
...@@ -757,8 +757,9 @@ def local_alloc_elemwise(node): ...@@ -757,8 +757,9 @@ def local_alloc_elemwise(node):
new = [] new = []
for i in node.inputs: for i in node.inputs:
if i.owner and isinstance(i.owner.op,T.Alloc): if i.owner and isinstance(i.owner.op,T.Alloc) and i.owner.inputs[0].type != i.owner.outputs[0].type:
#I suppose that alloc input must have the same shape as the output. #when i.owner.inputs[0].type == i.owner.outputs[0].type we will remove that alloc later
assert i.type.ndim == node.inputs[no_broad_idx].type.ndim assert i.type.ndim == node.inputs[no_broad_idx].type.ndim
new_i = i.owner.inputs[0] new_i = i.owner.inputs[0]
if theano.config.experimental.local_alloc_elemwise_assert: if theano.config.experimental.local_alloc_elemwise_assert:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论