提交 8b008d5e authored 作者: Frederic Bastien's avatar Frederic Bastien

Speed up Canonizer.get_constant that speed up simplify_constants as it use it frequently.

上级 80edc315
......@@ -4713,13 +4713,17 @@ class Canonizer(gof.LocalOptimizer):
numeric constant. If v is a plain Variable, returns None.
"""
if isinstance(v, Variable):
try:
# As the constant folding is in the canonicalize phase,
# We don't need to check all the graph each time.
return get_scalar_constant_value(v, only_process_constants=True)
except NotScalarConstantError:
if isinstance(v, Constant):
if getattr(v.tag, 'unique_value', None) is not None:
data = v.tag.unique_value
else:
data = v.data
if data.ndim == 0:
return data
else:
return None
elif isinstance(v, Variable):
return None
else:
return v
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论