Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
de08b763
提交
de08b763
authored
7月 10, 2015
作者:
Iban Harlouchet
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
flake8 of theano/gof/cc.py
上级
11a78c73
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
41 行增加
和
47 行删除
+41
-47
cc.py
theano/gof/cc.py
+41
-46
test_flake8.py
theano/tests/test_flake8.py
+0
-1
没有找到文件。
theano/gof/cc.py
浏览文件 @
de08b763
"""
"""
Defines Linkers that deal with C implementations.
Defines Linkers that deal with C implementations.
"""
"""
from
__future__
import
print_function
from
__future__
import
print_function
# Python imports
# Python imports
from
copy
import
copy
from
copy
import
copy
import
os
import
os
import
sys
import
sys
from
theano.compat
import
izip
import
logging
import
numpy
import
numpy
import
theano
from
theano
import
config
from
theano.compat
import
PY3
from
theano.compat
import
PY3
from
theano.compat
import
izip
from
six
import
string_types
,
reraise
from
six
import
string_types
,
reraise
from
six.moves
import
StringIO
,
xrange
from
six.moves
import
StringIO
,
xrange
from
theano.gof.utils
import
MethodNotDefined
import
theano
# Note that we need to do this before importing cutils, since when there is
from
theano
import
config
# no theano cache dir initialized yet, importing cutils may require compilation
# of cutils_ext.
from
theano.configparser
import
AddConfigVar
,
StrParam
# gof imports
from
theano.gof
import
graph
from
theano.gof
import
link
from
theano.gof
import
utils
from
theano.gof
import
cmodule
from
theano.gof.compilelock
import
get_lock
,
release_lock
from
theano.gof.callcache
import
CallCache
AddConfigVar
(
'gcc.cxxflags'
,
"Extra compiler flags for gcc"
,
StrParam
(
""
))
if
PY3
:
if
PY3
:
import
hashlib
import
hashlib
...
@@ -41,35 +58,14 @@ else:
...
@@ -41,35 +58,14 @@ else:
assert
isinstance
(
msg
,
numpy
.
ndarray
)
assert
isinstance
(
msg
,
numpy
.
ndarray
)
return
hashlib
.
md5
(
numpy
.
getbuffer
(
msg
))
.
hexdigest
()
return
hashlib
.
md5
(
numpy
.
getbuffer
(
msg
))
.
hexdigest
()
_logger
=
logging
.
getLogger
(
"theano.gof.cc"
)
def
hash_from_file
(
file_path
):
def
hash_from_file
(
file_path
):
"""Return the MD5 hash of a file."""
"""Return the MD5 hash of a file."""
return
hash_from_code
(
open
(
file_path
,
'rb'
)
.
read
())
return
hash_from_code
(
open
(
file_path
,
'rb'
)
.
read
())
# Note that we need to do this before importing cutils, since when there is
# no theano cache dir initialized yet, importing cutils may require compilation
# of cutils_ext.
from
theano.configparser
import
AddConfigVar
,
StrParam
AddConfigVar
(
'gcc.cxxflags'
,
"Extra compiler flags for gcc"
,
StrParam
(
""
))
# gof imports
from
theano.gof
import
graph
from
theano.gof
import
link
from
theano.gof
import
utils
from
theano.gof.compilelock
import
get_lock
,
release_lock
from
theano.gof
import
cmodule
import
logging
_logger
=
logging
.
getLogger
(
"theano.gof.cc"
)
from
theano.gof.callcache
import
CallCache
run_cthunk
=
None
# Will be imported only when needed.
run_cthunk
=
None
# Will be imported only when needed.
...
@@ -314,9 +310,8 @@ def get_c_declare(r, name, sub):
...
@@ -314,9 +310,8 @@ def get_c_declare(r, name, sub):
"""Wrapper around c_declare that declares py_name"""
"""Wrapper around c_declare that declares py_name"""
if
any
([
c
!=
"output"
and
getattr
(
c
.
op
,
'check_input'
,
if
any
([
c
!=
"output"
and
getattr
(
c
.
op
,
'check_input'
,
config
.
check_input
)
for
(
c
,
_
)
in
r
.
clients
])
or
(
r
.
owner
config
.
check_input
)
for
(
c
,
_
)
in
r
.
clients
])
or
(
and
getattr
(
r
.
owner
.
op
,
'check_input'
,
True
)):
r
.
owner
and
getattr
(
r
.
owner
.
op
,
'check_input'
,
True
)):
c_declare
=
r
.
type
.
c_declare
(
name
,
sub
,
True
)
c_declare
=
r
.
type
.
c_declare
(
name
,
sub
,
True
)
else
:
else
:
c_declare
=
r
.
type
.
c_declare
(
name
,
sub
,
False
)
c_declare
=
r
.
type
.
c_declare
(
name
,
sub
,
False
)
...
@@ -840,11 +835,11 @@ class CLinker(link.Linker):
...
@@ -840,11 +835,11 @@ class CLinker(link.Linker):
# FillMissing must disable some of them. Putting -ffast-math would
# FillMissing must disable some of them. Putting -ffast-math would
# make it disable all other parameter at the same time.
# make it disable all other parameter at the same time.
ret
+=
[
"-fno-math-errno"
,
ret
+=
[
"-fno-math-errno"
,
#"-funsafe-math-optimizations",
#
"-funsafe-math-optimizations",
#"-fno-signaling-nans",
#
"-fno-signaling-nans",
#"-fcx-limited-range",
#
"-fcx-limited-range",
#"-fno-rounding-math",
#
"-fno-rounding-math",
#"-ffinite-math-only",
#
"-ffinite-math-only",
# the current code generate label event if they are not used.
# the current code generate label event if they are not used.
# Could use gcc attribute for those label only
# Could use gcc attribute for those label only
...
@@ -1335,7 +1330,6 @@ class CLinker(link.Linker):
...
@@ -1335,7 +1330,6 @@ class CLinker(link.Linker):
preargs
.
remove
(
'-DREPLACE_WITH_AMDLIBM'
)
preargs
.
remove
(
'-DREPLACE_WITH_AMDLIBM'
)
if
'amdlibm'
in
libs
:
if
'amdlibm'
in
libs
:
libs
.
remove
(
'amdlibm'
)
libs
.
remove
(
'amdlibm'
)
src_code
=
mod
.
code
()
get_lock
()
get_lock
()
try
:
try
:
_logger
.
debug
(
"LOCATION
%
s"
,
str
(
location
))
_logger
.
debug
(
"LOCATION
%
s"
,
str
(
location
))
...
@@ -1371,8 +1365,8 @@ class CLinker(link.Linker):
...
@@ -1371,8 +1365,8 @@ class CLinker(link.Linker):
code
=
self
.
instantiate_code
(
1
+
len
(
self
.
args
))
code
=
self
.
instantiate_code
(
1
+
len
(
self
.
args
))
instantiate
=
cmodule
.
ExtFunction
(
'instantiate'
,
code
,
instantiate
=
cmodule
.
ExtFunction
(
'instantiate'
,
code
,
method
=
cmodule
.
METH_VARARGS
)
method
=
cmodule
.
METH_VARARGS
)
#
['error_storage'] + argnames,
#
['error_storage'] + argnames,
#
local_dict = d,
#
local_dict = d,
# global_dict = {})
# global_dict = {})
# Static methods that can run and destroy the struct built by
# Static methods that can run and destroy the struct built by
...
@@ -1498,7 +1492,7 @@ class _CThunk(object):
...
@@ -1498,7 +1492,7 @@ class _CThunk(object):
global
run_cthunk
global
run_cthunk
if
run_cthunk
is
None
:
if
run_cthunk
is
None
:
# Lazy import to avoid compilation when importing theano.
# Lazy import to avoid compilation when importing theano.
from
theano.gof.cutils
import
run_cthunk
from
theano.gof.cutils
import
run_cthunk
# noqa
self
.
cthunk
=
cthunk
self
.
cthunk
=
cthunk
self
.
init_tasks
=
init_tasks
self
.
init_tasks
=
init_tasks
self
.
tasks
=
tasks
self
.
tasks
=
tasks
...
@@ -1534,7 +1528,8 @@ class _CThunk(object):
...
@@ -1534,7 +1528,8 @@ class _CThunk(object):
exc_value
.
__thunk_trace__
=
trace
exc_value
.
__thunk_trace__
=
trace
except
Exception
:
except
Exception
:
print
((
'ERROR retrieving error_storage.'
print
((
'ERROR retrieving error_storage.'
' Was the error set in the c code?'
),
end
=
' '
,
file
=
sys
.
stderr
)
'Was the error set in the c code?'
),
end
=
' '
,
file
=
sys
.
stderr
)
print
(
self
.
error_storage
,
file
=
sys
.
stderr
)
print
(
self
.
error_storage
,
file
=
sys
.
stderr
)
raise
raise
reraise
(
exc_type
,
exc_value
,
exc_trace
)
reraise
(
exc_type
,
exc_value
,
exc_trace
)
...
@@ -1641,8 +1636,8 @@ class OpWiseCLinker(link.LocalLinker):
...
@@ -1641,8 +1636,8 @@ class OpWiseCLinker(link.LocalLinker):
for
node
in
order
:
for
node
in
order
:
if
self
.
allow_gc
:
if
self
.
allow_gc
:
post_thunk_old_storage
.
append
(
[
storage_map
[
input
]
post_thunk_old_storage
.
append
(
for
input
in
node
.
inputs
[
storage_map
[
input
]
for
input
in
node
.
inputs
if
((
input
in
computed
)
and
if
((
input
in
computed
)
and
(
input
not
in
fgraph
.
outputs
)
and
(
input
not
in
fgraph
.
outputs
)
and
node
==
last_user
[
input
])])
node
==
last_user
[
input
])])
...
@@ -1741,12 +1736,12 @@ class DualLinker(link.Linker):
...
@@ -1741,12 +1736,12 @@ class DualLinker(link.Linker):
no_recycling
=
self
.
no_recycling
no_recycling
=
self
.
no_recycling
_f
,
i1
,
o1
,
thunks1
,
order1
=
(
_f
,
i1
,
o1
,
thunks1
,
order1
=
(
link
.
PerformLinker
(
schedule
=
self
.
schedule
)
.
accept
(
fgraph
,
link
.
PerformLinker
(
schedule
=
self
.
schedule
)
.
accept
(
no_recycling
=
no_recycling
)
.
make_all
(
**
kwargs
))
fgraph
,
no_recycling
=
no_recycling
)
.
make_all
(
**
kwargs
))
kwargs
.
pop
(
'input_storage'
,
None
)
kwargs
.
pop
(
'input_storage'
,
None
)
_f
,
i2
,
o2
,
thunks2
,
order2
=
(
_f
,
i2
,
o2
,
thunks2
,
order2
=
(
OpWiseCLinker
(
schedule
=
self
.
schedule
)
.
accept
(
fgraph
,
OpWiseCLinker
(
schedule
=
self
.
schedule
)
.
accept
(
no_recycling
=
no_recycling
)
.
make_all
(
**
kwargs
))
fgraph
,
no_recycling
=
no_recycling
)
.
make_all
(
**
kwargs
))
def
f
():
def
f
():
for
input1
,
input2
in
izip
(
i1
,
i2
):
for
input1
,
input2
in
izip
(
i1
,
i2
):
...
...
theano/tests/test_flake8.py
浏览文件 @
de08b763
...
@@ -244,7 +244,6 @@ whitelist_flake8 = [
...
@@ -244,7 +244,6 @@ whitelist_flake8 = [
"gof/unify.py"
,
"gof/unify.py"
,
"gof/graph.py"
,
"gof/graph.py"
,
"gof/__init__.py"
,
"gof/__init__.py"
,
"gof/cc.py"
,
"gof/opt.py"
,
"gof/opt.py"
,
"gof/link.py"
,
"gof/link.py"
,
"gof/fg.py"
,
"gof/fg.py"
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论