Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
cf655c6f
提交
cf655c6f
authored
12月 01, 2012
作者:
Ian Goodfellow
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
make determinism type checks work with generator expressions
上级
8015719a
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
25 行增加
和
16 行删除
+25
-16
destroyhandler.py
theano/gof/destroyhandler.py
+3
-2
ordered_set.py
theano/misc/ordered_set.py
+22
-14
没有找到文件。
theano/gof/destroyhandler.py
浏览文件 @
cf655c6f
...
@@ -958,8 +958,9 @@ class DestroyHandler(toolbox.Bookkeeper):
...
@@ -958,8 +958,9 @@ class DestroyHandler(toolbox.Bookkeeper):
#CHECK FOR INPUT ALIASING
#CHECK FOR INPUT ALIASING
# OPT: pre-compute this on import
# OPT: pre-compute this on import
tolerate_same
=
getattr
(
app
.
op
,
'destroyhandler_tolerate_same'
,
[])
tolerate_same
=
getattr
(
app
.
op
,
'destroyhandler_tolerate_same'
,
[])
tolerated
=
OrderedSet
(
idx1
for
idx0
,
idx1
in
tolerate_same
assert
isinstance
(
tolerate_same
,
list
)
if
idx0
==
destroyed_idx
)
tolerated
=
OrderedSet
((
idx1
for
idx0
,
idx1
in
tolerate_same
if
idx0
==
destroyed_idx
),
known_deterministic
=
True
)
tolerated
.
add
(
destroyed_idx
)
tolerated
.
add
(
destroyed_idx
)
tolerate_aliased
=
getattr
(
app
.
op
,
'destroyhandler_tolerate_aliased'
,
[])
tolerate_aliased
=
getattr
(
app
.
op
,
'destroyhandler_tolerate_aliased'
,
[])
ignored
=
OrderedSet
(
idx1
for
idx0
,
idx1
in
tolerate_aliased
ignored
=
OrderedSet
(
idx1
for
idx0
,
idx1
in
tolerate_aliased
...
...
theano/misc/ordered_set.py
浏览文件 @
cf655c6f
...
@@ -5,6 +5,12 @@ except ImportError:
...
@@ -5,6 +5,12 @@ except ImportError:
# Python 2.4
# Python 2.4
pass
pass
from
theano.gof.python25
import
OrderedDict
from
theano.gof.python25
import
OrderedDict
import
types
def
check_deterministic
(
iterable
,
known_deterministic
):
if
not
isinstance
(
iterable
,
(
list
,
tuple
,
OrderedSet
))
or
\
(
isinstance
(
iterable
,
types
.
GeneratorType
and
known_deterministic
)):
raise
TypeError
((
type
(
iterable
),
known_deterministic
))
if
MutableSet
is
not
None
:
if
MutableSet
is
not
None
:
# From http://code.activestate.com/recipes/576694/
# From http://code.activestate.com/recipes/576694/
...
@@ -14,13 +20,18 @@ if MutableSet is not None:
...
@@ -14,13 +20,18 @@ if MutableSet is not None:
# Added by IG-- pre-existing theano code expected sets
# Added by IG-- pre-existing theano code expected sets
# to have this method
# to have this method
def
update
(
self
,
container
):
def
update
(
self
,
iterable
,
known_deterministic
=
False
):
# only allowed ordered containers
check_deterministic
(
iterable
,
known_deterministic
)
assert
isinstance
(
container
,
(
list
,
OrderedSet
))
self
|=
iterable
for
elem
in
container
:
self
.
add
(
elem
)
def
__init__
(
self
,
iterable
=
None
,
known_deterministic
=
False
):
"""
def
__init__
(
self
,
iterable
=
None
):
known_deterministic: if iterable is a generator expression,
the caller must certify that it is from
a deterministic class, like list or OrderedSet
"""
# Checks added by IG
check_deterministic
(
iterable
,
known_deterministic
)
self
.
end
=
end
=
[]
self
.
end
=
end
=
[]
end
+=
[
None
,
end
,
end
]
# sentinel node for doubly linked list
end
+=
[
None
,
end
,
end
]
# sentinel node for doubly linked list
self
.
map
=
{}
# key --> [key, prev, next]
self
.
map
=
{}
# key --> [key, prev, next]
...
@@ -88,16 +99,13 @@ else:
...
@@ -88,16 +99,13 @@ else:
An implementation of OrderedSet based on the keys of
An implementation of OrderedSet based on the keys of
an OrderedDict.
an OrderedDict.
"""
"""
def
__init__
(
self
,
iterable
=
None
):
def
__init__
(
self
,
iterable
=
None
,
known_deterministic
=
False
):
self
.
data
=
OrderedDict
()
self
.
data
=
OrderedDict
()
if
iterable
is
not
None
:
if
iterable
is
not
None
:
self
.
update
(
iterable
)
self
.
update
(
iterable
,
known_deterministic
)
def
update
(
self
,
container
):
def
update
(
self
,
container
,
known_deterministic
=
False
):
# only allowed ordered containers
check_deterministic
(
container
,
known_deterministic
)
if
not
isinstance
(
container
,
(
list
,
tuple
,
OrderedSet
)):
raise
TypeError
(
"OrderedSet can only be ordered if updated "
" with ordered containers. Got "
+
str
(
type
(
container
)))
for
elem
in
container
:
for
elem
in
container
:
self
.
add
(
elem
)
self
.
add
(
elem
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论