Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
a2941943
提交
a2941943
authored
7月 13, 2015
作者:
Iban Harlouchet
提交者:
Frederic
7月 22, 2015
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
flake8 of theano/gof/op.py; 3 E left
上级
d9166080
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
45 行增加
和
48 行删除
+45
-48
op.py
theano/gof/op.py
+45
-47
test_flake8.py
theano/tests/test_flake8.py
+0
-1
没有找到文件。
theano/gof/op.py
浏览文件 @
a2941943
...
@@ -4,14 +4,6 @@ The `Op` class is the base interface for all operations
...
@@ -4,14 +4,6 @@ The `Op` class is the base interface for all operations
compatible with `gof`'s :doc:`graph` routines.
compatible with `gof`'s :doc:`graph` routines.
"""
"""
__authors__
=
"theano-dev"
__copyright__
=
"(c) 2010, Universite de Montreal"
__license__
=
"3-clause BSD License"
__contact__
=
"theano-dev <theano-dev@googlegroups.com>"
__docformat__
=
"restructuredtext en"
import
inspect
import
inspect
import
logging
import
logging
import
numpy
import
numpy
...
@@ -32,6 +24,13 @@ from theano.gof import utils
...
@@ -32,6 +24,13 @@ from theano.gof import utils
from
theano.gof.cmodule
import
GCC_compiler
from
theano.gof.cmodule
import
GCC_compiler
from
theano.gof.fg
import
FunctionGraph
from
theano.gof.fg
import
FunctionGraph
__authors__
=
"theano-dev"
__copyright__
=
"(c) 2010, Universite de Montreal"
__license__
=
"3-clause BSD License"
__contact__
=
"theano-dev <theano-dev@googlegroups.com>"
__docformat__
=
"restructuredtext en"
class
CLinkerObject
(
object
):
class
CLinkerObject
(
object
):
"""Standard elements of an Op or Type used with the CLinker
"""Standard elements of an Op or Type used with the CLinker
...
@@ -224,8 +223,7 @@ class CLinkerOp(CLinkerObject):
...
@@ -224,8 +223,7 @@ class CLinkerOp(CLinkerObject):
- `MethodNotDefined`: the subclass does not override this method
- `MethodNotDefined`: the subclass does not override this method
"""
"""
raise
utils
.
MethodNotDefined
(
'
%
s.c_code'
\
raise
utils
.
MethodNotDefined
(
'
%
s.c_code'
%
self
.
__class__
.
__name__
)
%
self
.
__class__
.
__name__
)
def
c_code_cache_version_apply
(
self
,
node
):
def
c_code_cache_version_apply
(
self
,
node
):
"""Return a tuple of integers indicating the version of this Op.
"""Return a tuple of integers indicating the version of this Op.
...
@@ -278,8 +276,8 @@ class CLinkerOp(CLinkerObject):
...
@@ -278,8 +276,8 @@ class CLinkerOp(CLinkerObject):
:Exceptions:
:Exceptions:
- `MethodNotDefined`: the subclass does not override this method
- `MethodNotDefined`: the subclass does not override this method
"""
"""
raise
utils
.
MethodNotDefined
(
'
%
s.c_code_cleanup'
\
raise
utils
.
MethodNotDefined
(
'
%
s.c_code_cleanup'
%
%
self
.
__class__
.
__name__
)
self
.
__class__
.
__name__
)
def
c_support_code_apply
(
self
,
node
,
name
):
def
c_support_code_apply
(
self
,
node
,
name
):
"""Optional: Return utility code for use by an `Op` that will be
"""Optional: Return utility code for use by an `Op` that will be
...
@@ -302,7 +300,7 @@ class CLinkerOp(CLinkerObject):
...
@@ -302,7 +300,7 @@ class CLinkerOp(CLinkerObject):
"""
"""
raise
utils
.
MethodNotDefined
(
"c_support_code_apply"
,
raise
utils
.
MethodNotDefined
(
"c_support_code_apply"
,
type
(
self
),
self
.
__class__
.
__name__
)
type
(
self
),
self
.
__class__
.
__name__
)
def
c_init_code_apply
(
self
,
node
,
name
):
def
c_init_code_apply
(
self
,
node
,
name
):
"""
"""
...
@@ -362,7 +360,7 @@ class CLinkerOp(CLinkerObject):
...
@@ -362,7 +360,7 @@ class CLinkerOp(CLinkerObject):
"""
"""
raise
utils
.
MethodNotDefined
(
"c_support_code_struct"
,
raise
utils
.
MethodNotDefined
(
"c_support_code_struct"
,
type
(
self
),
self
.
__class__
.
__name__
)
type
(
self
),
self
.
__class__
.
__name__
)
def
c_cleanup_code_struct
(
self
,
node
,
name
):
def
c_cleanup_code_struct
(
self
,
node
,
name
):
"""
"""
...
@@ -552,7 +550,7 @@ class PureOp(object):
...
@@ -552,7 +550,7 @@ class PureOp(object):
# compute output value once with test inputs to validate graph
# compute output value once with test inputs to validate graph
thunk
=
node
.
op
.
make_thunk
(
node
,
storage_map
,
compute_map
,
thunk
=
node
.
op
.
make_thunk
(
node
,
storage_map
,
compute_map
,
no_recycling
=
[])
no_recycling
=
[])
thunk
.
inputs
=
[
storage_map
[
v
]
for
v
in
node
.
inputs
]
thunk
.
inputs
=
[
storage_map
[
v
]
for
v
in
node
.
inputs
]
thunk
.
outputs
=
[
storage_map
[
v
]
for
v
in
node
.
outputs
]
thunk
.
outputs
=
[
storage_map
[
v
]
for
v
in
node
.
outputs
]
...
@@ -615,11 +613,11 @@ class PureOp(object):
...
@@ -615,11 +613,11 @@ class PureOp(object):
"""
"""
raise
NotImplementedError
(
raise
NotImplementedError
(
"
%
s of class
%
s does not "
"
%
s of class
%
s does not "
"implement R_op. If this is a theano op, write to the "
"implement R_op. If this is a theano op, write to the "
"theano-dev mailing list for assistance. If it is your "
"theano-dev mailing list for assistance. If it is your "
"own op, implement the R_op method."
%
"own op, implement the R_op method."
%
(
self
,
self
.
__class__
.
__name__
))
(
self
,
self
.
__class__
.
__name__
))
def
perform
(
self
,
node
,
inputs
,
output_storage
):
def
perform
(
self
,
node
,
inputs
,
output_storage
):
"""
"""
...
@@ -716,7 +714,7 @@ class Op(utils.object2, PureOp, CLinkerOp):
...
@@ -716,7 +714,7 @@ class Op(utils.object2, PureOp, CLinkerOp):
return
getattr
(
t
,
'dtype'
,
''
)
==
'float16'
return
getattr
(
t
,
'dtype'
,
''
)
==
'float16'
if
(
any
(
is_f16
(
i
.
type
)
for
i
in
node
.
inputs
)
or
if
(
any
(
is_f16
(
i
.
type
)
for
i
in
node
.
inputs
)
or
any
(
is_f16
(
o
.
type
)
for
o
in
node
.
outputs
)):
any
(
is_f16
(
o
.
type
)
for
o
in
node
.
outputs
)):
print
(
"Disabling C code for
%
s due to unsupported "
print
(
"Disabling C code for
%
s due to unsupported "
"float16"
%
(
self
,))
"float16"
%
(
self
,))
raise
NotImplementedError
(
"float16"
)
raise
NotImplementedError
(
"float16"
)
...
@@ -763,6 +761,7 @@ class Op(utils.object2, PureOp, CLinkerOp):
...
@@ -763,6 +761,7 @@ class Op(utils.object2, PureOp, CLinkerOp):
return
r
return
r
else
:
else
:
ctx_val
=
node
.
context_type
.
filter
(
ctx
)
ctx_val
=
node
.
context_type
.
filter
(
ctx
)
def
rval
(
p
=
p
,
i
=
node_input_storage
,
o
=
node_output_storage
,
n
=
node
,
def
rval
(
p
=
p
,
i
=
node_input_storage
,
o
=
node_output_storage
,
n
=
node
,
ctx
=
ctx_val
):
ctx
=
ctx_val
):
r
=
p
(
n
,
[
x
[
0
]
for
x
in
i
],
o
,
ctx
)
r
=
p
(
n
,
[
x
[
0
]
for
x
in
i
],
o
,
ctx
)
...
@@ -994,10 +993,10 @@ int main( int argc, const char* argv[] )
...
@@ -994,10 +993,10 @@ int main( int argc, const char* argv[] )
}
}
"""
"""
default_openmp
=
GCC_compiler
.
try_compile_tmp
(
default_openmp
=
GCC_compiler
.
try_compile_tmp
(
src_code
=
code
,
src_code
=
code
,
tmp_prefix
=
'test_omp_'
,
tmp_prefix
=
'test_omp_'
,
flags
=
[
'-fopenmp'
],
flags
=
[
'-fopenmp'
],
try_run
=
False
)
try_run
=
False
)
return
default_openmp
return
default_openmp
def
update_self_openmp
(
self
):
def
update_self_openmp
(
self
):
...
@@ -1065,10 +1064,10 @@ class COp(Op):
...
@@ -1065,10 +1064,10 @@ class COp(Op):
backward_re
=
re
.
compile
(
r'^THEANO_(APPLY|SUPPORT)_CODE_SECTION$'
,
re
.
MULTILINE
)
backward_re
=
re
.
compile
(
r'^THEANO_(APPLY|SUPPORT)_CODE_SECTION$'
,
re
.
MULTILINE
)
# This is the set of allowed markers
# This is the set of allowed markers
SECTIONS
=
set
([
SECTIONS
=
set
([
'init_code'
,
'init_code_apply'
,
'init_code_struct'
,
'init_code'
,
'init_code_apply'
,
'init_code_struct'
,
'support_code'
,
'support_code_apply'
,
'support_code_struct'
,
'support_code'
,
'support_code_apply'
,
'support_code_struct'
,
'cleanup_code_struct'
,
'cleanup_code_struct'
,
'code'
,
'code_cleanup'
])
'code'
,
'code_cleanup'
])
@classmethod
@classmethod
def
get_path
(
cls
,
f
):
def
get_path
(
cls
,
f
):
...
@@ -1141,9 +1140,9 @@ class COp(Op):
...
@@ -1141,9 +1140,9 @@ class COp(Op):
n
=
1
n
=
1
while
n
<
len
(
split
):
while
n
<
len
(
split
):
if
split
[
n
]
==
'APPLY'
:
if
split
[
n
]
==
'APPLY'
:
self
.
code_sections
[
'support_code_apply'
]
=
split
[
n
+
1
]
self
.
code_sections
[
'support_code_apply'
]
=
split
[
n
+
1
]
elif
split
[
n
]
==
'SUPPORT'
:
elif
split
[
n
]
==
'SUPPORT'
:
self
.
code_sections
[
'support_code'
]
=
split
[
n
+
1
]
self
.
code_sections
[
'support_code'
]
=
split
[
n
+
1
]
n
+=
2
n
+=
2
continue
continue
...
@@ -1164,7 +1163,7 @@ class COp(Op):
...
@@ -1164,7 +1163,7 @@ class COp(Op):
(
self
.
func_files
[
i
],
split
[
n
]))
(
self
.
func_files
[
i
],
split
[
n
]))
if
split
[
n
]
not
in
self
.
code_sections
:
if
split
[
n
]
not
in
self
.
code_sections
:
self
.
code_sections
[
split
[
n
]]
=
""
self
.
code_sections
[
split
[
n
]]
=
""
self
.
code_sections
[
split
[
n
]]
+=
split
[
n
+
1
]
self
.
code_sections
[
split
[
n
]]
+=
split
[
n
+
1
]
n
+=
2
n
+=
2
else
:
else
:
...
@@ -1267,8 +1266,8 @@ class COp(Op):
...
@@ -1267,8 +1266,8 @@ class COp(Op):
def
get_sub_macros
(
self
,
sub
):
def
get_sub_macros
(
self
,
sub
):
define_macros
=
[]
define_macros
=
[]
undef_macros
=
[]
undef_macros
=
[]
define_macros
.
append
(
"#define FAIL
%
s"
%
define_macros
.
append
(
"#define FAIL
%
s"
%
(
(
self
.
_lquote_macro
(
sub
[
'fail'
]),))
self
.
_lquote_macro
(
sub
[
'fail'
]),))
undef_macros
.
append
(
"#undef FAIL"
)
undef_macros
.
append
(
"#undef FAIL"
)
if
'context'
in
sub
:
if
'context'
in
sub
:
define_macros
.
append
(
"#define CONTEXT
%
s"
%
(
sub
[
'context'
],))
define_macros
.
append
(
"#define CONTEXT
%
s"
%
(
sub
[
'context'
],))
...
@@ -1305,25 +1304,24 @@ class COp(Op):
...
@@ -1305,25 +1304,24 @@ class COp(Op):
def
c_code
(
self
,
node
,
name
,
inp
,
out
,
sub
):
def
c_code
(
self
,
node
,
name
,
inp
,
out
,
sub
):
if
self
.
func_name
is
not
None
:
if
self
.
func_name
is
not
None
:
assert
'code'
not
in
self
.
code_sections
assert
'code'
not
in
self
.
code_sections
func_name
=
self
.
func_name
func_args
=
self
.
format_c_function_args
(
inp
,
out
)
fail
=
sub
[
'fail'
]
define_macros
,
undef_macros
=
self
.
get_c_macros
(
node
,
name
,
define_macros
,
undef_macros
=
self
.
get_c_macros
(
node
,
name
,
check_input
=
False
)
check_input
=
False
)
# Generate the C code
# Generate the C code
return
"""
return
"""
%(define_macros)
s
%(define_macros)
s
{
{
if (
%(func_name)
s(
%(func_args)
s) != 0) {
if (
%(func_name)
s(
%(func_args)
s) != 0) {
%(fail)
s
%(fail)
s
}
}
}
}
%(undef_macros)
s
%(undef_macros)
s
"""
%
dict
(
func_name
=
self
.
func_name
,
fail
=
sub
[
'fail'
],
"""
%
dict
(
func_name
=
self
.
func_name
,
func_args
=
self
.
format_c_function_args
(
inp
,
out
),
fail
=
sub
[
'fail'
],
define_macros
=
define_macros
,
undef_macros
=
undef_macros
)
func_args
=
self
.
format_c_function_args
(
inp
,
out
),
define_macros
=
define_macros
,
undef_macros
=
undef_macros
)
else
:
else
:
if
'code'
in
self
.
code_sections
:
if
'code'
in
self
.
code_sections
:
op_code
=
self
.
code_sections
[
'code'
]
op_code
=
self
.
code_sections
[
'code'
]
...
...
theano/tests/test_flake8.py
浏览文件 @
a2941943
...
@@ -225,7 +225,6 @@ whitelist_flake8 = [
...
@@ -225,7 +225,6 @@ whitelist_flake8 = [
"sparse/sandbox/sp.py"
,
"sparse/sandbox/sp.py"
,
"gof/unify.py"
,
"gof/unify.py"
,
"gof/__init__.py"
,
"gof/__init__.py"
,
"gof/op.py"
,
"gof/tests/test_cmodule.py"
,
"gof/tests/test_cmodule.py"
,
"gof/tests/test_destroyhandler.py"
,
"gof/tests/test_destroyhandler.py"
,
"gof/tests/test_opt.py"
,
"gof/tests/test_opt.py"
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论