Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
c9ee9d37
提交
c9ee9d37
authored
3月 01, 2012
作者:
Olivier Delalleau
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
A few PEP8 fixes
Also fixed some small typos and replaced a zip by izip.
上级
2068a94b
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
46 行增加
和
26 行删除
+46
-26
debugmode.py
theano/compile/debugmode.py
+46
-26
没有找到文件。
theano/compile/debugmode.py
浏览文件 @
c9ee9d37
...
...
@@ -6,6 +6,7 @@
__docformat__
=
"restructuredtext en"
import
time
,
copy
,
sys
,
copy_reg
,
gc
,
os
from
itertools
import
izip
from
StringIO
import
StringIO
import
numpy
...
...
@@ -1931,35 +1932,39 @@ class _Maker(FunctionMaker): # inheritance buys a few helper functions
"""
Create a function.
defaults -> a list matching the inputs list and providing default
values
if the default for an input is None, then that input is a
required input. For an input with an update, the default
acts as initialization.
defaults -> a list matching the inputs list and providing default
values if the default for an input is None, then that input
is a required input. For an input with an update, the
default
acts as initialization.
trustme -> disables some exceptions, used internally
"""
if
defaults
is
None
:
defaults
=
[
None
]
*
len
(
self
.
inputs
)
input_storage
=
[]
# list of independent one-element lists, will be passed to the linker
# List of independent one-element lists, will be passed to the linker.
input_storage
=
[]
_defaults
=
[]
# The following loop is to fill in the input_storage and _defaults lists.
for
(
input
,
indices
,
subinputs
),
default
in
zip
(
self
.
indices
,
defaults
):
# The following loop is to fill in the input_storage and _defaults
# lists.
for
(
input
,
indices
,
subinputs
),
default
in
izip
(
self
.
indices
,
defaults
):
__default
=
default
if
isinstance
(
default
,
gof
.
Container
):
# If the default is a gof.Container, this means we want to
share
#
the same storage. This is done by appending default.storage
#
to input_storage
# If the default is a gof.Container, this means we want to
#
share the same storage. This is done by appending
#
default.storage to input_storage.
if
indices
is
not
None
:
raise
TypeError
(
"Cannot take a Container instance as default for a SymbolicInputKit."
)
raise
TypeError
(
"Cannot take a Container instance as "
"default for a SymbolicInputKit."
)
input_storage
.
append
(
default
.
storage
)
default
=
None
required
=
False
elif
isinstance
(
input
,
SymbolicInputKit
):
# If the input is a SymbolicInputKit, it represents more than
# one storage unit. The indices and subinputs lists represent
which
#
of the kit's inputs are active in this graph, so we make as many
# storage units as needed
# one storage unit. The indices and subinputs lists represent
#
which of the kit's inputs are active in this graph, so we
#
make as many
storage units as needed
if
isinstance
(
default
,
(
list
,
tuple
))
\
and
all
(
isinstance
(
x
,
gof
.
Container
)
for
x
in
default
):
if
len
(
default
)
==
len
(
indices
):
...
...
@@ -1967,7 +1972,9 @@ class _Maker(FunctionMaker): # inheritance buys a few helper functions
elif
len
(
default
)
>
len
(
indices
):
input_storage
+=
[
default
[
i
]
.
storage
for
i
in
indices
]
else
:
raise
ValueError
(
'Not enough storage for SymbolicInputKit'
,
input
,
indices
,
default
)
raise
ValueError
(
'Not enough storage for SymbolicInputKit'
,
input
,
indices
,
default
)
default
=
_NODEFAULT
else
:
input_storage
+=
[[
None
]
for
i
in
indices
]
...
...
@@ -1977,8 +1984,10 @@ class _Maker(FunctionMaker): # inheritance buys a few helper functions
# Filling _defaults. Each entry is a tuple of three elements:
# (required, refeed, value)
# - required means that the user must provide a value when calling the function
# - refeed means that we want to put the default back in the storage after each function call
# - required means that the user must provide a value when calling
# the function
# - refeed means that we want to put the default back in the
# storage after each function call
# - value is the value that will be put in the storage initially
# Even though a SymbolicInputKit represents more than one input,
...
...
@@ -2001,7 +2010,9 @@ class _Maker(FunctionMaker): # inheritance buys a few helper functions
_defaults
.
append
((
False
,
False
,
None
))
else
:
# This might catch some bugs early
raise
ValueError
(
"A default (initial) value is required for an input which can update itself."
,
input
)
raise
ValueError
(
"A default (initial) value is required for an "
"input which can update itself."
,
input
)
else
:
_defaults
.
append
((
False
,
False
,
default
))
else
:
...
...
@@ -2066,8 +2077,8 @@ class DebugMode(Mode):
If there are internal errors, this mode will raise an
`DebugModeError` exception.
:remark: The work of debugging is implemented by the `_Maker`, `_Linker`,
and
`_VariableEquivalenceTracker` classes.
:remark: The work of debugging is implemented by the `_Maker`, `_Linker`,
and
`_VariableEquivalenceTracker` classes.
"""
...
...
@@ -2084,7 +2095,8 @@ class DebugMode(Mode):
check_py_code
=
config
.
DebugMode
.
check_py
"""
Should we evaluate (and check) the `perform` implementations? Always checked if no `c_code`.
Should we evaluate (and check) the `perform` implementations?
Always checked if no `c_code`.
"""
check_isfinite
=
config
.
DebugMode
.
check_finite
...
...
@@ -2102,7 +2114,9 @@ class DebugMode(Mode):
# This function will be used to create a FunctionMaker in
# function_module.function
def
function_maker
(
self
,
i
,
o
,
m
,
*
args
,
**
kwargs
):
"""Return an instance of `_Maker` which handles much of the debugging work"""
"""
Return an instance of `_Maker` which handles much of the debugging work
"""
assert
m
is
self
return
_Maker
(
i
,
o
,
self
.
optimizer
,
self
,
*
args
,
**
kwargs
)
...
...
@@ -2114,13 +2128,18 @@ class DebugMode(Mode):
check_isfinite
=
None
,
require_matching_strides
=
None
,
linker
=
None
):
"""Initialize member variables.
If any of these arguments (except optimizer) is not None, it overrides the class default.
The linker arguments is not used. It is set their to allow Mode.requiring() and some other fct to work with DebugMode too.
If any of these arguments (except optimizer) is not None, it overrides
the class default.
The linker argument is not used. It is set there to allow
Mode.requiring() and some other fct to work with DebugMode too.
"""
if
linker
is
not
None
and
not
issubclass
(
linker
,
_Linker
):
raise
Exception
(
"DebugMode can use only its own linker! Don't give him one to use it."
,
linker
)
raise
Exception
(
"DebugMode can only use its own linker! You "
"should not provide one."
,
linker
)
super
(
DebugMode
,
self
)
.
__init__
(
optimizer
=
optimizer
,
...
...
@@ -2142,6 +2161,7 @@ class DebugMode(Mode):
self
.
require_matching_strides
=
require_matching_strides
if
not
(
self
.
check_c_code
or
self
.
check_py_code
):
raise
ValueError
(
'DebugMode has to check at least one of c and py code'
)
raise
ValueError
(
'DebugMode has to check at least one of c and py '
'code'
)
register_mode
(
'DEBUG_MODE'
,
DebugMode
(
optimizer
=
'fast_run'
))
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论