提交 9a87ce10 authored 作者: Frederic Bastien's avatar Frederic Bastien

make debugmode use the new theano.misc.may_share_memory.may_share_memory fct to…

make debugmode use the new theano.misc.may_share_memory.may_share_memory fct to don't raise useless warning. It was calling the wrong *Type.may_share_memory sometimes.
上级 33adfef5
...@@ -522,13 +522,12 @@ def _check_inputs(node, storage_map, r_vals, dr_vals, active_nodes, clobber_dr_v ...@@ -522,13 +522,12 @@ def _check_inputs(node, storage_map, r_vals, dr_vals, active_nodes, clobber_dr_v
if warn_input_not_reused: if warn_input_not_reused:
vmap=getattr(node.op,'view_map',{}) vmap=getattr(node.op,'view_map',{})
for oo,ii in vmap.iteritems(): for oo,ii in vmap.iteritems():
if hasattr(node.outputs[0].type,"may_share_memory"): if not _may_share_memory(storage_map[node.outputs[oo]][0],storage_map[node.inputs[ii[0]]][0]):
if not node.outputs[0].type.may_share_memory(storage_map[node.outputs[oo]][0],storage_map[node.inputs[ii[0]]][0]):
#when a subtensor return a tensor ofndim==0, numpy seam to return a copy. #when a subtensor return a tensor ofndim==0, numpy seam to return a copy.
#when have an empty ndarray(happen with output guard) it is not the same. why? #when have an empty ndarray(happen with output guard) it is not the same. why?
if storage_map[node.outputs[oo]][0].ndim>0 and storage_map[node.outputs[oo]][0].size>0: if storage_map[node.outputs[oo]][0].ndim>0 and storage_map[node.outputs[oo]][0].size>0:
warning("input idx %d marked as viewed but new memory allocated by node '%s'"%(ii[0],str(node))) import pdb;pdb.set_trace()
elif storage_map[node.outputs[oo]][0] is not storage_map[node.inputs[ii[0]]][0]: _may_share_memory(storage_map[node.outputs[oo]][0],storage_map[node.inputs[ii[0]]][0])
warning("input idx %d marked as viewed but new memory allocated by node '%s'"%(ii[0],str(node))) warning("input idx %d marked as viewed but new memory allocated by node '%s'"%(ii[0],str(node)))
for r_idx, r in enumerate(node.inputs): for r_idx, r in enumerate(node.inputs):
...@@ -610,13 +609,8 @@ def _check_viewmap(node, storage_map): ...@@ -610,13 +609,8 @@ def _check_viewmap(node, storage_map):
raise BadViewMap(node, oi, outstorage, out_alias_idx=other_oi) raise BadViewMap(node, oi, outstorage, out_alias_idx=other_oi)
def _may_share_memory(a, b): def _may_share_memory(a, b):
try: from theano.misc.may_share_memory import may_share_memory
return numpy.may_share_memory(a, b) return may_share_memory(a,b,False)
except:
return False
#return (hasattr(a,'__array_interface__') and
#hasattr(b,'__array_interface__') and
#numpy.may_share_memory(a,b))
def _is_function_output(node): def _is_function_output(node):
""" """
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论