Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
90eec589
提交
90eec589
authored
4月 19, 2017
作者:
Frederic Bastien
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rename outdim to ndim at a few places and add a test of the old name.
上级
9853268d
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
26 行增加
和
23 行删除
+26
-23
basic.py
theano/tensor/basic.py
+13
-13
test_basic.py
theano/tensor/tests/test_basic.py
+13
-10
没有找到文件。
theano/tensor/basic.py
浏览文件 @
90eec589
...
...
@@ -5108,28 +5108,28 @@ def flatten(x, ndim=None, outdim=None):
the flattend variable with dimensionality of outdim
"""
if
outdim
is
None
and
ndim
is
None
:
out
dim
=
1
n
dim
=
1
elif
outdim
is
not
None
and
ndim
is
not
None
:
raise
ValueError
(
"You should only specify outdim or ndim"
)
elif
outdim
is
None
:
outdim
=
n
dim
# Any input variable can be flattened to have
out
dim of 1,
# even if it's a scalar. Otherwise,
out
dim must be positive
elif
outdim
is
not
None
:
ndim
=
out
dim
# Any input variable can be flattened to have
n
dim of 1,
# even if it's a scalar. Otherwise,
n
dim must be positive
# and smaller than x.ndim.
if
outdim
<
1
or
(
outdim
>
1
and
out
dim
>
x
.
ndim
):
raise
ValueError
(
'
out
dim
%
s out of bound [1,
%
d)'
%
(
out
dim
,
x
.
ndim
+
1
))
if
ndim
<
1
or
(
ndim
>
1
and
n
dim
>
x
.
ndim
):
raise
ValueError
(
'
n
dim
%
s out of bound [1,
%
d)'
%
(
n
dim
,
x
.
ndim
+
1
))
if
out
dim
>
1
:
dims
=
tuple
(
x
.
shape
[:
out
dim
-
1
])
+
(
-
1
,)
if
n
dim
>
1
:
dims
=
tuple
(
x
.
shape
[:
n
dim
-
1
])
+
(
-
1
,)
else
:
dims
=
(
-
1
,)
x_reshaped
=
x
.
reshape
(
dims
)
bcast_kept_dims
=
x
.
broadcastable
[:
out
dim
-
1
]
bcast_new_dim
=
python_all
(
x
.
broadcastable
[
out
dim
-
1
:])
bcast_kept_dims
=
x
.
broadcastable
[:
n
dim
-
1
]
bcast_new_dim
=
python_all
(
x
.
broadcastable
[
n
dim
-
1
:])
broadcastable
=
bcast_kept_dims
+
(
bcast_new_dim
,)
x_reshaped
=
theano
.
tensor
.
addbroadcast
(
x_reshaped
,
*
filter
(
lambda
i
:
broadcastable
[
i
],
range
(
out
dim
)))
x_reshaped
,
*
filter
(
lambda
i
:
broadcastable
[
i
],
range
(
n
dim
)))
return
x_reshaped
...
...
theano/tensor/tests/test_basic.py
浏览文件 @
90eec589
...
...
@@ -5530,7 +5530,7 @@ def test_flatten_scalar():
# utt.verify_grad(flatten, [a_val]) #TODO: fix verify_grd to work on scalars
def
test_flatten_
out
dim1
():
def
test_flatten_
n
dim1
():
a
=
dmatrix
()
c
=
flatten
(
a
,
1
)
f
=
inplace_func
([
a
],
c
)
...
...
@@ -5543,7 +5543,7 @@ def test_flatten_outdim1():
utt
.
verify_grad
(
flatten
,
[
a_val
])
def
test_flatten_
out
dim2
():
def
test_flatten_
n
dim2
():
a
=
dmatrix
()
c
=
flatten
(
a
,
2
)
f
=
inplace_func
([
a
],
c
)
...
...
@@ -5552,11 +5552,11 @@ def test_flatten_outdim2():
f
=
inplace_func
([
a
],
c
)
assert
np
.
all
(
f
(
a_val
)
==
a_val
)
flatten_2
=
partial
(
flatten
,
out
dim
=
2
)
flatten_2
=
partial
(
flatten
,
n
dim
=
2
)
utt
.
verify_grad
(
flatten_2
,
[
a_val
])
def
test_flatten_
out
dim2_of_3
():
def
test_flatten_
n
dim2_of_3
():
a
=
TensorType
(
'float64'
,
(
False
,
False
,
False
))()
c
=
flatten
(
a
,
2
)
f
=
inplace_func
([
a
],
c
)
...
...
@@ -5567,6 +5567,9 @@ def test_flatten_outdim2_of_3():
f
=
inplace_func
([
a
],
c
)
assert
np
.
all
(
f
(
a_val
)
==
c_val
)
flatten_2
=
partial
(
flatten
,
ndim
=
2
)
utt
.
verify_grad
(
flatten_2
,
[
a_val
])
# test outdim parameter name
flatten_2
=
partial
(
flatten
,
outdim
=
2
)
utt
.
verify_grad
(
flatten_2
,
[
a_val
])
...
...
@@ -5576,27 +5579,27 @@ def test_flatten_broadcastable():
# that of the input
inp
=
TensorType
(
'float64'
,
(
False
,
False
,
False
,
False
))()
out
=
flatten
(
inp
,
out
dim
=
2
)
out
=
flatten
(
inp
,
n
dim
=
2
)
assert
out
.
broadcastable
==
(
False
,
False
)
inp
=
TensorType
(
'float64'
,
(
False
,
False
,
False
,
True
))()
out
=
flatten
(
inp
,
out
dim
=
2
)
out
=
flatten
(
inp
,
n
dim
=
2
)
assert
out
.
broadcastable
==
(
False
,
False
)
inp
=
TensorType
(
'float64'
,
(
False
,
True
,
False
,
True
))()
out
=
flatten
(
inp
,
out
dim
=
2
)
out
=
flatten
(
inp
,
n
dim
=
2
)
assert
out
.
broadcastable
==
(
False
,
False
)
inp
=
TensorType
(
'float64'
,
(
False
,
True
,
True
,
True
))()
out
=
flatten
(
inp
,
out
dim
=
2
)
out
=
flatten
(
inp
,
n
dim
=
2
)
assert
out
.
broadcastable
==
(
False
,
True
)
inp
=
TensorType
(
'float64'
,
(
True
,
False
,
True
,
True
))()
out
=
flatten
(
inp
,
out
dim
=
3
)
out
=
flatten
(
inp
,
n
dim
=
3
)
assert
out
.
broadcastable
==
(
True
,
False
,
True
)
def
test_flatten_
out
dim_invalid
():
def
test_flatten_
n
dim_invalid
():
a
=
dmatrix
()
assert_raises
(
ValueError
,
flatten
,
a
,
3
)
assert_raises
(
ValueError
,
flatten
,
a
,
0
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论