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

Cache constant float that aren't int. This lower the work merge1 opt have to do

上级 838b8ab4
...@@ -276,7 +276,9 @@ def constant(x, name=None, ndim=None, dtype=None): ...@@ -276,7 +276,9 @@ def constant(x, name=None, ndim=None, dtype=None):
if (sig not in constant_cache and ret.data.size == 1 and if (sig not in constant_cache and ret.data.size == 1 and
(-10) <= ret.data <= 10 and (-10) <= ret.data <= 10 and
(ret.dtype in int_dtypes or ret.dtype in uint_dtypes or (ret.dtype in int_dtypes or ret.dtype in uint_dtypes or
(ret.dtype in float_dtypes and int(ret.data) == ret.data))): (ret.dtype in float_dtypes and
# Limit the size of the cache.
len(constant_cache) < 10000))):
constant_cache[sig] = ret constant_cache[sig] = ret
# This is needed to raise a good error to the user. # This is needed to raise a good error to the user.
ret.cached = True ret.cached = True
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论