Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
61f21c55
提交
61f21c55
authored
8月 21, 2012
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make a DefaultOrderedDict available.
Will be used in a later commit.
上级
ffbd2074
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
173 行增加
和
0 行删除
+173
-0
python25.py
theano/gof/python25.py
+173
-0
没有找到文件。
theano/gof/python25.py
浏览文件 @
61f21c55
...
...
@@ -158,3 +158,176 @@ if sys.version_info[:2] < (2, 6):
else
:
from
itertools
import
combinations
,
product
from
sys
import
maxsize
if
sys
.
version_info
[:
2
]
<
(
2
,
7
):
# The following implementation of OrderedDict compatible with python 2.4
# was taked from http://pypi.python.org/pypi/ordereddict/1.1
# It is under the MIT license.
# Copyright (c) 2009 Raymond Hettinger
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation files
# (the "Software"), to deal in the Software without restriction,
# including without limitation the rights to use, copy, modify, merge,
# publish, distribute, sublicense, and/or sell copies of the Software,
# and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
from
UserDict
import
DictMixin
class
OrderedDict
(
dict
,
DictMixin
):
def
__init__
(
self
,
*
args
,
**
kwds
):
if
len
(
args
)
>
1
:
raise
TypeError
(
'expected at most 1 arguments, got
%
d'
%
len
(
args
))
try
:
self
.
__end
except
AttributeError
:
self
.
clear
()
self
.
update
(
*
args
,
**
kwds
)
def
clear
(
self
):
self
.
__end
=
end
=
[]
end
+=
[
None
,
end
,
end
]
# sentinel node for doubly linked list
self
.
__map
=
{}
# key --> [key, prev, next]
dict
.
clear
(
self
)
def
__setitem__
(
self
,
key
,
value
):
if
key
not
in
self
:
end
=
self
.
__end
curr
=
end
[
1
]
curr
[
2
]
=
end
[
1
]
=
self
.
__map
[
key
]
=
[
key
,
curr
,
end
]
dict
.
__setitem__
(
self
,
key
,
value
)
def
__delitem__
(
self
,
key
):
dict
.
__delitem__
(
self
,
key
)
key
,
prev
,
next
=
self
.
__map
.
pop
(
key
)
prev
[
2
]
=
next
next
[
1
]
=
prev
def
__iter__
(
self
):
end
=
self
.
__end
curr
=
end
[
2
]
while
curr
is
not
end
:
yield
curr
[
0
]
curr
=
curr
[
2
]
def
__reversed__
(
self
):
end
=
self
.
__end
curr
=
end
[
1
]
while
curr
is
not
end
:
yield
curr
[
0
]
curr
=
curr
[
1
]
def
popitem
(
self
,
last
=
True
):
if
not
self
:
raise
KeyError
(
'dictionary is empty'
)
if
last
:
key
=
reversed
(
self
)
.
next
()
else
:
key
=
iter
(
self
)
.
next
()
value
=
self
.
pop
(
key
)
return
key
,
value
def
__reduce__
(
self
):
items
=
[[
k
,
self
[
k
]]
for
k
in
self
]
tmp
=
self
.
__map
,
self
.
__end
del
self
.
__map
,
self
.
__end
inst_dict
=
vars
(
self
)
.
copy
()
self
.
__map
,
self
.
__end
=
tmp
if
inst_dict
:
return
(
self
.
__class__
,
(
items
,),
inst_dict
)
return
self
.
__class__
,
(
items
,)
def
keys
(
self
):
return
list
(
self
)
setdefault
=
DictMixin
.
setdefault
update
=
DictMixin
.
update
pop
=
DictMixin
.
pop
values
=
DictMixin
.
values
items
=
DictMixin
.
items
iterkeys
=
DictMixin
.
iterkeys
itervalues
=
DictMixin
.
itervalues
iteritems
=
DictMixin
.
iteritems
def
__repr__
(
self
):
if
not
self
:
return
'
%
s()'
%
(
self
.
__class__
.
__name__
,)
return
'
%
s(
%
r)'
%
(
self
.
__class__
.
__name__
,
self
.
items
())
def
copy
(
self
):
return
self
.
__class__
(
self
)
@classmethod
def
fromkeys
(
cls
,
iterable
,
value
=
None
):
d
=
cls
()
for
key
in
iterable
:
d
[
key
]
=
value
return
d
def
__eq__
(
self
,
other
):
if
isinstance
(
other
,
OrderedDict
):
if
len
(
self
)
!=
len
(
other
):
return
False
for
p
,
q
in
zip
(
self
.
items
(),
other
.
items
()):
if
p
!=
q
:
return
False
return
True
return
dict
.
__eq__
(
self
,
other
)
def
__ne__
(
self
,
other
):
return
not
self
==
other
else
:
from
UserDict
import
DictMixin
OrderedDict
=
collections
.
OrderedDict
from
collections
import
Callable
class
DefaultOrderedDict
(
OrderedDict
):
def
__init__
(
self
,
default_factory
=
None
,
*
a
,
**
kw
):
if
(
default_factory
is
not
None
and
not
callable
(
default_factory
)):
raise
TypeError
(
'first argument must be callable'
)
OrderedDict
.
__init__
(
self
,
*
a
,
**
kw
)
self
.
default_factory
=
default_factory
def
__getitem__
(
self
,
key
):
try
:
return
OrderedDict
.
__getitem__
(
self
,
key
)
except
KeyError
:
return
self
.
__missing__
(
key
)
def
__missing__
(
self
,
key
):
if
self
.
default_factory
is
None
:
raise
KeyError
(
key
)
self
[
key
]
=
value
=
self
.
default_factory
()
return
value
def
__reduce__
(
self
):
if
self
.
default_factory
is
None
:
args
=
tuple
()
else
:
args
=
self
.
default_factory
,
return
type
(
self
),
args
,
None
,
None
,
self
.
items
()
def
copy
(
self
):
return
self
.
__copy__
()
def
__copy__
(
self
):
return
type
(
self
)(
self
.
default_factory
,
self
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论