Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
e53c4879
提交
e53c4879
authored
9月 06, 2020
作者:
Brandon T. Willard
提交者:
Brandon T. Willard
9月 07, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add axis argument to squeeze
上级
91e20cc4
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
34 行增加
和
3 行删除
+34
-3
test_extra_ops.py
tests/tensor/test_extra_ops.py
+16
-0
extra_ops.py
theano/tensor/extra_ops.py
+18
-3
没有找到文件。
tests/tensor/test_extra_ops.py
浏览文件 @
e53c4879
...
...
@@ -358,6 +358,22 @@ class TestSqueeze(utt.InferShapeTester):
assert
tested
.
shape
==
expected
.
shape
assert
np
.
allclose
(
tested
,
expected
)
def
test_axis
(
self
):
variable
=
tensor
.
TensorType
(
theano
.
config
.
floatX
,
[
False
,
True
,
False
])()
res
=
squeeze
(
variable
,
axis
=
1
)
assert
res
.
broadcastable
==
(
False
,
False
)
variable
=
tensor
.
TensorType
(
theano
.
config
.
floatX
,
[
False
,
True
,
False
])()
res
=
squeeze
(
variable
,
axis
=
(
1
,))
assert
res
.
broadcastable
==
(
False
,
False
)
variable
=
tensor
.
TensorType
(
theano
.
config
.
floatX
,
[
False
,
True
,
False
,
True
])()
res
=
squeeze
(
variable
,
axis
=
(
1
,
3
))
assert
res
.
broadcastable
==
(
False
,
False
)
class
TestCompress
(
utt
.
InferShapeTester
):
axis_list
=
[
None
,
-
1
,
0
,
0
,
0
,
1
]
...
...
theano/tensor/extra_ops.py
浏览文件 @
e53c4879
import
numpy
as
np
import
theano
from
collections.abc
import
Collection
from
theano.tensor
import
basic
from
theano.tensor
import
nlinalg
# noqa
from
theano
import
gof
,
scalar
...
...
@@ -575,7 +577,7 @@ def bincount(x, weights=None, minlength=None, assert_nonneg=False):
return
out
def
squeeze
(
x
):
def
squeeze
(
x
,
axis
=
None
):
"""
Remove broadcastable dimensions from the shape of an array.
...
...
@@ -590,13 +592,26 @@ def squeeze(x):
x
Input data, tensor variable.
axis : None or int or tuple of ints, optional
Selects a subset of the single-dimensional entries in the
shape. If an axis is selected with shape entry greater than
one, an error is raised.
Returns
-------
object
`x` without its broadcastable dimensions.
"""
view
=
x
.
dimshuffle
([
i
for
i
in
range
(
x
.
ndim
)
if
not
x
.
broadcastable
[
i
]])
if
axis
is
None
:
axis
=
range
(
x
.
ndim
)
elif
not
isinstance
(
axis
,
Collection
):
axis
=
(
axis
,)
view
=
x
.
dimshuffle
(
[
i
for
i
in
range
(
x
.
ndim
)
if
not
x
.
broadcastable
[
i
]
or
i
not
in
axis
]
)
return
view
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论