Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
abc28761
提交
abc28761
authored
10月 01, 2015
作者:
Piotr Frankowski
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
#3429 - python 'with' statement in reset modules
上级
54b194d5
隐藏空白字符变更
内嵌
并排
正在显示
15 个修改的文件
包含
74 行增加
和
108 行删除
+74
-108
function_module.py
theano/compile/function_module.py
+11
-17
test_function.py
theano/compile/tests/test_function.py
+2
-3
d3viz.py
theano/d3viz/d3viz.py
+2
-3
callcache.py
theano/gof/callcache.py
+4
-6
cmodule.py
theano/gof/cmodule.py
+6
-7
compiledir.py
theano/gof/compiledir.py
+21
-29
compilelock.py
theano/gof/compilelock.py
+2
-3
buildbot_filter.py
theano/misc/buildbot_filter.py
+2
-1
check_duplicate_key.py
theano/misc/check_duplicate_key.py
+4
-6
check_whitespace.py
theano/misc/hooks/check_whitespace.py
+8
-12
reindent.py
theano/misc/hooks/reindent.py
+2
-3
nvcc_compiler.py
theano/sandbox/cuda/nvcc_compiler.py
+3
-4
scan_perform_ext.py
theano/scan_module/scan_perform_ext.py
+4
-2
test_scan.py
theano/scan_module/tests/test_scan.py
+2
-8
test_opt.py
theano/tensor/tests/test_opt.py
+1
-4
没有找到文件。
theano/compile/function_module.py
浏览文件 @
abc28761
...
...
@@ -1207,22 +1207,17 @@ class FunctionMaker(object):
print
(
'graph_db already exists'
)
else
:
# create graph_db
f
=
open
(
graph_db_file
,
'wb'
)
print
(
'create new graph_db in
%
s'
%
graph_db_file
)
# file needs to be open and closed for every pickle
f
.
close
()
with
open
(
graph_db_file
,
'wb'
)
as
f
:
print
(
'create new graph_db in
%
s'
%
graph_db_file
)
# load the graph_db dictionary
try
:
f
=
open
(
graph_db_file
,
'rb'
)
# Temporary hack to allow
# theano.scan_module.tests.test_scan.T_Scan to
# finish. Should be changed in definitive version.
tmp
=
theano
.
config
.
unpickle_function
theano
.
config
.
unpickle_function
=
False
graph_db
=
pickle
.
load
(
f
)
# hack end
f
.
close
()
with
open
(
graph_db_file
,
'rb'
)
as
f
:
# Temporary hack to allow
# theano.scan_module.tests.test_scan.T_Scan to
# finish. Should be changed in definitive version.
tmp
=
theano
.
config
.
unpickle_function
theano
.
config
.
unpickle_function
=
False
graph_db
=
pickle
.
load
(
f
)
print
(
'graph_db loaded and it is not empty'
)
except
EOFError
as
e
:
# the file has nothing in it
...
...
@@ -1351,9 +1346,8 @@ class FunctionMaker(object):
before_opt
=
self
.
fgraph
.
clone
(
check_integrity
=
False
)
optimizer_profile
=
optimizer
(
self
.
fgraph
)
graph_db
.
update
({
before_opt
:
self
.
fgraph
})
f
=
open
(
graph_db_file
,
'wb'
)
pickle
.
dump
(
graph_db
,
f
,
-
1
)
f
.
close
()
with
open
(
graph_db_file
,
'wb'
)
as
f
:
pickle
.
dump
(
graph_db
,
f
,
-
1
)
print
(
'new graph saved into graph_db'
)
release_lock
()
return
optimizer_profile
...
...
theano/compile/tests/test_function.py
浏览文件 @
abc28761
...
...
@@ -18,9 +18,8 @@ def test_function_dump():
tmpdir
=
tempfile
.
mkdtemp
()
fname
=
os
.
path
.
join
(
tmpdir
,
'test_function_dump.pkl'
)
theano
.
function_dump
(
fname
,
[
v
],
v
+
1
)
f
=
open
(
fname
,
'rb'
)
l
=
pickle
.
load
(
f
)
f
.
close
()
with
open
(
fname
,
'rb'
)
as
f
:
l
=
pickle
.
load
(
f
)
finally
:
if
tmpdir
is
not
None
:
shutil
.
rmtree
(
tmpdir
)
...
...
theano/d3viz/d3viz.py
浏览文件 @
abc28761
...
...
@@ -84,9 +84,8 @@ def d3viz(fct, outfile, copy_deps=True, *args, **kwargs):
# Read template HTML file
template_file
=
os
.
path
.
join
(
__path__
,
'html'
,
'template.html'
)
f
=
open
(
template_file
)
template
=
f
.
read
()
f
.
close
()
with
open
(
template_file
)
as
f
:
template
=
f
.
read
()
# Copy dependencies to output directory
src_deps
=
__path__
...
...
theano/gof/callcache.py
浏览文件 @
abc28761
...
...
@@ -10,18 +10,16 @@ class CallCache(object):
try
:
if
filename
is
None
:
raise
IOError
(
'bad filename'
)
# just goes to except
f
=
open
(
filename
,
'r'
)
self
.
cache
=
pickle
.
load
(
f
)
f
.
close
()
with
open
(
filename
,
'r'
)
as
f
:
self
.
cache
=
pickle
.
load
(
f
)
except
IOError
:
self
.
cache
=
{}
def
persist
(
self
,
filename
=
None
):
if
filename
is
None
:
filename
=
self
.
filename
f
=
open
(
filename
,
'w'
)
pickle
.
dump
(
self
.
cache
,
f
)
f
.
close
()
with
open
(
filename
,
'w'
)
as
f
:
pickle
.
dump
(
self
.
cache
,
f
)
def
call
(
self
,
fn
,
args
=
(),
key
=
None
):
if
key
is
None
:
...
...
theano/gof/cmodule.py
浏览文件 @
abc28761
...
...
@@ -2112,15 +2112,14 @@ class GCC_compiler(Compiler):
lib_dirs
.
append
(
python_lib
)
cppfilename
=
os
.
path
.
join
(
location
,
'mod.cpp'
)
cppfile
=
open
(
cppfilename
,
'w'
)
with
open
(
cppfilename
,
'w'
)
as
cppfile
:
_logger
.
debug
(
'Writing module C++ code to
%
s'
,
cppfilename
)
_logger
.
debug
(
'Writing module C++ code to
%
s'
,
cppfilename
)
cppfile
.
write
(
src_code
)
# Avoid gcc warning "no newline at end of file".
if
not
src_code
.
endswith
(
'
\n
'
):
cppfile
.
write
(
'
\n
'
)
cppfile
.
close
()
cppfile
.
write
(
src_code
)
# Avoid gcc warning "no newline at end of file".
if
not
src_code
.
endswith
(
'
\n
'
):
cppfile
.
write
(
'
\n
'
)
lib_filename
=
os
.
path
.
join
(
location
,
...
...
theano/gof/compiledir.py
浏览文件 @
abc28761
...
...
@@ -349,35 +349,27 @@ def print_compiledir_content():
total_key_sizes
=
0
nb_keys
=
{}
for
dir
in
os
.
listdir
(
compiledir
):
file
=
None
try
:
try
:
filename
=
os
.
path
.
join
(
compiledir
,
dir
,
"key.pkl"
)
file
=
open
(
filename
,
'rb'
)
keydata
=
pickle
.
load
(
file
)
ops
=
list
(
set
([
x
for
x
in
flatten
(
keydata
.
keys
)
if
isinstance
(
x
,
theano
.
gof
.
Op
)]))
if
len
(
ops
)
==
0
:
zeros_op
+=
1
elif
len
(
ops
)
>
1
:
more_than_one_ops
+=
1
else
:
types
=
list
(
set
([
x
for
x
in
flatten
(
keydata
.
keys
)
if
isinstance
(
x
,
theano
.
gof
.
Type
)]))
table
.
append
((
dir
,
ops
[
0
],
types
))
size
=
os
.
path
.
getsize
(
filename
)
total_key_sizes
+=
size
if
size
>
max_key_file_size
:
big_key_files
.
append
((
dir
,
size
,
ops
))
nb_keys
.
setdefault
(
len
(
keydata
.
keys
),
0
)
nb_keys
[
len
(
keydata
.
keys
)]
+=
1
except
IOError
:
pass
finally
:
if
file
is
not
None
:
file
.
close
()
filename
=
os
.
path
.
join
(
compiledir
,
dir
,
"key.pkl"
)
with
open
(
filename
,
'rb'
)
as
file
:
keydata
=
pickle
.
load
(
file
)
ops
=
list
(
set
([
x
for
x
in
flatten
(
keydata
.
keys
)
if
isinstance
(
x
,
theano
.
gof
.
Op
)]))
if
len
(
ops
)
==
0
:
zeros_op
+=
1
elif
len
(
ops
)
>
1
:
more_than_one_ops
+=
1
else
:
types
=
list
(
set
([
x
for
x
in
flatten
(
keydata
.
keys
)
if
isinstance
(
x
,
theano
.
gof
.
Type
)]))
table
.
append
((
dir
,
ops
[
0
],
types
))
size
=
os
.
path
.
getsize
(
filename
)
total_key_sizes
+=
size
if
size
>
max_key_file_size
:
big_key_files
.
append
((
dir
,
size
,
ops
))
nb_keys
.
setdefault
(
len
(
keydata
.
keys
),
0
)
nb_keys
[
len
(
keydata
.
keys
)]
+=
1
print
(
"List of
%
d compiled individual ops in this theano cache
%
s:"
%
(
len
(
table
),
compiledir
))
...
...
theano/gof/compilelock.py
浏览文件 @
abc28761
...
...
@@ -339,9 +339,8 @@ def refresh_lock(lock_file):
''
.
join
([
str
(
random
.
randint
(
0
,
9
))
for
i
in
range
(
10
)]),
hostname
)
try
:
lock_write
=
open
(
lock_file
,
'w'
)
lock_write
.
write
(
unique_id
+
'
\n
'
)
lock_write
.
close
()
with
open
(
lock_file
,
'w'
)
as
lock_write
:
lock_write
.
write
(
unique_id
+
'
\n
'
)
except
Exception
:
# In some strange case, this happen. To prevent all tests
# from failing, we release the lock, but as there is a
...
...
theano/misc/buildbot_filter.py
浏览文件 @
abc28761
...
...
@@ -24,6 +24,7 @@ if __name__ == "__main__":
import
pdb
pdb
.
set_trace
()
if
len
(
sys
.
argv
)
>
1
:
print
(
filter_output
(
open
(
sys
.
argv
[
1
])))
with
open
(
sys
.
argv
[
1
])
as
f
:
print
(
filter_output
(
f
))
else
:
print
(
filter_output
(
sys
.
stdin
))
theano/misc/check_duplicate_key.py
浏览文件 @
abc28761
...
...
@@ -23,9 +23,8 @@ for dir in dirs:
key
=
None
try
:
f
=
open
(
os
.
path
.
join
(
dir
,
"key.pkl"
))
key
=
f
.
read
()
f
.
close
()
with
open
(
os
.
path
.
join
(
dir
,
"key.pkl"
))
as
f
:
key
=
f
.
read
()
keys
.
setdefault
(
key
,
0
)
keys
[
key
]
+=
1
del
f
...
...
@@ -36,9 +35,8 @@ for dir in dirs:
path
=
os
.
path
.
join
(
dir
,
"mod.cpp"
)
if
not
os
.
path
.
exists
(
path
):
path
=
os
.
path
.
join
(
dir
,
"mod.cu"
)
f
=
open
(
path
)
mod
=
f
.
read
()
f
.
close
()
with
open
(
path
)
as
f
:
mod
=
f
.
read
()
mods
.
setdefault
(
mod
,
())
mods
[
mod
]
+=
(
key
,)
del
mod
...
...
theano/misc/hooks/check_whitespace.py
浏览文件 @
abc28761
...
...
@@ -145,31 +145,27 @@ def get_file_contents(filename, revision="tip"):
def
save_commit_message
(
filename
):
commit_message
=
run_mercurial_command
(
"tip --template '{desc}'"
)
save_file
=
open
(
filename
,
"w"
)
save_file
.
write
(
commit_message
)
save_file
.
close
()
with
open
(
filename
,
"w"
)
as
save_file
:
save_file
.
write
(
commit_message
)
def
save_diffs
(
diffs
,
filename
):
diff
=
"
\n\n
"
.
join
(
diffs
)
diff_file
=
open
(
filename
,
"w"
)
diff_file
.
write
(
diff
)
diff_file
.
close
()
with
open
(
filename
,
"w"
)
as
diff_file
:
diff_file
.
write
(
diff
)
def
should_skip_commit
():
if
not
os
.
path
.
exists
(
SKIP_WHITESPACE_CHECK_FILENAME
):
return
False
whitespace_check_file
=
open
(
SKIP_WHITESPACE_CHECK_FILENAME
,
"r"
)
whitespace_check_changeset
=
whitespace_check_file
.
read
()
whitespace_check_file
.
close
()
with
open
(
SKIP_WHITESPACE_CHECK_FILENAME
,
"r"
)
as
whitespace_check_file
:
whitespace_check_changeset
=
whitespace_check_file
.
read
()
return
whitespace_check_changeset
==
parent_commit
()
def
save_skip_next_commit
():
whitespace_check_file
=
open
(
SKIP_WHITESPACE_CHECK_FILENAME
,
"w"
)
whitespace_check_file
.
write
(
parent_commit
())
whitespace_check_file
.
close
()
with
open
(
SKIP_WHITESPACE_CHECK_FILENAME
,
"w"
)
as
whitespace_check_file
:
whitespace_check_file
.
write
(
parent_commit
())
def
main
(
argv
=
None
):
...
...
theano/misc/hooks/reindent.py
浏览文件 @
abc28761
...
...
@@ -132,9 +132,8 @@ def check(file):
shutil
.
copyfile
(
file
,
bak
)
if
verbose
:
print
(
"backed up"
,
file
,
"to"
,
bak
)
f
=
open
(
file
,
"w"
)
r
.
write
(
f
)
f
.
close
()
with
open
(
file
,
"w"
)
as
f
:
r
.
write
(
f
)
if
verbose
:
print
(
"wrote new"
,
file
)
return
True
...
...
theano/sandbox/cuda/nvcc_compiler.py
浏览文件 @
abc28761
...
...
@@ -301,12 +301,11 @@ class NVCC_compiler(Compiler):
lib_dirs
.
append
(
python_lib
)
cppfilename
=
os
.
path
.
join
(
location
,
'mod.cu'
)
cppfile
=
open
(
cppfilename
,
'w'
)
with
open
(
cppfilename
,
'w'
)
as
cppfile
:
_logger
.
debug
(
'Writing module C++ code to
%
s'
,
cppfilename
)
_logger
.
debug
(
'Writing module C++ code to
%
s'
,
cppfilename
)
cppfile
.
write
(
src_code
)
cppfile
.
write
(
src_code
)
cppfile
.
close
()
lib_filename
=
os
.
path
.
join
(
location
,
'
%
s.
%
s'
%
(
module_name
,
get_lib_extension
()))
...
...
theano/scan_module/scan_perform_ext.py
浏览文件 @
abc28761
...
...
@@ -76,7 +76,8 @@ except ImportError:
)
raise
ImportError
(
"The file lazylinker_c.c is not available."
)
code
=
open
(
cfile
)
.
read
()
with
open
(
cfile
)
as
f
:
code
=
f
.
read
()
loc
=
os
.
path
.
join
(
config
.
compiledir
,
dirname
)
if
not
os
.
path
.
exists
(
loc
):
try
:
...
...
@@ -114,7 +115,8 @@ except ImportError:
hide_symbols
=
False
)
# Save version into the __init__.py file.
init_py
=
os
.
path
.
join
(
loc
,
'__init__.py'
)
open
(
init_py
,
'w'
)
.
write
(
'_version =
%
s
\n
'
%
version
)
with
open
(
init_py
,
'w'
)
as
f
:
f
.
write
(
'_version =
%
s
\n
'
%
version
)
# If we just compiled the module for the first time, then it was
# imported at the same time: we need to make sure we do not
# reload the now outdated __init__.pyc below.
...
...
theano/scan_module/tests/test_scan.py
浏览文件 @
abc28761
...
...
@@ -250,16 +250,10 @@ class T_Scan(unittest.TestCase):
tmpdir
=
mkdtemp
()
os
.
chdir
(
tmpdir
)
f_out
=
open
(
'tmp_scan_test_pickle.pkl'
,
'wb'
)
try
:
with
open
(
'tmp_scan_test_pickle.pkl'
,
'wb'
)
as
f_out
:
pickle
.
dump
(
_my_f
,
f_out
,
protocol
=-
1
)
finally
:
f_out
.
close
()
f_in
=
open
(
'tmp_scan_test_pickle.pkl'
,
'rb'
)
try
:
with
open
(
'tmp_scan_test_pickle.pkl'
,
'rb'
)
as
f_in
:
my_f
=
pickle
.
load
(
f_in
)
finally
:
f_in
.
close
()
finally
:
# Get back to the original dir, and delete the temporary one.
os
.
chdir
(
origdir
)
...
...
theano/tensor/tests/test_opt.py
浏览文件 @
abc28761
...
...
@@ -3674,16 +3674,13 @@ class test_shapeoptimizer(unittest.TestCase):
# Due to incompatibilities between python 2 and 3 in the format
# of pickled numpy ndarray, we have to force an encoding
from
theano.misc.pkl_utils
import
CompatUnpickler
pkl_file
=
open
(
pkl_filename
,
"rb"
)
try
:
with
open
(
pkl_filename
,
"rb"
)
as
pkl_file
:
if
PY3
:
u
=
CompatUnpickler
(
pkl_file
,
encoding
=
"latin1"
)
else
:
u
=
CompatUnpickler
(
pkl_file
)
fn_args
=
u
.
load
()
theano
.
function
(
**
fn_args
)
finally
:
pkl_file
.
close
()
class
test_assert
(
utt
.
InferShapeTester
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论