Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
66dc1578
提交
66dc1578
authored
4月 13, 2015
作者:
Arnaud Bergeron
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make printing.py pass test_flake8
上级
837f6ad6
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
26 行增加
和
48 行删除
+26
-48
printing.py
theano/printing.py
+26
-47
test_flake8.py
theano/tests/test_flake8.py
+0
-1
没有找到文件。
theano/printing.py
浏览文件 @
66dc1578
...
...
@@ -8,11 +8,9 @@ import logging
import
os
import
sys
import
warnings
# Not available on all platforms
hashlib
=
None
import
hashlib
import
numpy
np
=
numpy
import
numpy
as
np
try
:
import
pydot
as
pd
...
...
@@ -106,7 +104,7 @@ def debugprint(obj, depth=-1, print_type=False,
results_to_print
.
extend
(
obj
.
outputs
)
profile_list
.
extend
([
None
for
item
in
obj
.
outputs
])
order
=
obj
.
toposort
()
elif
isinstance
(
obj
,
(
int
,
long
,
float
,
n
umpy
.
ndarray
)):
elif
isinstance
(
obj
,
(
int
,
long
,
float
,
n
p
.
ndarray
)):
print
obj
elif
isinstance
(
obj
,
(
theano
.
In
,
theano
.
Out
)):
results_to_print
.
append
(
obj
.
variable
)
...
...
@@ -296,8 +294,8 @@ class OperatorPrinter:
input_strings
=
[]
max_i
=
len
(
node
.
inputs
)
-
1
for
i
,
input
in
enumerate
(
node
.
inputs
):
if
(
self
.
assoc
==
'left'
and
i
!=
0
or
self
.
assoc
==
'right'
and
i
!=
max_i
):
if
(
self
.
assoc
==
'left'
and
i
!=
0
or
self
.
assoc
==
'right'
and
i
!=
max_i
):
s
=
pprinter
.
process
(
input
,
pstate
.
clone
(
precedence
=
self
.
precedence
+
1e-6
))
else
:
...
...
@@ -334,8 +332,9 @@ class PatternPrinter:
pattern
,
precedences
=
self
.
patterns
[
idx
]
precedences
+=
(
1000
,)
*
len
(
node
.
inputs
)
pp_process
=
lambda
input
,
precedence
:
pprinter
.
process
(
input
,
pstate
.
clone
(
precedence
=
precedence
))
def
pp_process
(
input
,
precedence
):
return
pprinter
.
process
(
input
,
pstate
.
clone
(
precedence
=
precedence
))
d
=
dict
((
str
(
i
),
x
)
for
i
,
x
in
enumerate
(
pp_process
(
input
,
precedence
)
for
input
,
precedence
in
...
...
@@ -416,15 +415,14 @@ class LeafPrinter:
class
PPrinter
:
def
__init__
(
self
):
self
.
printers
=
[]
def
assign
(
self
,
condition
,
printer
):
if
isinstance
(
condition
,
gof
.
Op
):
op
=
condition
condition
=
(
lambda
pstate
,
r
:
r
.
owner
is
not
None
and
r
.
owner
.
op
==
op
)
condition
=
(
lambda
pstate
,
r
:
r
.
owner
is
not
None
and
r
.
owner
.
op
==
op
)
self
.
printers
.
insert
(
0
,
(
condition
,
printer
))
def
process
(
self
,
r
,
pstate
=
None
):
...
...
@@ -460,14 +458,12 @@ class PPrinter:
map
(
str
,
list
(
inputs
)
+
updates
.
keys
())))]
else
:
strings
=
[]
pprinter
=
self
.
clone_assign
(
lambda
pstate
,
r
:
r
.
name
is
not
None
and
r
is
not
current
,
LeafPrinter
())
pprinter
=
self
.
clone_assign
(
lambda
pstate
,
r
:
r
.
name
is
not
None
and
r
is
not
current
,
LeafPrinter
())
inv_updates
=
dict
((
b
,
a
)
for
(
a
,
b
)
in
updates
.
iteritems
())
i
=
1
for
node
in
gof
.
graph
.
io_toposort
(
list
(
inputs
)
+
updates
.
keys
(),
list
(
outputs
)
+
updates
.
values
()):
list
(
outputs
)
+
updates
.
values
()):
for
output
in
node
.
outputs
:
if
output
in
inv_updates
:
name
=
str
(
inv_updates
[
output
])
...
...
@@ -532,8 +528,8 @@ else:
pprint
=
PPrinter
()
pprint
.
assign
(
lambda
pstate
,
r
:
True
,
DefaultPrinter
())
pprint
.
assign
(
lambda
pstate
,
r
:
hasattr
(
pstate
,
'target'
)
and
pstate
.
target
is
not
r
and
r
.
name
is
not
None
,
pprint
.
assign
(
lambda
pstate
,
r
:
hasattr
(
pstate
,
'target'
)
and
pstate
.
target
is
not
r
and
r
.
name
is
not
None
,
LeafPrinter
())
pp
=
pprint
...
...
@@ -643,8 +639,8 @@ def pydotprint(fct, outfile=None,
if
isinstance
(
fct
,
Function
):
mode
=
fct
.
maker
.
mode
profile
=
getattr
(
fct
,
"profile"
,
None
)
if
(
not
isinstance
(
mode
,
ProfileMode
)
or
fct
not
in
mode
.
profile_stats
):
if
(
not
isinstance
(
mode
,
ProfileMode
)
or
fct
not
in
mode
.
profile_stats
):
mode
=
None
outputs
=
fct
.
maker
.
fgraph
.
outputs
topo
=
fct
.
maker
.
fgraph
.
toposort
()
...
...
@@ -679,8 +675,8 @@ def pydotprint(fct, outfile=None,
c3
=
pd
.
Cluster
(
'Middle'
)
cond
=
None
for
node
in
topo
:
if
(
node
.
op
.
__class__
.
__name__
==
'IfElse'
and
node
.
op
.
name
==
cond_highlight
):
if
(
node
.
op
.
__class__
.
__name__
==
'IfElse'
and
node
.
op
.
name
==
cond_highlight
):
cond
=
node
if
cond
is
None
:
_logger
.
warn
(
"pydotprint: cond_highlight is set but there is no"
...
...
@@ -719,17 +715,17 @@ def pydotprint(fct, outfile=None,
else
:
varstr
=
'name='
+
var
.
name
+
" "
+
str
(
var
.
type
)
elif
isinstance
(
var
,
gof
.
Constant
):
dstr
=
'val='
+
str
(
n
umpy
.
asarray
(
var
.
data
))
dstr
=
'val='
+
str
(
n
p
.
asarray
(
var
.
data
))
if
'
\n
'
in
dstr
:
dstr
=
dstr
[:
dstr
.
index
(
'
\n
'
)]
varstr
=
'
%
s
%
s'
%
(
dstr
,
str
(
var
.
type
))
elif
(
var
in
input_update
and
input_update
[
var
]
.
variable
.
name
is
not
None
):
elif
(
var
in
input_update
and
input_update
[
var
]
.
variable
.
name
is
not
None
):
if
var_with_name_simple
:
varstr
=
input_update
[
var
]
.
variable
.
name
+
" UPDATE"
else
:
varstr
=
(
input_update
[
var
]
.
variable
.
name
+
" UPDATE "
+
str
(
var
.
type
))
varstr
=
(
input_update
[
var
]
.
variable
.
name
+
" UPDATE "
+
str
(
var
.
type
))
else
:
# a var id is needed as otherwise var with the same type will be
# merged in the graph.
...
...
@@ -784,8 +780,8 @@ def pydotprint(fct, outfile=None,
if
(
applystr
in
all_strings
)
or
with_ids
:
idx
=
' id='
+
str
(
topo
.
index
(
node
))
if
len
(
applystr
)
+
len
(
idx
)
>
max_label_size
:
applystr
=
(
applystr
[:
max_label_size
-
3
-
len
(
idx
)]
+
idx
+
'...'
)
applystr
=
(
applystr
[:
max_label_size
-
3
-
len
(
idx
)]
+
idx
+
'...'
)
else
:
applystr
=
applystr
+
idx
elif
len
(
applystr
)
>
max_label_size
:
...
...
@@ -1220,15 +1216,6 @@ def var_descriptor(obj, _prev_obs=None, _tag_generator=None):
how a variable is computed. Does not include any memory
location dependent information such as the id of a node.
"""
global
hashlib
if
hashlib
is
None
:
try
:
import
hashlib
except
ImportError
:
raise
RuntimeError
(
"Can't run var_descriptor because hashlib is not available."
)
if
_prev_obs
is
None
:
_prev_obs
=
{}
...
...
@@ -1294,14 +1281,6 @@ def hex_digest(x):
"""
Returns a short, mostly hexadecimal hash of a numpy ndarray
"""
global
hashlib
if
hashlib
is
None
:
try
:
import
hashlib
except
ImportError
:
raise
RuntimeError
(
"Can't run hex_digest"
"because hashlib is not available."
)
assert
isinstance
(
x
,
np
.
ndarray
)
rval
=
hashlib
.
md5
(
x
.
tostring
())
.
hexdigest
()
# hex digest must be annotated with strides to avoid collisions
...
...
theano/tests/test_flake8.py
浏览文件 @
66dc1578
...
...
@@ -323,7 +323,6 @@ whitelist_flake8 = [
"gof/sandbox/equilibrium.py"
,
"sandbox/cuda/opt_util.py"
,
"gof/tests/test_utils.py"
,
"printing.py"
,
"raise_op.py"
,
"tests/test_flake8.py"
,
"misc/pkl_utils.py"
,
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论