Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
5ee86171
提交
5ee86171
authored
6月 04, 2013
作者:
Frédéric Bastien
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1281 from abalkin/py3k-fixes
Fixes for python 3 compatibility.
上级
6f443939
7671eb9a
显示空白字符变更
内嵌
并排
正在显示
10 个修改的文件
包含
75 行增加
和
26 行删除
+75
-26
__init__.py
theano/compat/__init__.py
+11
-0
cmodule.py
theano/gof/cmodule.py
+37
-8
__init__.py
theano/misc/tests/__init__.py
+0
-0
__init__.py
theano/sandbox/linalg/tests/__init__.py
+0
-0
scan.py
theano/scan_module/scan.py
+1
-2
__init__.py
theano/scan_module/tests/__init__.py
+0
-0
test_scan.py
theano/scan_module/tests/test_scan.py
+21
-12
basic.py
theano/tensor/basic.py
+3
-2
opt.py
theano/tensor/opt.py
+1
-1
test_basic.py
theano/tensor/tests/test_basic.py
+1
-1
没有找到文件。
theano/compat/__init__.py
浏览文件 @
5ee86171
...
...
@@ -30,7 +30,12 @@ if PY3:
from
itertools
import
combinations
,
product
from
sys
import
maxsize
def
decode
(
x
):
return
x
.
decode
()
def
decode_iter
(
itr
):
for
x
in
itr
:
yield
x
.
decode
()
else
:
from
operator
import
div
as
operator_div
...
...
@@ -44,3 +49,9 @@ else:
from
theano.compat.python2x
import
all
,
any
,
partial
,
defaultdict
,
deque
from
theano.compat.python2x
import
combinations
,
product
,
maxsize
from
theano.compat.python2x
import
DictMixin
,
OrderedDict
def
decode
(
x
):
return
x
def
decode_iter
(
x
):
return
x
theano/gof/cmodule.py
浏览文件 @
5ee86171
...
...
@@ -13,13 +13,14 @@ import subprocess
import
sys
import
tempfile
import
time
import
itertools
import
distutils.sysconfig
import
numpy.distutils
# TODO: TensorType should handle this
import
theano
from
theano.compat
import
PY3
,
b
,
next
from
theano.compat
import
PY3
,
next
,
decode
,
decode_iter
from
theano.gof.utils
import
flatten
from
theano.configparser
import
config
from
theano.gof.cc
import
hash_from_code
...
...
@@ -1470,6 +1471,34 @@ def gcc_version():
return
gcc_version_str
def
gcc_llvm
():
""" Detect if the g++ version used is the llvm one or not.
It don't support all g++ parameters even if it support many of them.
"""
if
gcc_llvm
.
is_llvm
is
None
:
pass
p
=
None
try
:
p
=
call_subprocess_Popen
([
'g++'
,
'--version'
],
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
)
p
.
wait
()
output
=
p
.
stdout
.
read
()
+
p
.
stderr
.
read
()
except
OSError
:
# Typically means g++ cannot be found.
# So it is not an llvm compiler.
# Normally this should not happen as we should not try to
# compile when g++ is not available. If this happen, it
# will crash later so supposing it is not llvm is "safe".
output
=
b
(
''
)
del
p
gcc_llvm
.
is_llvm
=
b
(
"llvm"
)
in
output
return
gcc_llvm
.
is_llvm
gcc_llvm
.
is_llvm
=
None
class
GCC_compiler
(
object
):
# The equivalent flags of --march=native used by g++.
march_flags
=
None
...
...
@@ -1515,11 +1544,11 @@ class GCC_compiler(object):
if
p
.
returncode
!=
0
:
return
None
stdout
=
p
.
stdout
.
readlines
(
)
stderr
=
p
.
stderr
.
readlines
(
)
stdout
=
decode_iter
(
p
.
stdout
.
readlines
()
)
stderr
=
decode_iter
(
p
.
stderr
.
readlines
()
)
lines
=
[]
if
parse
:
for
line
in
stdout
+
stderr
:
for
line
in
itertools
.
chain
(
stdout
,
stderr
)
:
if
"COLLECT_GCC_OPTIONS="
in
line
:
continue
elif
"-march="
in
line
and
"-march=native"
not
in
line
:
...
...
@@ -1528,8 +1557,8 @@ class GCC_compiler(object):
lines
.
append
(
line
.
strip
())
lines
=
list
(
set
(
lines
))
# to remove duplicate
else
:
lines
=
stdout
+
stderr
return
lines
lines
=
itertools
.
chain
(
stdout
,
stderr
)
return
list
(
lines
)
# The '-' at the end is needed. Otherwise, g++ do not output
# enough information.
...
...
@@ -1804,7 +1833,7 @@ class GCC_compiler(object):
try
:
p
=
call_subprocess_Popen
(
cmd
,
stderr
=
subprocess
.
PIPE
)
compile_stderr
=
p
.
communicate
()[
1
]
compile_stderr
=
decode
(
p
.
communicate
()[
1
])
except
Exception
:
# An exception can occur e.g. if `g++` is not found.
print_command_line_error
()
...
...
@@ -1825,7 +1854,7 @@ class GCC_compiler(object):
# prints the exception, having '\n' in the text makes it more
# difficult to read.
raise
Exception
(
'Compilation failed (return status=
%
s):
%
s'
%
(
status
,
compile_stderr
.
replace
(
b
(
'
\n
'
),
b
(
'. '
)
)))
(
status
,
compile_stderr
.
replace
(
'
\n
'
,
'. '
)))
elif
config
.
cmodule
.
compilation_warning
and
compile_stderr
:
# Print errors just below the command line.
print
compile_stderr
...
...
theano/misc/tests/__init__.py
0 → 100644
浏览文件 @
5ee86171
theano/sandbox/linalg/tests/__init__.py
0 → 100644
浏览文件 @
5ee86171
theano/scan_module/scan.py
浏览文件 @
5ee86171
...
...
@@ -785,8 +785,7 @@ def scan(fn,
not
isinstance
(
x
,
SharedVariable
)
and
not
isinstance
(
x
,
gof
.
Constant
)),
gof
.
graph
.
inputs
(
fake_outputs
))
extra_inputs
=
filter
(
lambda
x
:
x
not
in
args
+
fake_nonseqs
,
all_inputs
)
extra_inputs
=
[
x
for
x
in
all_inputs
if
x
not
in
args
+
fake_nonseqs
]
non_seqs
+=
extra_inputs
## Note we do not use all_inputs directly since the order of variables
## in args is quite important
...
...
theano/scan_module/tests/__init__.py
0 → 100644
浏览文件 @
5ee86171
theano/scan_module/tests/test_scan.py
浏览文件 @
5ee86171
...
...
@@ -17,6 +17,7 @@ from theano.gof.python25 import any
from
theano.tests
import
unittest_tools
as
utt
import
theano.scalar.sharedvar
from
theano.gof.python25
import
OrderedDict
from
theano.compat
import
PY3
from
numpy.testing.noseclasses
import
KnownFailureTest
...
...
@@ -2366,8 +2367,8 @@ class T_Scan(unittest.TestCase):
f
=
theano
.
function
([
x
,
y
],
[
sx
,
sy
],
mode
=
mode_with_opt
.
excluding
(
'scanOp_pushout_seqs_ops'
))
topo
=
f
.
maker
.
fgraph
.
toposort
()
scans
=
filter
(
lambda
n
:
isinstance
(
n
.
op
,
theano
.
scan_module
.
scan_op
.
Scan
)
,
topo
)
scans
=
[
n
for
n
in
topo
if
isinstance
(
n
.
op
,
theano
.
scan_module
.
scan_op
.
Scan
)
]
self
.
assertTrue
(
len
(
scans
)
==
2
)
sx
,
upx
=
theano
.
scan
(
sum
,
sequences
=
[
x
],
n_steps
=
2
)
...
...
@@ -2376,8 +2377,8 @@ class T_Scan(unittest.TestCase):
f
=
theano
.
function
([
x
,
y
],
[
sx
,
sy
],
mode
=
mode_with_opt
.
excluding
(
'scanOp_pushout_seqs_ops'
))
topo
=
f
.
maker
.
fgraph
.
toposort
()
scans
=
filter
(
lambda
n
:
isinstance
(
n
.
op
,
theano
.
scan_module
.
scan_op
.
Scan
)
,
topo
)
scans
=
[
n
for
n
in
topo
if
isinstance
(
n
.
op
,
theano
.
scan_module
.
scan_op
.
Scan
)
]
self
.
assertTrue
(
len
(
scans
)
==
2
)
sx
,
upx
=
theano
.
scan
(
sum
,
sequences
=
[
x
],
n_steps
=
4
)
...
...
@@ -2386,8 +2387,8 @@ class T_Scan(unittest.TestCase):
f
=
theano
.
function
([
x
,
y
],
[
sx
,
sy
],
mode
=
mode_with_opt
.
excluding
(
'scanOp_pushout_seqs_ops'
))
topo
=
f
.
maker
.
fgraph
.
toposort
()
scans
=
filter
(
lambda
n
:
isinstance
(
n
.
op
,
theano
.
scan_module
.
scan_op
.
Scan
)
,
topo
)
scans
=
[
n
for
n
in
topo
if
isinstance
(
n
.
op
,
theano
.
scan_module
.
scan_op
.
Scan
)
]
self
.
assertTrue
(
len
(
scans
)
==
1
)
sx
,
upx
=
theano
.
scan
(
sum
,
sequences
=
[
x
])
...
...
@@ -2396,8 +2397,8 @@ class T_Scan(unittest.TestCase):
f
=
theano
.
function
([
x
],
[
sx
,
sy
],
mode
=
mode_with_opt
.
excluding
(
'scanOp_pushout_seqs_ops'
))
topo
=
f
.
maker
.
fgraph
.
toposort
()
scans
=
filter
(
lambda
n
:
isinstance
(
n
.
op
,
theano
.
scan_module
.
scan_op
.
Scan
),
topo
)
scans
=
[
n
for
n
in
topo
if
isinstance
(
n
.
op
,
theano
.
scan_module
.
scan_op
.
Scan
)]
self
.
assertTrue
(
len
(
scans
)
==
1
)
sx
,
upx
=
theano
.
scan
(
sum
,
sequences
=
[
x
])
...
...
@@ -2406,8 +2407,8 @@ class T_Scan(unittest.TestCase):
f
=
theano
.
function
([
x
],
[
sx
,
sy
],
mode
=
mode_with_opt
.
excluding
(
'scanOp_pushout_seqs_ops'
))
topo
=
f
.
maker
.
fgraph
.
toposort
()
scans
=
filter
(
lambda
n
:
isinstance
(
n
.
op
,
theano
.
scan_module
.
scan_op
.
Scan
),
topo
)
scans
=
[
n
for
n
in
topo
if
isinstance
(
n
.
op
,
theano
.
scan_module
.
scan_op
.
Scan
)]
self
.
assertTrue
(
len
(
scans
)
==
1
)
sx
,
upx
=
theano
.
scan
(
sum
,
sequences
=
[
x
])
...
...
@@ -2416,8 +2417,8 @@ class T_Scan(unittest.TestCase):
f
=
theano
.
function
([
x
],
[
sx
,
sy
],
mode
=
mode_with_opt
.
excluding
(
'scanOp_pushout_seqs_ops'
))
topo
=
f
.
maker
.
fgraph
.
toposort
()
scans
=
filter
(
lambda
n
:
isinstance
(
n
.
op
,
theano
.
scan_module
.
scan_op
.
Scan
),
topo
)
scans
=
[
n
for
n
in
topo
if
isinstance
(
n
.
op
,
theano
.
scan_module
.
scan_op
.
Scan
)]
self
.
assertTrue
(
len
(
scans
)
==
2
)
def
test_hash
(
self
):
...
...
@@ -3515,6 +3516,14 @@ def test_speed():
t0
=
time
.
time
()
r_i
=
iter
(
r
[
1
:])
r_ii
=
iter
(
r
[:
-
1
])
if
PY3
:
while
True
:
try
:
tmp
=
next
(
r_i
)
tmp
+=
next
(
r_ii
)
except
StopIteration
:
break
else
:
while
True
:
try
:
tmp
=
r_i
.
next
()
...
...
theano/tensor/basic.py
浏览文件 @
5ee86171
...
...
@@ -4609,12 +4609,13 @@ class Subtensor(Op):
# There is a bug in numpy that results in isinstance(x, int) returning
# False for numpy integers.
# See <http://projects.scipy.org/numpy/ticket/2235>.
elif
isinstance
(
entry
,
(
numpy
.
integer
,
int
)
):
elif
isinstance
(
entry
,
numpy
.
integer
):
return
entry
# On Windows 64-bit, shapes are returned as Python long, as they can
# be bigger than what a Python int can hold.
# Shapes should always fit in a numpy.int64, and we support them better
elif
isinstance
(
entry
,
long
):
# 2) In Python3, long replaced int. So we must assert it fit in int64.
elif
isinstance
(
entry
,
(
int
,
long
)):
entry64
=
numpy
.
int64
(
entry
)
return
entry64
else
:
...
...
theano/tensor/opt.py
浏览文件 @
5ee86171
...
...
@@ -1625,7 +1625,7 @@ def local_useless_subtensor(node):
except
NotScalarConstantError
:
pass
if
isinstance
(
idx
.
stop
,
int
):
if
isinstance
(
idx
.
stop
,
(
int
,
numpy
.
integer
)
):
if
idx
.
stop
<
length_pos_data
:
return
False
elif
isinstance
(
idx
.
stop
,
theano
.
scalar
.
Scalar
):
...
...
theano/tensor/tests/test_basic.py
浏览文件 @
5ee86171
...
...
@@ -6438,7 +6438,7 @@ class T_long_tensor(unittest.TestCase):
for
exp
in
xrange
(
64
):
val
=
2L
**
exp
-
1
scalar_ct
=
constant
(
val
)
assert
scalar_ct
.
dtype
==
'int64'
assert
scalar_ct
.
dtype
.
startswith
(
'int'
)
assert
scalar_ct
.
value
==
val
vector_ct
=
constant
([
val
,
val
])
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论