Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
3dcaac82
提交
3dcaac82
authored
12月 05, 2012
作者:
nouiz
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1118 from delallea/python24
A few improvements to OrderedSet implementation
上级
440ed842
bb9ed8fb
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
44 行增加
和
17 行删除
+44
-17
destroyhandler.py
theano/gof/destroyhandler.py
+3
-3
ordered_set.py
theano/misc/ordered_set.py
+41
-14
没有找到文件。
theano/gof/destroyhandler.py
浏览文件 @
3dcaac82
...
@@ -141,7 +141,7 @@ def _contains_cycle(fgraph, orderings):
...
@@ -141,7 +141,7 @@ def _contains_cycle(fgraph, orderings):
# IG: I tried using a shared empty_list = [] constructed
# IG: I tried using a shared empty_list = [] constructed
# outside of the for loop to avoid constructing multiple
# outside of the for loop to avoid constructing multiple
# lists, but this was not any faster.
# lists, but this was not any faster.
parents
.
extend
(
orderings
.
get
(
a_n
,[]))
parents
.
extend
(
orderings
.
get
(
a_n
,
[]))
if
parents
:
if
parents
:
for
parent
in
parents
:
for
parent
in
parents
:
...
@@ -982,8 +982,8 @@ class DestroyHandler(toolbox.Bookkeeper):
...
@@ -982,8 +982,8 @@ class DestroyHandler(toolbox.Bookkeeper):
# depend on destroyed_input
# depend on destroyed_input
root_clients
=
OrderedSet
()
root_clients
=
OrderedSet
()
for
r
in
root_impact
:
for
r
in
root_impact
:
assert
not
[
a
for
a
,
c
in
self
.
clients
[
r
]
.
items
()
if
not
c
]
assert
not
[
a
for
a
,
c
in
self
.
clients
[
r
]
.
items
()
if
not
c
]
root_clients
.
update
([
a
for
a
,
c
in
self
.
clients
[
r
]
.
items
()
if
c
])
root_clients
.
update
([
a
for
a
,
c
in
self
.
clients
[
r
]
.
items
()
if
c
])
root_clients
.
remove
(
app
)
root_clients
.
remove
(
app
)
if
root_clients
:
if
root_clients
:
rval
[
app
]
=
root_clients
rval
[
app
]
=
root_clients
...
...
theano/misc/ordered_set.py
浏览文件 @
3dcaac82
...
@@ -15,7 +15,8 @@ def check_deterministic(iterable):
...
@@ -15,7 +15,8 @@ def check_deterministic(iterable):
# So I must use an assert here. In the long term we should fix the rest of
# So I must use an assert here. In the long term we should fix the rest of
# theano to use exceptions correctly, so that this can be a TypeError.
# theano to use exceptions correctly, so that this can be a TypeError.
if
iterable
is
not
None
:
if
iterable
is
not
None
:
assert
isinstance
(
iterable
,
(
list
,
tuple
,
OrderedSet
,
types
.
GeneratorType
))
assert
isinstance
(
iterable
,
(
list
,
tuple
,
OrderedSet
,
types
.
GeneratorType
,
basestring
))
if
MutableSet
is
not
None
:
if
MutableSet
is
not
None
:
# From http://code.activestate.com/recipes/576694/
# From http://code.activestate.com/recipes/576694/
...
@@ -106,9 +107,21 @@ if MutableSet is not None:
...
@@ -106,9 +107,21 @@ if MutableSet is not None:
return
'
%
s(
%
r)'
%
(
self
.
__class__
.
__name__
,
list
(
self
))
return
'
%
s(
%
r)'
%
(
self
.
__class__
.
__name__
,
list
(
self
))
def
__eq__
(
self
,
other
):
def
__eq__
(
self
,
other
):
# Note that we implement only the comparison to another
# `OrderedSet`, and not to a regular `set`, because otherwise we
# could have a non-symmetric equality relation like:
# my_ordered_set == my_set and my_set != my_ordered_set
if
isinstance
(
other
,
OrderedSet
):
if
isinstance
(
other
,
OrderedSet
):
return
len
(
self
)
==
len
(
other
)
and
list
(
self
)
==
list
(
other
)
return
len
(
self
)
==
len
(
other
)
and
list
(
self
)
==
list
(
other
)
return
set
(
self
)
==
set
(
other
)
elif
isinstance
(
other
,
set
):
# Raise exception to avoid confusion.
raise
TypeError
(
'Cannot compare an `OrderedSet` to a `set` because '
'this comparison cannot be made symmetric: please '
'manually cast your `OrderedSet` into `set` before '
'performing this comparison.'
)
else
:
return
NotImplemented
def
__del__
(
self
):
def
__del__
(
self
):
self
.
clear
()
# remove circular references
self
.
clear
()
# remove circular references
...
@@ -149,7 +162,7 @@ else:
...
@@ -149,7 +162,7 @@ else:
raise
KeyError
(
key
)
raise
KeyError
(
key
)
def
__iter__
(
self
):
def
__iter__
(
self
):
return
self
.
data
.
keys
()
.
__iter__
()
return
self
.
data
.
__iter__
()
def
__reversed__
(
self
):
def
__reversed__
(
self
):
return
self
.
data
.
__reversed__
()
return
self
.
data
.
__reversed__
()
...
@@ -158,18 +171,32 @@ else:
...
@@ -158,18 +171,32 @@ else:
raise
NotImplementedError
()
raise
NotImplementedError
()
def
__eq__
(
self
,
other
):
def
__eq__
(
self
,
other
):
return
type
(
self
)
==
type
(
other
)
and
\
# Note that we implement only the comparison to another
self
.
data
==
other
.
data
# `OrderedSet`, and not to a regular `set`, because otherwise we
# could have a non-symmetric equality relation like:
def
__del__
(
self
):
# my_ordered_set == my_set and my_set != my_ordered_set
# Remove circular references
if
isinstance
(
other
,
OrderedSet
):
self
.
data
.
clear
()
return
len
(
self
)
==
len
(
other
)
and
list
(
self
)
==
list
(
other
)
elif
isinstance
(
other
,
set
):
# Raise exception to avoid confusion.
raise
TypeError
(
'Cannot compare an `OrderedSet` to a `set` because '
'this comparison cannot be made symmetric: please '
'manually cast your `OrderedSet` into `set` before '
'performing this comparison.'
)
else
:
return
NotImplemented
# NB: Contrary to the other implementation above, we do not override
# the `__del__` method. On one hand, this is not needed since this
# implementation does not add circular references. Moreover, one should
# not clear the underlying dictionary holding the data as soon as the
# ordered set is cleared from memory, because there may still be
# pointers to this dictionary.
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
print
(
OrderedSet
(
'abracadaba'
))
print
list
(
OrderedSet
(
'abracadaba'
))
print
(
OrderedSet
(
'simsalabim'
))
print
list
(
OrderedSet
(
'simsalabim'
))
print
OrderedSet
(
'boom'
)
==
OrderedSet
(
'moob'
)
print
OrderedSet
(
'boom'
)
==
'moob'
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论