Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
7f6a333b
提交
7f6a333b
authored
10月 02, 2011
作者:
goodfeli
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #83 from dwf/misc_pep8
Misc style fixes in op.py
上级
2cbba6b9
8f92ab47
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
23 行增加
和
23 行删除
+23
-23
op.py
theano/gof/op.py
+23
-23
没有找到文件。
theano/gof/op.py
浏览文件 @
7f6a333b
...
...
@@ -15,8 +15,6 @@ __docformat__ = "restructuredtext en"
import
logging
import
warnings
import
numpy
import
theano
from
theano
import
config
...
...
@@ -142,7 +140,6 @@ class CLinkerObject(object):
"""
return
self
.
c_code_cache_version
()
def
c_compile_args
(
self
):
"""Optional: Return a list of compile args recommended to compile the
code returned by other methods in this class.
...
...
@@ -176,6 +173,7 @@ class CLinkerObject(object):
"""
raise
utils
.
MethodNotDefined
(
"c_no_compile_args"
,
type
(
self
),
self
.
__class__
.
__name__
)
class
CLinkerOp
(
CLinkerObject
):
"""
Interface definition for `Op` subclasses compiled by `CLinker`.
...
...
@@ -415,7 +413,7 @@ class PureOp(object):
no_recycling
=
[])
required
=
thunk
()
assert
not
required
# We provided all inputs
assert
not
required
# We provided all inputs
for
output
in
node
.
outputs
:
# Check that the output has been computed
...
...
@@ -469,6 +467,7 @@ class PureOp(object):
"""
raise
utils
.
MethodNotDefined
(
"perform"
,
type
(
self
),
self
.
__class__
.
__name__
)
class
Op
(
utils
.
object2
,
PureOp
,
CLinkerOp
):
"""Convenience class to bundle `PureOp` and `CLinkerOp`"""
def
__new__
(
cls
,
*
args
,
**
kwargs
):
...
...
@@ -521,13 +520,15 @@ class Op(utils.object2, PureOp, CLinkerOp):
no_recycling
=
e_no_recycling
)
logger
.
debug
(
'Trying CLinker.make_thunk'
)
fill_storage
,
node_input_filters
,
node_output_filters
=
cl
.
make_thunk
(
input_storage
=
node_input_storage
,
output_storage
=
node_output_storage
)
outputs
=
cl
.
make_thunk
(
input_storage
=
node_input_storage
,
output_storage
=
node_output_storage
)
fill_storage
,
node_input_filters
,
node_output_filters
=
outputs
def
rval
():
fill_storage
()
for
o
in
node
.
outputs
:
compute_map
[
o
][
0
]
=
True
rval
.
cthunk
=
fill_storage
.
cthunk
rval
.
inputs
=
node_input_storage
rval
.
outputs
=
node_output_storage
...
...
@@ -540,11 +541,13 @@ class Op(utils.object2, PureOp, CLinkerOp):
p
=
node
.
op
.
perform
# default arguments are stored in the closure of `rval`
def
rval
(
p
=
p
,
i
=
node_input_storage
,
o
=
node_output_storage
,
n
=
node
):
r
=
p
(
n
,
[
x
[
0
]
for
x
in
i
],
o
)
for
o
in
node
.
outputs
:
compute_map
[
o
][
0
]
=
True
return
r
rval
.
inputs
=
node_input_storage
rval
.
outputs
=
node_output_storage
rval
.
perform
=
p
...
...
@@ -567,6 +570,7 @@ def get_test_value(v):
v_tensor
=
theano
.
tensor
.
as_tensor_variable
(
v
)
return
PureOp
.
_get_test_value
(
v_tensor
)
def
missing_test_message
(
msg
):
""" Displays msg, a message saying that some test_value is missing,
in the appropriate form based on config.compute_test_value:
...
...
@@ -577,16 +581,14 @@ def missing_test_message(msg):
warn: display msg as a warning
raise: raise an AttributeError with msg as the exception text
"""
action
=
config
.
compute_test_value
if
action
==
'raise'
:
raise
AttributeError
(
msg
)
elif
action
==
'warn'
:
warnings
.
warn
(
msg
,
stacklevel
=
2
)
warnings
.
warn
(
msg
,
stacklevel
=
2
)
else
:
assert
action
in
[
'ignore'
,
'off'
]
assert
action
in
[
'ignore'
,
'off'
]
def
debug_error_message
(
msg
):
""" Displays a message saying that an error was found in some
...
...
@@ -598,28 +600,24 @@ def debug_error_message(msg):
#this message should never be called when the debugger is off
assert
action
!=
'off'
if
action
in
[
'raise'
,
'ignore'
]:
if
action
in
[
'raise'
,
'ignore'
]:
raise
ValueError
(
msg
)
else
:
assert
action
==
'warn'
warnings
.
warn
(
msg
,
stacklevel
=
2
)
warnings
.
warn
(
msg
,
stacklevel
=
2
)
def
debug_assert
(
condition
,
msg
):
def
debug_assert
(
condition
,
msg
):
if
not
condition
:
action
=
config
.
compute_test_value
if
action
in
[
'raise'
,
'ignore'
]:
raise
AssertionError
(
msg
)
else
:
assert
action
==
'warn'
warnings
.
warn
(
msg
,
stacklevel
=
2
)
warnings
.
warn
(
msg
,
stacklevel
=
2
)
def
get_debug_values
(
*
args
):
""" Given a list of variables, does one of three things:
1. If the interactive debugger is off, returns an empty list
...
...
@@ -649,9 +647,11 @@ def get_debug_values(*args):
rval
.
append
(
get_test_value
(
arg
))
except
AttributeError
:
if
hasattr
(
arg
,
'name'
)
and
arg
.
name
is
not
None
:
missing_test_message
(
"Argument "
+
str
(
i
)
+
"('"
+
arg
.
name
+
"') has no test value"
)
missing_test_message
(
"Argument "
+
str
(
i
)
+
"('"
+
arg
.
name
+
"') has no test value"
)
else
:
missing_test_message
(
"Argument "
+
str
(
i
)
+
" has no test value"
)
missing_test_message
(
"Argument "
+
str
(
i
)
+
" has no test value"
)
return
[]
return
[
tuple
(
rval
)
]
return
[
tuple
(
rval
)
]
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论