Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
1cbb3cb8
提交
1cbb3cb8
authored
9月 26, 2011
作者:
nouiz
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #59 from goodfeli/get_test_value
Added the get_test_value function
上级
e9299c5d
4d7d37d6
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
55 行增加
和
3 行删除
+55
-3
op.py
theano/gof/op.py
+19
-1
test_op.py
theano/gof/tests/test_op.py
+36
-2
没有找到文件。
theano/gof/op.py
浏览文件 @
1cbb3cb8
...
@@ -344,7 +344,7 @@ class PureOp(object):
...
@@ -344,7 +344,7 @@ class PureOp(object):
# ensure that the test value is correct
# ensure that the test value is correct
return
v
.
type
.
filter
(
v
.
tag
.
test_value
)
return
v
.
type
.
filter
(
v
.
tag
.
test_value
)
raise
AttributeError
(
'
%
s has no
t
test value'
%
v
)
raise
AttributeError
(
'
%
s has no test value'
%
v
)
def
__call__
(
self
,
*
inputs
,
**
kwargs
):
def
__call__
(
self
,
*
inputs
,
**
kwargs
):
"""Optional: Return some or all output[s] of `make_node`.
"""Optional: Return some or all output[s] of `make_node`.
...
@@ -545,3 +545,21 @@ class Op(utils.object2, PureOp, CLinkerOp):
...
@@ -545,3 +545,21 @@ class Op(utils.object2, PureOp, CLinkerOp):
rval
.
perform
=
p
rval
.
perform
=
p
rval
.
lazy
=
False
rval
.
lazy
=
False
return
rval
return
rval
def
get_test_value
(
v
):
"""
Extract test value from variable v. Raises AttributeError if there is none.
For an ndarray, the value is the ndarray itself
For a Constant, the test value is v.value.
For a Shared variable, it is the internal value.
For another Variable, it is the content of v.tag.test_value."""
try
:
return
PureOp
.
_get_test_value
(
v
)
except
AttributeError
:
if
hasattr
(
v
,
'__array__'
):
return
v
raise
theano/gof/tests/test_op.py
浏览文件 @
1cbb3cb8
...
@@ -5,11 +5,17 @@ import numpy
...
@@ -5,11 +5,17 @@ import numpy
import
theano
import
theano
from
theano.gof.op
import
*
import
theano.gof.op
as
op
from
theano.gof.type
import
Type
,
Generic
from
theano.gof.type
import
Type
,
Generic
from
theano.gof.graph
import
Apply
,
Variable
from
theano.gof.graph
import
Apply
,
Variable
import
theano.tensor
as
T
from
theano
import
scalar
from
theano
import
scalar
from
theano
import
shared
config
=
theano
.
config
Op
=
op
.
Op
utils
=
op
.
utils
def
as_variable
(
x
):
def
as_variable
(
x
):
assert
isinstance
(
x
,
Variable
)
assert
isinstance
(
x
,
Variable
)
...
@@ -182,5 +188,33 @@ class TestMakeThunk(unittest.TestCase):
...
@@ -182,5 +188,33 @@ class TestMakeThunk(unittest.TestCase):
assert
compute_map
[
o
][
0
]
assert
compute_map
[
o
][
0
]
assert
storage_map
[
o
][
0
]
==
4
assert
storage_map
[
o
][
0
]
==
4
def
test_test_value_ndarray
():
x
=
numpy
.
zeros
((
5
,
5
))
v
=
op
.
get_test_value
(
x
)
assert
v
is
x
def
test_test_value_constant
():
x
=
T
.
as_tensor_variable
(
numpy
.
zeros
((
5
,
5
)))
v
=
op
.
get_test_value
(
x
)
assert
numpy
.
all
(
v
==
numpy
.
zeros
((
5
,
5
)))
def
test_test_value_shared
():
x
=
shared
(
numpy
.
zeros
((
5
,
5
)))
v
=
op
.
get_test_value
(
x
)
assert
numpy
.
all
(
v
==
numpy
.
zeros
((
5
,
5
)))
def
test_test_value_op
():
try
:
prev_value
=
config
.
compute_test_value
config
.
compute_test_value
=
'raise'
x
=
T
.
log
(
numpy
.
ones
((
5
,
5
)))
v
=
op
.
get_test_value
(
x
)
assert
numpy
.
allclose
(
v
,
numpy
.
zeros
((
5
,
5
)))
finally
:
config
.
compute_test_value
=
prev_value
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
unittest
.
main
()
unittest
.
main
()
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论