Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
39269c13
提交
39269c13
authored
5月 28, 2017
作者:
Tim Cooijmans
提交者:
Reyhane Askari
8月 25, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add context manager to trace constructed Variables, inherit stack traces
上级
9bc05a38
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
47 行增加
和
0 行删除
+47
-0
graph.py
theano/gof/graph.py
+28
-0
opt.py
theano/gof/opt.py
+19
-0
没有找到文件。
theano/gof/graph.py
浏览文件 @
39269c13
...
@@ -4,6 +4,7 @@ Node classes (`Apply`, `Variable`) and expression graph algorithms.
...
@@ -4,6 +4,7 @@ Node classes (`Apply`, `Variable`) and expression graph algorithms.
from
__future__
import
absolute_import
,
print_function
,
division
from
__future__
import
absolute_import
,
print_function
,
division
from
collections
import
deque
from
collections
import
deque
import
contextlib
from
copy
import
copy
from
copy
import
copy
from
itertools
import
count
from
itertools
import
count
...
@@ -390,6 +391,8 @@ class Variable(Node):
...
@@ -390,6 +391,8 @@ class Variable(Node):
self
.
name
=
name
self
.
name
=
name
self
.
auto_name
=
'auto_'
+
str
(
next
(
self
.
__count__
))
self
.
auto_name
=
'auto_'
+
str
(
next
(
self
.
__count__
))
Variable
.
notify_construction_observers
(
self
)
def
__str__
(
self
):
def
__str__
(
self
):
"""Return a str representation of the Variable.
"""Return a str representation of the Variable.
...
@@ -536,6 +539,21 @@ class Variable(Node):
...
@@ -536,6 +539,21 @@ class Variable(Node):
d
[
"tag"
]
=
t
d
[
"tag"
]
=
t
return
d
return
d
construction_observers
=
[]
@classmethod
def
append_construction_observer
(
cls
,
observer
):
cls
.
construction_observers
.
append
(
observer
)
@classmethod
def
remove_construction_observer
(
cls
,
observer
):
cls
.
construction_observers
.
remove
(
observer
)
@classmethod
def
notify_construction_observers
(
cls
,
instance
):
for
observer
in
cls
.
construction_observers
:
observer
(
instance
)
class
Constant
(
Variable
):
class
Constant
(
Variable
):
"""
"""
...
@@ -1426,3 +1444,13 @@ def is_in_ancestors(l_node, f_node):
...
@@ -1426,3 +1444,13 @@ def is_in_ancestors(l_node, f_node):
todo
.
append
(
cur
)
todo
.
append
(
cur
)
todo
.
extend
(
i
.
owner
for
i
in
cur
.
inputs
if
i
.
owner
)
todo
.
extend
(
i
.
owner
for
i
in
cur
.
inputs
if
i
.
owner
)
return
False
return
False
@contextlib.contextmanager
def
nodes_constructed
():
new_nodes
=
[]
def
observer
(
node
):
new_nodes
.
append
(
node
)
Variable
.
append_construction_observer
(
observer
)
yield
new_nodes
Variable
.
remove_construction_observer
(
observer
)
theano/gof/opt.py
浏览文件 @
39269c13
...
@@ -6,6 +6,7 @@ amount of useful generic optimization tools.
...
@@ -6,6 +6,7 @@ amount of useful generic optimization tools.
from
__future__
import
absolute_import
,
print_function
,
division
from
__future__
import
absolute_import
,
print_function
,
division
from
collections
import
deque
,
defaultdict
,
OrderedDict
from
collections
import
deque
,
defaultdict
,
OrderedDict
import
contextlib
import
copy
import
copy
import
inspect
import
inspect
import
logging
import
logging
...
@@ -2976,6 +2977,24 @@ def with_stack_trace(from_var, to_var):
...
@@ -2976,6 +2977,24 @@ def with_stack_trace(from_var, to_var):
copy_stack_trace
(
from_var
,
to_var
)
copy_stack_trace
(
from_var
,
to_var
)
return
to_var
return
to_var
@contextlib.contextmanager
def
inherit_stack_trace
(
from_var
):
"""
Contextmanager that copies the stack trace from one or more tensor variables to all tensor
variables constructed in the body.
Parameters
----------
from_var
Tensor variable or list of tensor variables to copy stack traces from.
"""
with
graph
.
nodes_constructed
()
as
new_nodes
:
yield
copy_stack_trace
(
from_var
,
new_nodes
)
def
check_stack_trace
(
f_or_fgraph
,
ops_to_check
=
'last'
,
bug_print
=
'raise'
):
def
check_stack_trace
(
f_or_fgraph
,
ops_to_check
=
'last'
,
bug_print
=
'raise'
):
"""
"""
This function checks if the outputs of specific ops of a compiled graph
This function checks if the outputs of specific ops of a compiled graph
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论