Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
856a3662
提交
856a3662
authored
4月 13, 2015
作者:
Arnaud Bergeron
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove support for python < 2.6.
上级
347a46eb
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
6 行增加
和
162 行删除
+6
-162
__init__.py
theano/compat/__init__.py
+5
-2
python2x.py
theano/compat/python2x.py
+1
-160
没有找到文件。
theano/compat/__init__.py
浏览文件 @
856a3662
...
@@ -43,10 +43,13 @@ else:
...
@@ -43,10 +43,13 @@ else:
return
e
[
0
]
return
e
[
0
]
cmp
=
cmp
cmp
=
cmp
from
functools
import
partial
from
collections
import
defaultdict
,
deque
from
itertools
import
combinations
,
product
from
sys
import
maxsize
# Older Python 2.x compatibility
# Older Python 2.x compatibility
from
theano.compat.python2x
import
partial
,
defaultdict
,
deque
from
theano.compat.python2x
import
combinations
,
product
,
maxsize
from
theano.compat.python2x
import
DictMixin
,
OrderedDict
from
theano.compat.python2x
import
DictMixin
,
OrderedDict
def
decode
(
x
):
def
decode
(
x
):
...
...
theano/compat/python2x.py
浏览文件 @
856a3662
"""
"""
Helper functions to make theano backwards compatible with python 2.4 - 2.7
Helper functions to make theano backwards compatible with python 2.6 - 2.7
(tested on python 2.4 and 2.5)
"""
"""
import
collections
import
sys
import
sys
if
sys
.
version_info
[:
2
]
<
(
2
,
5
):
def
all
(
iterable
):
for
element
in
iterable
:
if
not
element
:
return
False
return
True
def
any
(
iterable
):
for
element
in
iterable
:
if
element
:
return
True
return
False
def
partial
(
func
,
*
args
,
**
keywords
):
def
newfunc
(
*
fargs
,
**
fkeywords
):
newkeywords
=
keywords
.
copy
()
newkeywords
.
update
(
fkeywords
)
return
func
(
*
(
args
+
fargs
),
**
newkeywords
)
newfunc
.
func
=
func
newfunc
.
args
=
args
newfunc
.
keywords
=
keywords
return
newfunc
class
deque
(
collections
.
deque
):
"""
Custom deque class to implement the `remove` method.
"""
def
remove
(
self
,
item
):
found
=
None
for
i
,
x
in
enumerate
(
self
):
if
x
==
item
:
found
=
i
break
if
found
is
None
:
raise
ValueError
(
'item not found in deque'
)
# To remove an item, we rotate the queue until it is the first item
# in the queue, we pop it, and finally we rotate back the queue.
self
.
rotate
(
-
found
)
self
.
popleft
()
self
.
rotate
(
found
)
class
defaultdict
(
dict
):
def
__init__
(
self
,
default_factory
=
None
,
*
a
,
**
kw
):
if
(
default_factory
is
not
None
and
not
hasattr
(
default_factory
,
'__call__'
)):
raise
TypeError
(
'first argument must be callable'
)
dict
.
__init__
(
self
,
*
a
,
**
kw
)
self
.
default_factory
=
default_factory
def
__getitem__
(
self
,
key
):
try
:
return
dict
.
__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
,
# consider replacing items() with iteritems()
return
type
(
self
),
args
,
None
,
None
,
self
.
items
()
def
copy
(
self
):
return
self
.
__copy__
()
def
__copy__
(
self
):
return
type
(
self
)(
self
.
default_factory
,
self
)
def
__deepcopy__
(
self
,
memo
):
import
copy
return
type
(
self
)(
self
.
default_factory
,
copy
.
deepcopy
(
self
.
items
()))
def
__repr__
(
self
):
return
'defaultdict(
%
s,
%
s)'
%
(
self
.
default_factory
,
dict
.
__repr__
(
self
))
else
:
# Only bother with this else clause and the __all__ line if you are putting
# this in a separate file.
import
__builtin__
all
=
__builtin__
.
all
any
=
__builtin__
.
any
import
collections
import
functools
partial
=
functools
.
partial
defaultdict
=
collections
.
defaultdict
deque
=
collections
.
deque
__all__
=
[
'all'
,
'any'
,
'partial'
,
'defaultdict'
,
'deque'
]
if
sys
.
version_info
[:
2
]
<
(
2
,
6
):
# Borrowed from Python docs
def
combinations
(
iterable
,
r
):
# combinations('ABCD', 2) --> AB AC AD BC BD CD
# combinations(range(4), 3) --> 012 013 023 123
pool
=
tuple
(
iterable
)
n
=
len
(
pool
)
if
r
>
n
:
return
indices
=
range
(
r
)
yield
tuple
(
pool
[
i
]
for
i
in
indices
)
while
True
:
for
i
in
reversed
(
range
(
r
)):
if
indices
[
i
]
!=
i
+
n
-
r
:
break
else
:
return
indices
[
i
]
+=
1
for
j
in
range
(
i
+
1
,
r
):
indices
[
j
]
=
indices
[
j
-
1
]
+
1
yield
tuple
(
pool
[
i
]
for
i
in
indices
)
def
product
(
*
args
,
**
kwds
):
# product('ABCD', 'xy') --> Ax Ay Bx By Cx Cy Dx Dy
# product(range(2), repeat=3) --> 000 001 010 011 100 101 110 111
pools
=
map
(
tuple
,
args
)
*
kwds
.
get
(
'repeat'
,
1
)
result
=
[[]]
for
pool
in
pools
:
result
=
[
x
+
[
y
]
for
x
in
result
for
y
in
pool
]
for
prod
in
result
:
yield
tuple
(
prod
)
# For maxsize
class
__Dummy
(
object
):
"""
Dummy class used to know what is the max index of a slice.
This way, we do not have to rely on guesses for untested
architectures.
"""
def
__getslice__
(
self
,
*
args
):
return
args
# This "slice" should be a (1, maxsize) tuple
__dummy_slice
=
__Dummy
()[
1
:]
maxsize
=
__dummy_slice
[
1
]
del
__dummy_slice
,
__Dummy
else
:
from
itertools
import
combinations
,
product
from
sys
import
maxsize
__all__
+=
[
'combinations'
,
'product'
,
'maxsize'
]
if
sys
.
version_info
[:
2
]
<
(
2
,
7
):
if
sys
.
version_info
[:
2
]
<
(
2
,
7
):
# The following implementation of OrderedDict compatible with python 2.4
# The following implementation of OrderedDict compatible with python 2.4
# was taken from http://pypi.python.org/pypi/ordereddict/1.1
# was taken from http://pypi.python.org/pypi/ordereddict/1.1
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论