Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
a2bd7dcd
提交
a2bd7dcd
authored
4月 21, 2011
作者:
Pascal Lamblin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix Reshape.infer_shape when one of the given shapes is -1
上级
6b16e20c
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
38 行增加
和
6 行删除
+38
-6
basic.py
theano/tensor/basic.py
+12
-3
test_basic.py
theano/tensor/tests/test_basic.py
+26
-3
没有找到文件。
theano/tensor/basic.py
浏览文件 @
a2bd7dcd
...
...
@@ -3788,9 +3788,18 @@ class Reshape(Op):
g_out
,
=
grads
return
[
reshape
(
g_out
,
shape
(
x
),
ndim
=
x
.
ndim
),
None
]
def
infer_shape
(
self
,
node
,
ishapes
):
#we can't just put node.inputs[1] as not all op support interation
#and this is needed in the ShapeOptimizer
return
[
tuple
([
node
.
inputs
[
1
][
i
]
for
i
in
range
(
self
.
ndim
)])]
# inputs[1] can contain at most one value of '-1', meaning the actual
# shape of the output will be automatically computed by reshape, so
# that the total number of elements stays the same.
# TODO: Maybe put that formula here?
# It's not trivial, because we would have to check if the product of
# all the non-minus-one shapes is a divisor of the product of the
# original shapes.
return
[
tuple
([
switch
(
eq
(
node
.
inputs
[
1
][
i
],
-
1
),
theano
.
tensor
.
opt
.
Shape_i
(
i
)(
node
.
outputs
[
0
]),
node
.
inputs
[
1
][
i
])
for
i
in
range
(
self
.
ndim
)]
)]
def
reshape
(
x
,
newshape
,
ndim
=
None
,
name
=
None
):
if
ndim
is
None
:
...
...
theano/tensor/tests/test_basic.py
浏览文件 @
a2bd7dcd
...
...
@@ -3290,9 +3290,11 @@ class T_op_cache(unittest.TestCase):
a
=
numpy
.
random
.
rand
(
5
,
2
)
.
astype
(
config
.
floatX
)
self
.
assertTrue
(
numpy
.
all
(
fn_py
(
a
)
==
fn_c_or_py
(
a
)))
class
T_reshape
(
unittest
.
TestCase
):
def
setUp
(
self
):
utt
.
seed_rng
()
def
test_reshape
():
def
test_reshape
(
self
):
a
=
dvector
()
b
=
dmatrix
()
d
=
dmatrix
()
...
...
@@ -3361,9 +3363,30 @@ def test_reshape():
assert
numpy
.
all
(
f
(
numpy
.
asarray
([[
0
,
1
,
2
],[
3
,
4
,
5
]]))
==
numpy
.
asarray
([[[
0
],[
1
],[
2
]],[[
3
],[
4
],[
5
]]]))
assert
f
.
maker
.
env
.
toposort
()[
-
2
]
.
outputs
[
0
]
.
type
.
broadcastable
==
(
False
,
False
,
True
)
assert
numpy
.
all
(
f_sub
(
a_val
,
b_val
)
==
[
2
,
3
])
def
test_infer_shape
(
self
):
a
=
matrix
(
'a'
)
shapes
=
ivector
(
'shapes'
)
ndim
=
2
r
=
a
.
reshape
(
shapes
,
ndim
=
2
)
z
=
zeros_like
(
r
)
f
=
function
([
a
,
shapes
],
z
.
shape
)
rng
=
numpy
.
random
.
RandomState
(
seed
=
utt
.
fetch_seed
())
a_val
=
rng
.
uniform
(
size
=
(
3
,
4
))
.
astype
(
config
.
floatX
)
self
.
assertTrue
((
f
(
a_val
,
[
4
,
3
])
==
[
4
,
3
])
.
all
())
self
.
assertTrue
((
f
(
a_val
,
[
-
1
,
3
])
==
[
4
,
3
])
.
all
())
self
.
assertTrue
((
f
(
a_val
,
[
4
,
-
1
])
==
[
4
,
3
])
.
all
())
self
.
assertRaises
(
ValueError
,
f
,
a_val
,
[
-
1
,
5
])
self
.
assertRaises
(
ValueError
,
f
,
a_val
,
[
7
,
-
1
])
self
.
assertRaises
(
ValueError
,
f
,
a_val
,
[
7
,
5
])
self
.
assertRaises
(
ValueError
,
f
,
a_val
,
[
-
1
,
-
1
])
def
test_make_column_matrix_broadcastable
():
# The goal of the operation made by `b` is to ensure the second dimension
# of the column matrix is broadcastable.
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论