Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
072b031f
提交
072b031f
authored
10月 11, 2015
作者:
Sina Honari
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
correcting the bugs
上级
9b71642c
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
21 行增加
和
5 行删除
+21
-5
__init__.py
theano/sandbox/cuda/__init__.py
+1
-0
basic.py
theano/tensor/basic.py
+19
-4
test_opt.py
theano/tensor/tests/test_opt.py
+1
-1
没有找到文件。
theano/sandbox/cuda/__init__.py
浏览文件 @
072b031f
...
...
@@ -6,6 +6,7 @@ import os
import
shutil
import
stat
import
sys
import
warnings
import
theano
from
theano.compat
import
get_unbound_function
...
...
theano/tensor/basic.py
浏览文件 @
072b031f
...
...
@@ -4656,13 +4656,27 @@ class Flatten(Op):
}
"""
%
locals
()
def
is_flat
(
node
,
outdim
=
1
):
"""
Checks whether node's op is an instance of Reshape
and verifies the dimensionality of variable is correct.
"""
return
isinstance
(
node
.
op
,
theano
.
tensor
.
Reshape
)
and
\
node
.
inputs
[
1
]
.
ndim
==
outdim
if
not
isinstance
(
node
.
op
,
theano
.
tensor
.
Reshape
):
return
False
new_shape
=
node
.
inputs
[
1
]
# If new shape is defined by `MakeVector`, then number of inputs to
# `MakeVector` must be equal to `outdim`.
if
new_shape
.
owner
and
\
isinstance
(
new_shape
.
owner
.
op
,
theano
.
tensor
.
opt
.
MakeVector
):
return
new_shape
.
ndim
==
1
and
len
(
new_shape
.
owner
.
inputs
)
==
outdim
# `TensorConstant`
elif
isinstance
(
new_shape
,
theano
.
tensor
.
TensorConstant
):
return
new_shape
.
ndim
==
1
and
new_shape
.
data
.
shape
[
0
]
==
outdim
else
:
raise
NotImplemented
()
def
flatten
(
x
,
outdim
=
1
):
...
...
@@ -4677,10 +4691,11 @@ def flatten(x, outdim=1):
# even if it's a scalar. Otherwise, outdim must be positive
# and smaller than x.ndim.
if
outdim
<
1
or
(
outdim
>
1
and
outdim
>
x
.
ndim
):
raise
ValueError
(
'outdim
%
s out of bound [1,
%
d)'
%
(
outdim
,
x
.
ndim
+
1
))
raise
ValueError
(
'outdim
%
s out of bound [1,
%
d)'
%
(
outdim
,
x
.
ndim
+
1
))
if
outdim
>
1
:
dims
=
tuple
(
x
.
shape
[:
outdim
-
1
])
+
(
-
1
,)
dims
=
tuple
(
x
.
shape
[:
outdim
-
1
])
+
(
-
1
,)
else
:
dims
=
(
-
1
,)
x_reshaped
=
x
.
reshape
(
dims
)
...
...
theano/tensor/tests/test_opt.py
浏览文件 @
072b031f
...
...
@@ -5890,7 +5890,7 @@ def test_local_flatten_lift():
topo
=
f
.
maker
.
fgraph
.
toposort
()
shape_out_np
=
tuple
(
x_np
.
shape
[:
i
-
1
])
+
(
numpy
.
prod
(
x_np
.
shape
[
i
-
1
:]),)
assert
shape_out_np
==
out_np
.
shape
assert
tensor
.
is_flat
(
topo
[
0
],
outdim
=
i
)
assert
tensor
.
is_flat
(
topo
[
-
2
],
outdim
=
i
)
assert
isinstance
(
topo
[
-
1
]
.
op
,
tensor
.
Elemwise
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论