Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
0ea10588
提交
0ea10588
authored
10月 17, 2020
作者:
Brandon T. Willard
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move get_test_value method to the Variable (sub)classes
The test value computation steps were also extracted from `PureOp.__call__` and put into a stand-alone `compute_test_value` function.
上级
03b82c26
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
37 行增加
和
4 行删除
+37
-4
sharedvalue.py
theano/compile/sharedvalue.py
+3
-0
__init__.py
theano/gof/__init__.py
+8
-1
graph.py
theano/gof/graph.py
+23
-0
op.py
theano/gof/op.py
+0
-0
scan.py
theano/scan_module/scan.py
+3
-3
没有找到文件。
theano/compile/sharedvalue.py
浏览文件 @
0ea10588
...
@@ -150,6 +150,9 @@ class SharedVariable(Variable):
...
@@ -150,6 +150,9 @@ class SharedVariable(Variable):
else
:
else
:
self
.
container
.
value
=
copy
.
deepcopy
(
new_value
)
self
.
container
.
value
=
copy
.
deepcopy
(
new_value
)
def
get_test_value
(
self
):
return
self
.
get_value
(
borrow
=
True
,
return_internal_type
=
True
)
def
zero
(
self
,
borrow
=
False
):
def
zero
(
self
,
borrow
=
False
):
"""
"""
Set the values of a shared variable to 0.
Set the values of a shared variable to 0.
...
...
theano/gof/__init__.py
浏览文件 @
0ea10588
...
@@ -58,7 +58,14 @@ from theano.gof.link import (
...
@@ -58,7 +58,14 @@ from theano.gof.link import (
WrapLinkerMany
,
WrapLinkerMany
,
)
)
from
theano.gof.op
import
Op
,
OpenMPOp
,
PureOp
,
COp
,
ops_with_inner_function
from
theano.gof.op
import
(
Op
,
OpenMPOp
,
PureOp
,
COp
,
ops_with_inner_function
,
get_test_value
,
)
from
theano.gof.type
import
EnumType
,
EnumList
,
CEnumType
from
theano.gof.type
import
EnumType
,
EnumList
,
CEnumType
...
...
theano/gof/graph.py
浏览文件 @
0ea10588
...
@@ -383,19 +383,39 @@ class Variable(Node):
...
@@ -383,19 +383,39 @@ class Variable(Node):
self
.
tag
=
utils
.
ValidatingScratchpad
(
"test_value"
,
type
.
filter
)
self
.
tag
=
utils
.
ValidatingScratchpad
(
"test_value"
,
type
.
filter
)
self
.
type
=
type
self
.
type
=
type
if
owner
is
not
None
and
not
isinstance
(
owner
,
Apply
):
if
owner
is
not
None
and
not
isinstance
(
owner
,
Apply
):
raise
TypeError
(
"owner must be an Apply instance"
,
owner
)
raise
TypeError
(
"owner must be an Apply instance"
,
owner
)
self
.
owner
=
owner
self
.
owner
=
owner
if
index
is
not
None
and
not
isinstance
(
index
,
integer_types
):
if
index
is
not
None
and
not
isinstance
(
index
,
integer_types
):
raise
TypeError
(
"index must be an int"
,
index
)
raise
TypeError
(
"index must be an int"
,
index
)
self
.
index
=
index
self
.
index
=
index
if
name
is
not
None
and
not
isinstance
(
name
,
string_types
):
if
name
is
not
None
and
not
isinstance
(
name
,
string_types
):
raise
TypeError
(
"name must be a string"
,
name
)
raise
TypeError
(
"name must be a string"
,
name
)
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
)
Variable
.
notify_construction_observers
(
self
)
def
get_test_value
(
self
):
"""Get the test value.
Raises
------
AttributeError
"""
if
not
hasattr
(
self
.
tag
,
"test_value"
):
detailed_err_msg
=
utils
.
get_variable_trace_string
(
self
)
raise
AttributeError
(
"{} has no test value {}"
.
format
(
self
,
detailed_err_msg
)
)
return
self
.
tag
.
test_value
def
__str__
(
self
):
def
__str__
(
self
):
"""Return a str representation of the Variable."""
"""Return a str representation of the Variable."""
if
self
.
name
is
not
None
:
if
self
.
name
is
not
None
:
...
@@ -583,6 +603,9 @@ class Constant(Variable):
...
@@ -583,6 +603,9 @@ class Constant(Variable):
self
.
data
=
type
.
filter
(
data
)
self
.
data
=
type
.
filter
(
data
)
utils
.
add_tag_trace
(
self
)
utils
.
add_tag_trace
(
self
)
def
get_test_value
(
self
):
return
self
.
data
def
equals
(
self
,
other
):
def
equals
(
self
,
other
):
# this does what __eq__ should do, but Variable and Apply should always be hashable by id
# this does what __eq__ should do, but Variable and Apply should always be hashable by id
return
isinstance
(
other
,
Constant
)
and
self
.
signature
()
==
other
.
signature
()
return
isinstance
(
other
,
Constant
)
and
self
.
signature
()
==
other
.
signature
()
...
...
theano/gof/op.py
浏览文件 @
0ea10588
差异被折叠。
点击展开。
theano/scan_module/scan.py
浏览文件 @
0ea10588
...
@@ -523,7 +523,7 @@ def scan(
...
@@ -523,7 +523,7 @@ def scan(
# Try to transfer test_value to the new variable
# Try to transfer test_value to the new variable
if
config
.
compute_test_value
!=
"off"
:
if
config
.
compute_test_value
!=
"off"
:
try
:
try
:
nw_slice
.
tag
.
test_value
=
gof
.
Op
.
_
get_test_value
(
_seq_val_slice
)
nw_slice
.
tag
.
test_value
=
gof
.
get_test_value
(
_seq_val_slice
)
except
AttributeError
as
e
:
except
AttributeError
as
e
:
if
config
.
compute_test_value
!=
"ignore"
:
if
config
.
compute_test_value
!=
"ignore"
:
# No need to print a warning or raise an error now,
# No need to print a warning or raise an error now,
...
@@ -655,7 +655,7 @@ def scan(
...
@@ -655,7 +655,7 @@ def scan(
# Try to transfer test_value to the new variable
# Try to transfer test_value to the new variable
if
config
.
compute_test_value
!=
"off"
:
if
config
.
compute_test_value
!=
"off"
:
try
:
try
:
arg
.
tag
.
test_value
=
gof
.
Op
.
_
get_test_value
(
actual_arg
)
arg
.
tag
.
test_value
=
gof
.
get_test_value
(
actual_arg
)
except
AttributeError
as
e
:
except
AttributeError
as
e
:
if
config
.
compute_test_value
!=
"ignore"
:
if
config
.
compute_test_value
!=
"ignore"
:
# No need to print a warning or raise an error now,
# No need to print a warning or raise an error now,
...
@@ -716,7 +716,7 @@ def scan(
...
@@ -716,7 +716,7 @@ def scan(
# Try to transfer test_value to the new variable
# Try to transfer test_value to the new variable
if
config
.
compute_test_value
!=
"off"
:
if
config
.
compute_test_value
!=
"off"
:
try
:
try
:
nw_slice
.
tag
.
test_value
=
gof
.
Op
.
_
get_test_value
(
nw_slice
.
tag
.
test_value
=
gof
.
get_test_value
(
_init_out_var_slice
_init_out_var_slice
)
)
except
AttributeError
as
e
:
except
AttributeError
as
e
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论