Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
be23ebcf
提交
be23ebcf
authored
2月 29, 2012
作者:
lamblin
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #495 from nouiz/debugprint_id2
Debugprint id2
上级
9ca0033f
8888cd7b
显示空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
197 行增加
和
41 行删除
+197
-41
NEWS.txt
NEWS.txt
+9
-0
basic.txt
doc/library/tensor/basic.txt
+5
-3
gradients.txt
doc/tutorial/gradients.txt
+1
-0
debugmode.py
theano/compile/debugmode.py
+73
-14
printing.py
theano/printing.py
+14
-23
test_printing.py
theano/tests/test_printing.py
+95
-1
没有找到文件。
NEWS.txt
浏览文件 @
be23ebcf
...
@@ -17,6 +17,15 @@ Interface change
...
@@ -17,6 +17,15 @@ Interface change
``on_unused_input={'raise', 'warn', 'ignore'}`` to control this.
``on_unused_input={'raise', 'warn', 'ignore'}`` to control this.
(Pascal L.)
(Pascal L.)
New Feature
* debugprint new param ids=["CHAR","id","int",""]
This make the identifier printed to be the python id, a uniq char, a
unit int, or not have it printed. We changed the default to be "CHAR"
as this is more readable.
* debugprint new param stop_on_name=[False,True]. If True, we don't print
anything bellow an intermediate variable that have a name. Default to False.
* debugprint now stop printing the "|" symbol in a columns after the last input.
=============
=============
Release Notes
Release Notes
=============
=============
...
...
doc/library/tensor/basic.txt
浏览文件 @
be23ebcf
...
@@ -1187,12 +1187,14 @@ Gradient / Differentiation
...
@@ -1187,12 +1187,14 @@ Gradient / Differentiation
:returns: gradients of the cost with respect to each of the `wrt` terms
:returns: gradients of the cost with respect to each of the `wrt` terms
.. _R_op_list:
R op
====
List of Implemented R op
========================
See the tutorial for the R op documentation.
See the :ref:`gradient tutorial <tutcomputinggrads>` for the R op documentation.
list of ops that support R-op:
list of ops that support R-op:
* with test [Most is tensor/tests/test_rop.py]
* with test [Most is tensor/tests/test_rop.py]
...
...
doc/tutorial/gradients.txt
浏览文件 @
be23ebcf
...
@@ -200,6 +200,7 @@ you need to do something similar to this:
...
@@ -200,6 +200,7 @@ you need to do something similar to this:
>>> f([[1,1],[1,1]], [[2,2,],[2,2]], [0,1])
>>> f([[1,1],[1,1]], [[2,2,],[2,2]], [0,1])
array([ 2., 2.])
array([ 2., 2.])
:ref:`List <R_op_list>` of Op that implement Rop.
L-operator
L-operator
----------
----------
...
...
theano/compile/debugmode.py
浏览文件 @
be23ebcf
...
@@ -480,32 +480,79 @@ class InvalidValueError(DebugModeError):
...
@@ -480,32 +480,79 @@ class InvalidValueError(DebugModeError):
########################
########################
def
char_from_number
(
number
):
""" Converts number to string by rendering it in base 26 using
capital letters as digits """
base
=
26
rval
=
""
if
number
==
0
:
rval
=
'A'
while
number
!=
0
:
remainder
=
number
%
base
new_char
=
chr
(
ord
(
'A'
)
+
remainder
)
rval
=
new_char
+
rval
number
/=
base
return
rval
def
debugprint
(
r
,
prefix
=
''
,
depth
=-
1
,
done
=
None
,
print_type
=
False
,
def
debugprint
(
r
,
prefix
=
''
,
depth
=-
1
,
done
=
None
,
print_type
=
False
,
file
=
sys
.
stdout
,
print_destroy_map
=
False
,
print_view_map
=
False
,
file
=
sys
.
stdout
,
print_destroy_map
=
False
,
print_view_map
=
False
,
order
=
[]):
order
=
[],
ids
=
'CHAR'
,
stop_on_name
=
False
,
prefix_child
=
None
):
"""Print the graph leading to `r` to given depth.
"""Print the graph leading to `r` to given depth.
:param r: Variable instance
:param r: Variable instance
:param prefix: prefix to each line (typically some number of spaces)
:param prefix: prefix to each line (typically some number of spaces)
:param depth: maximum recursion depth (Default -1 for unlimited).
:param depth: maximum recursion depth (Default -1 for unlimited).
:param done: set of Apply instances that have already been printed
:param done: dict of Apply instances that have already been printed
and there associated printed ids
:param print_type: wether to print the Variable type after the other infos
:param print_type: wether to print the Variable type after the other infos
:param file: file-like object to which to print
:param file: file-like object to which to print
:param print_destroy_map: wether to print the op destroy_map after ofther info
:param print_destroy_map: wether to print the op destroy_map after ofther info
:param print_view_map: wether to print the op view_map after ofther info
:param print_view_map: wether to print the op view_map after ofther info
:param order: If not empty will print the index in the toposort.
:param order: If not empty will print the index in the toposort.
:param ids: How do we print the identifier of the variable
id - print the python id value
int - print integer character
CHAR - print capital character
"" - don't print an identifier
:param stop_on_name: When True, if a node in the graph have a name,
we don't print anything below it.
"""
"""
if
depth
==
0
:
if
depth
==
0
:
return
return
if
done
is
None
:
if
done
is
None
:
done
=
se
t
()
done
=
dic
t
()
if
print_type
:
if
print_type
:
type_str
=
' <
%
s>'
%
r
.
type
type_str
=
' <
%
s>'
%
r
.
type
else
:
else
:
type_str
=
''
type_str
=
''
if
prefix_child
is
None
:
prefix_child
=
prefix
def
get_id_str
(
obj
):
if
obj
in
done
:
id_str
=
"[@
%
s]"
%
done
[
obj
]
elif
ids
==
"id"
:
id_str
=
"[@
%
s]"
%
str
(
id
(
r
))
elif
ids
==
"int"
:
id_str
=
"[@
%
s]"
%
str
(
len
(
done
))
elif
ids
==
"CHAR"
:
id_str
=
"[@
%
s]"
%
char_from_number
(
len
(
done
))
elif
ids
==
""
:
id_str
=
""
done
[
obj
]
=
id_str
return
id_str
if
hasattr
(
r
.
owner
,
'op'
):
if
hasattr
(
r
.
owner
,
'op'
):
# this variable is the output of computation,
# this variable is the output of computation,
# so just print out the apply
# so just print out the apply
...
@@ -534,29 +581,41 @@ def debugprint(r, prefix='', depth=-1, done=None, print_type=False,
...
@@ -534,29 +581,41 @@ def debugprint(r, prefix='', depth=-1, done=None, print_type=False,
o
=
''
o
=
''
if
order
:
if
order
:
o
=
str
(
order
.
index
(
r
.
owner
))
o
=
str
(
order
.
index
(
r
.
owner
))
already_printed
=
a
in
done
# get_id_str put it in the dict
id_str
=
get_id_str
(
a
)
if
len
(
a
.
outputs
)
==
1
:
if
len
(
a
.
outputs
)
==
1
:
print
>>
file
,
'
%
s
%
s
[@
%
i]
%
s
\'
%
s
\'
%
s
%
s
%
s'
%
(
prefix
,
a
.
op
,
print
>>
file
,
'
%
s
%
s
%
s
%
s
\'
%
s
\'
%
s
%
s
%
s'
%
(
prefix
,
a
.
op
,
id
(
r
)
,
id
_str
,
type_str
,
r_name
,
type_str
,
r_name
,
destroy_map_str
,
destroy_map_str
,
view_map_str
,
view_map_str
,
o
)
o
)
else
:
else
:
print
>>
file
,
'
%
s
%
s.
%
i
[@
%
i]
%
s
\'
%
s
\'
%
s
%
s
%
s'
%
(
prefix
,
a
.
op
,
print
>>
file
,
'
%
s
%
s.
%
i
%
s
%
s
\'
%
s
\'
%
s
%
s
%
s'
%
(
prefix
,
a
.
op
,
a
.
outputs
.
index
(
r
),
a
.
outputs
.
index
(
r
),
id
(
r
)
,
type_str
,
id
_str
,
type_str
,
r_name
,
r_name
,
destroy_map_str
,
destroy_map_str
,
view_map_str
,
view_map_str
,
o
)
o
)
if
id
(
a
)
not
in
done
:
if
not
already_printed
:
done
.
add
(
id
(
a
))
if
(
not
stop_on_name
or
for
i
in
a
.
inputs
:
not
(
hasattr
(
r
,
'name'
)
and
r
.
name
is
not
None
)):
debugprint
(
i
,
prefix
+
' |'
,
depth
=
depth
-
1
,
done
=
done
,
new_prefix
=
prefix_child
+
' |'
print_type
=
print_type
,
file
=
file
,
order
=
order
)
new_prefix_child
=
prefix_child
+
' |'
for
idx
,
i
in
enumerate
(
a
.
inputs
):
if
idx
==
len
(
a
.
inputs
)
-
1
:
new_prefix_child
=
prefix_child
+
' '
debugprint
(
i
,
new_prefix
,
depth
=
depth
-
1
,
done
=
done
,
print_type
=
print_type
,
file
=
file
,
order
=
order
,
ids
=
ids
,
stop_on_name
=
stop_on_name
,
prefix_child
=
new_prefix_child
)
else
:
else
:
#this is a variable
#this is an input variable
print
>>
file
,
'
%
s
%
s [@
%
i]
%
s'
%
(
prefix
,
r
,
id
(
r
),
type_str
)
id_str
=
get_id_str
(
r
)
print
>>
file
,
'
%
s
%
s
%
s
%
s'
%
(
prefix
,
r
,
id_str
,
type_str
)
return
file
return
file
...
...
theano/printing.py
浏览文件 @
be23ebcf
...
@@ -28,7 +28,8 @@ from theano.compile.profilemode import ProfileMode
...
@@ -28,7 +28,8 @@ from theano.compile.profilemode import ProfileMode
_logger
=
logging
.
getLogger
(
"theano.printing"
)
_logger
=
logging
.
getLogger
(
"theano.printing"
)
def
debugprint
(
obj
,
depth
=-
1
,
print_type
=
False
,
file
=
None
):
def
debugprint
(
obj
,
depth
=-
1
,
print_type
=
False
,
file
=
None
,
ids
=
'CHAR'
,
stop_on_name
=
False
):
"""Print a computation graph to file
"""Print a computation graph to file
:type obj: Variable, Apply, or Function instance
:type obj: Variable, Apply, or Function instance
...
@@ -39,6 +40,14 @@ def debugprint(obj, depth=-1, print_type=False, file=None):
...
@@ -39,6 +40,14 @@ def debugprint(obj, depth=-1, print_type=False, file=None):
:param print_type: wether to print the type of printed objects
:param print_type: wether to print the type of printed objects
:type file: None, 'str', or file-like object
:type file: None, 'str', or file-like object
:param file: print to this file ('str' means to return a string)
:param file: print to this file ('str' means to return a string)
:type ids: str
:param ids: How do we print the identifier of the variable
id - print the python id value
int - print integer character
CHAR - print capital character
"" - don't print an identifier
:param stop_on_name: When True, if a node in the graph have a name,
we don't print anything below it.
:returns: string if `file` == 'str', else file arg
:returns: string if `file` == 'str', else file arg
...
@@ -64,7 +73,7 @@ def debugprint(obj, depth=-1, print_type=False, file=None):
...
@@ -64,7 +73,7 @@ def debugprint(obj, depth=-1, print_type=False, file=None):
_file
=
sys
.
stdout
_file
=
sys
.
stdout
else
:
else
:
_file
=
file
_file
=
file
done
=
se
t
()
done
=
dic
t
()
results_to_print
=
[]
results_to_print
=
[]
order
=
[]
order
=
[]
if
isinstance
(
obj
,
gof
.
Variable
):
if
isinstance
(
obj
,
gof
.
Variable
):
...
@@ -83,7 +92,8 @@ def debugprint(obj, depth=-1, print_type=False, file=None):
...
@@ -83,7 +92,8 @@ def debugprint(obj, depth=-1, print_type=False, file=None):
raise
TypeError
(
"debugprint cannot print an object of this type"
,
obj
)
raise
TypeError
(
"debugprint cannot print an object of this type"
,
obj
)
for
r
in
results_to_print
:
for
r
in
results_to_print
:
debugmode
.
debugprint
(
r
,
depth
=
depth
,
done
=
done
,
print_type
=
print_type
,
debugmode
.
debugprint
(
r
,
depth
=
depth
,
done
=
done
,
print_type
=
print_type
,
file
=
_file
,
order
=
order
)
file
=
_file
,
order
=
order
,
ids
=
ids
,
stop_on_name
=
stop_on_name
)
if
file
is
_file
:
if
file
is
_file
:
return
file
return
file
elif
file
==
'str'
:
elif
file
==
'str'
:
...
@@ -904,31 +914,12 @@ class _TagGenerator:
...
@@ -904,31 +914,12 @@ class _TagGenerator:
self
.
cur_tag_number
=
0
self
.
cur_tag_number
=
0
def
get_tag
(
self
):
def
get_tag
(
self
):
rval
=
self
.
from_number
(
self
.
cur_tag_number
)
rval
=
debugmode
.
char_
from_number
(
self
.
cur_tag_number
)
self
.
cur_tag_number
+=
1
self
.
cur_tag_number
+=
1
return
rval
return
rval
def
from_number
(
self
,
number
):
""" Converts number to string by rendering it in base 26 using
capital letters as digits """
base
=
26
rval
=
""
if
number
==
0
:
rval
=
'A'
while
number
!=
0
:
remainder
=
number
%
base
new_char
=
chr
(
ord
(
'A'
)
+
remainder
)
rval
=
new_char
+
rval
number
/=
base
return
rval
def
min_informative_str
(
obj
,
indent_level
=
0
,
def
min_informative_str
(
obj
,
indent_level
=
0
,
_prev_obs
=
None
,
_tag_generator
=
None
):
_prev_obs
=
None
,
_tag_generator
=
None
):
...
...
theano/tests/test_printing.py
浏览文件 @
be23ebcf
...
@@ -11,7 +11,7 @@ from nose.plugins.skip import SkipTest
...
@@ -11,7 +11,7 @@ from nose.plugins.skip import SkipTest
import
theano
import
theano
import
theano.tensor
as
tensor
import
theano.tensor
as
tensor
from
theano.printing
import
min_informative_str
from
theano.printing
import
min_informative_str
,
debugprint
def
test_pydotprint_cond_highlight
():
def
test_pydotprint_cond_highlight
():
...
@@ -86,3 +86,97 @@ def test_min_informative_str():
...
@@ -86,3 +86,97 @@ def test_min_informative_str():
print
'--'
+
reference
+
'--'
print
'--'
+
reference
+
'--'
assert
mis
==
reference
assert
mis
==
reference
def
test_debugprint
():
A
=
tensor
.
matrix
(
name
=
'A'
)
B
=
tensor
.
matrix
(
name
=
'B'
)
C
=
A
+
B
C
.
name
=
'C'
D
=
tensor
.
matrix
(
name
=
'D'
)
E
=
tensor
.
matrix
(
name
=
'E'
)
F
=
D
+
E
G
=
C
+
F
# just test that it work
debugprint
(
G
)
# test ids=int
s
=
StringIO
.
StringIO
()
debugprint
(
G
,
file
=
s
,
ids
=
'int'
)
s
=
s
.
getvalue
()
# The additional white space are needed!
reference
=
"""Elemwise{add,no_inplace} [@0] ''
|Elemwise{add,no_inplace} [@1] 'C'
| |A [@2]
| |B [@3]
|Elemwise{add,no_inplace} [@4] ''
|D [@5]
|E [@6]
"""
if
s
!=
reference
:
print
'--'
+
s
+
'--'
print
'--'
+
reference
+
'--'
assert
s
==
reference
# test ids=CHAR
s
=
StringIO
.
StringIO
()
debugprint
(
G
,
file
=
s
,
ids
=
'CHAR'
)
s
=
s
.
getvalue
()
# The additional white space are needed!
reference
=
"""Elemwise{add,no_inplace} [@A] ''
|Elemwise{add,no_inplace} [@B] 'C'
| |A [@C]
| |B [@D]
|Elemwise{add,no_inplace} [@E] ''
|D [@F]
|E [@G]
"""
if
s
!=
reference
:
print
'--'
+
s
+
'--'
print
'--'
+
reference
+
'--'
assert
s
==
reference
# test ids=CHAR, stop_on_name=True
s
=
StringIO
.
StringIO
()
debugprint
(
G
,
file
=
s
,
ids
=
'CHAR'
,
stop_on_name
=
True
)
s
=
s
.
getvalue
()
# The additional white space are needed!
reference
=
"""Elemwise{add,no_inplace} [@A] ''
|Elemwise{add,no_inplace} [@B] 'C'
|Elemwise{add,no_inplace} [@C] ''
|D [@D]
|E [@E]
"""
if
s
!=
reference
:
print
'--'
+
s
+
'--'
print
'--'
+
reference
+
'--'
assert
s
==
reference
# test ids=
s
=
StringIO
.
StringIO
()
debugprint
(
G
,
file
=
s
,
ids
=
''
)
s
=
s
.
getvalue
()
# The additional white space are needed!
reference
=
"""Elemwise{add,no_inplace} ''
|Elemwise{add,no_inplace} 'C'
| |A
| |B
|Elemwise{add,no_inplace} ''
|D
|E
"""
if
s
!=
reference
:
print
'--'
+
s
+
'--'
print
'--'
+
reference
+
'--'
assert
s
==
reference
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论