Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
51046423
提交
51046423
authored
11月 06, 2013
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix test of shape_of_variables and raise a good error to explain that the…
Fix test of shape_of_variables and raise a good error to explain that the FunctionGraph interface changed.
上级
41adddb7
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
24 行增加
和
8 行删除
+24
-8
test_utils.py
theano/tensor/tests/test_utils.py
+16
-7
utils.py
theano/tensor/utils.py
+8
-1
没有找到文件。
theano/tensor/tests/test_utils.py
浏览文件 @
51046423
import
unittest
import
numpy
import
numpy
import
theano
import
theano
...
@@ -50,23 +52,30 @@ def test_hash_from_dict():
...
@@ -50,23 +52,30 @@ def test_hash_from_dict():
assert
hash_from_dict
({
0
:
(
0
,)})
==
hash_from_dict
({
0
:
[
0
]})
assert
hash_from_dict
({
0
:
(
0
,)})
==
hash_from_dict
({
0
:
[
0
]})
def
test_shape_of_variables_simple
():
class
Tshape_of_variables
(
unittest
.
TestCase
):
def
test_simple
(
self
):
x
=
theano
.
tensor
.
matrix
(
'x'
)
x
=
theano
.
tensor
.
matrix
(
'x'
)
y
=
x
+
x
y
=
x
+
x
fgraph
=
theano
.
FunctionGraph
([
x
],
[
y
])
fgraph
=
theano
.
FunctionGraph
([
x
],
[
y
],
clone
=
False
)
assert
shape_of_variables
(
fgraph
,
{
x
:
(
5
,
5
)})
==
{
x
:
(
5
,
5
),
y
:
(
5
,
5
)}
shapes
=
shape_of_variables
(
fgraph
,
{
x
:
(
5
,
5
)})
assert
shapes
==
{
x
:
(
5
,
5
),
y
:
(
5
,
5
)}
x
=
theano
.
tensor
.
matrix
(
'x'
)
x
=
theano
.
tensor
.
matrix
(
'x'
)
y
=
theano
.
tensor
.
dot
(
x
,
x
.
T
)
y
=
theano
.
tensor
.
dot
(
x
,
x
.
T
)
fgraph
=
theano
.
FunctionGraph
([
x
],
[
y
]
)
fgraph
=
theano
.
FunctionGraph
([
x
],
[
y
],
clone
=
False
)
shapes
=
shape_of_variables
(
fgraph
,
{
x
:
(
5
,
1
)})
shapes
=
shape_of_variables
(
fgraph
,
{
x
:
(
5
,
1
)})
assert
shapes
[
x
]
==
(
5
,
1
)
assert
shapes
[
x
]
==
(
5
,
1
)
assert
shapes
[
y
]
==
(
5
,
5
)
assert
shapes
[
y
]
==
(
5
,
5
)
def
test_subtensor
(
self
):
def
test_shape_of_variables_subtensor
():
x
=
theano
.
tensor
.
matrix
(
'x'
)
x
=
theano
.
tensor
.
matrix
(
'x'
)
subx
=
x
[
1
:]
subx
=
x
[
1
:]
fgraph
=
theano
.
FunctionGraph
([
x
],
[
subx
]
)
fgraph
=
theano
.
FunctionGraph
([
x
],
[
subx
],
clone
=
False
)
shapes
=
shape_of_variables
(
fgraph
,
{
x
:
(
10
,
10
)})
shapes
=
shape_of_variables
(
fgraph
,
{
x
:
(
10
,
10
)})
assert
shapes
[
subx
]
==
(
9
,
10
)
assert
shapes
[
subx
]
==
(
9
,
10
)
def
test_err
(
self
):
x
=
theano
.
tensor
.
matrix
(
'x'
)
subx
=
x
[
1
:]
fgraph
=
theano
.
FunctionGraph
([
x
],
[
subx
])
self
.
assertRaises
(
ValueError
,
shape_of_variables
,
fgraph
,
{
x
:
(
10
,
10
)})
theano/tensor/utils.py
浏览文件 @
51046423
import
numpy
import
numpy
import
theano
import
theano
from
theano.compat.python2x
import
any
from
theano.gof.cc
import
hash_from_code
from
theano.gof.cc
import
hash_from_code
...
@@ -69,7 +70,7 @@ def shape_of_variables(fgraph, input_shapes):
...
@@ -69,7 +70,7 @@ def shape_of_variables(fgraph, input_shapes):
>>> import theano
>>> import theano
>>> x = theano.tensor.matrix('x')
>>> x = theano.tensor.matrix('x')
>>> y = x[512:]; y.name = 'y'
>>> y = x[512:]; y.name = 'y'
>>> fgraph = theano.FunctionGraph([x], [y])
>>> fgraph = theano.FunctionGraph([x], [y]
, clone=False
)
>>> shape_of_variables(fgraph, {x: (1024, 1024)})
>>> shape_of_variables(fgraph, {x: (1024, 1024)})
{y: (512, 1024), x: (1024, 1024)}
{y: (512, 1024), x: (1024, 1024)}
"""
"""
...
@@ -85,6 +86,12 @@ def shape_of_variables(fgraph, input_shapes):
...
@@ -85,6 +86,12 @@ def shape_of_variables(fgraph, input_shapes):
compute_shapes
=
theano
.
function
(
input_dims
,
output_dims
)
compute_shapes
=
theano
.
function
(
input_dims
,
output_dims
)
if
any
([
i
not
in
fgraph
.
inputs
for
i
in
input_shapes
.
keys
()]):
raise
ValueError
(
"input_shapes keys aren't in the fgraph.inputs. FunctionGraph()"
" interface changed. Now by default, it clone the graph it receive."
" To have the old behavior, give him this new parameter `clone=False`."
)
numeric_input_dims
=
[
dim
for
inp
in
fgraph
.
inputs
numeric_input_dims
=
[
dim
for
inp
in
fgraph
.
inputs
for
dim
in
input_shapes
[
inp
]]
for
dim
in
input_shapes
[
inp
]]
numeric_output_dims
=
compute_shapes
(
*
numeric_input_dims
)
numeric_output_dims
=
compute_shapes
(
*
numeric_input_dims
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论