Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
d76c66a5
提交
d76c66a5
authored
9月 09, 2014
作者:
Frédéric Bastien
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2086 from daemonmaker/todo_astensorvariable_applydefaultoutput
Completed TODO in tensor.py:as_tensor_variable which said to use the App...
上级
2036661e
6b31175f
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
42 行增加
和
13 行删除
+42
-13
basic.py
theano/tensor/basic.py
+4
-4
test_basic.py
theano/tensor/tests/test_basic.py
+38
-9
没有找到文件。
theano/tensor/basic.py
浏览文件 @
d76c66a5
...
...
@@ -145,13 +145,13 @@ def as_tensor_variable(x, name=None, ndim=None):
return
x
.
_as_TensorVariable
()
# TODO: pass name and ndim arguments
if
isinstance
(
x
,
gof
.
Apply
):
#
TODO:
use Apply's default output mechanism
if
len
(
x
.
outputs
)
!=
1
:
# use Apply's default output mechanism
if
(
x
.
op
.
default_output
is
None
)
and
(
len
(
x
.
outputs
)
!=
1
)
:
raise
ValueError
(
"It is ambiguous which output of a multi-output Op has"
" to be fetched."
,
x
)
else
:
x
=
x
.
outputs
[
0
]
x
=
x
.
default_output
()
if
isinstance
(
x
,
Variable
):
if
isinstance
(
x
.
type
,
scal
.
Scalar
):
x
=
tensor_from_scalar
(
x
)
...
...
theano/tensor/tests/test_basic.py
浏览文件 @
d76c66a5
...
...
@@ -1919,17 +1919,46 @@ Allocb4GradTester = makeBroadcastTester(
)
def
test_as_tensor_variable
():
x
=
tensor
.
TensorType
(
config
.
floatX
,
(
True
,
False
))(
'x'
)
x
=
as_tensor_variable
(
x
,
ndim
=
1
)
assert
(
x
.
ndim
==
1
)
class
ApplyDefaultTestOp
(
theano
.
Op
):
def
__init__
(
self
,
id
):
self
.
default_output
=
id
x
=
tensor
.
matrix
(
'x'
,
dtype
=
config
.
floatX
)
try
:
def
make_node
(
self
,
x
):
x
=
theano
.
tensor
.
as_tensor_variable
(
x
)
return
theano
.
Apply
(
self
,
[
x
],
[
x
.
type
()])
class
TestAsTensorVariable
(
unittest
.
TestCase
):
"""
Unit test for ensuring that as_tensor_variable handles Apply objects
correctly and removes leading broadcastable dimensions when possible.
"""
def
setUp
(
self
):
self
.
x
=
tensor
.
scalar
(
'x'
)
def
test_one_output
(
self
):
good_apply_var
=
ApplyDefaultTestOp
(
0
)
.
make_node
(
self
.
x
)
x
=
as_tensor_variable
(
good_apply_var
)
def
test_below_zero_output
(
self
):
bad_apply_var
=
ApplyDefaultTestOp
(
-
1
)
.
make_node
(
self
.
x
)
self
.
assertRaises
(
AttributeError
,
as_tensor_variable
,
bad_apply_var
)
def
test_above_output_len
(
self
):
bad_apply_var
=
ApplyDefaultTestOp
(
2
)
.
make_node
(
self
.
x
)
self
.
assertRaises
(
AttributeError
,
as_tensor_variable
,
bad_apply_var
)
def
test_list
(
self
):
bad_apply_var
=
ApplyDefaultTestOp
([
0
,
1
])
.
make_node
(
self
.
x
)
self
.
assertRaises
(
AttributeError
,
as_tensor_variable
,
bad_apply_var
)
def
test_strip_leading_broadcastable
(
self
):
x
=
tensor
.
TensorType
(
config
.
floatX
,
(
True
,
False
))(
'x'
)
x
=
as_tensor_variable
(
x
,
ndim
=
1
)
assert
(
False
)
# The call above should have failed
except
ValueError
:
pass
assert
(
x
.
ndim
==
1
)
x
=
tensor
.
matrix
(
'x'
,
dtype
=
config
.
floatX
)
self
.
assertRaises
(
ValueError
,
as_tensor_variable
,
x
,
ndim
=
1
)
class
TestAlloc
(
unittest
.
TestCase
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论