Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
72faef33
提交
72faef33
authored
4月 16, 2015
作者:
Frédéric Bastien
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2690 from swook/master
Add numpy.compress to theano.tensor
上级
e9384d66
c532b6c0
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
65 行增加
和
1 行删除
+65
-1
extra_ops.py
theano/tensor/extra_ops.py
+20
-0
test_extra_ops.py
theano/tensor/tests/test_extra_ops.py
+40
-1
var.py
theano/tensor/var.py
+5
-0
没有找到文件。
theano/tensor/extra_ops.py
浏览文件 @
72faef33
...
...
@@ -511,6 +511,26 @@ def squeeze(x):
return
view
def
compress
(
condition
,
x
,
axis
=
None
):
"""Return selected slices of an array along given axis.
It returns the input tensor, but with selected slices along a given axis
retained. If no axis is provided, the tensor is flattened
Corresponds to numpy.compress
:param x: Input data, tensor variable
:param condition: 1 dimensional array of non-zero and zero values
corresponding to indices of slices along a selected axis
:return: `x` with selected slices
.. versionadded:: 0.7
"""
indices
=
theano
.
tensor
.
basic
.
flatnonzero
(
condition
)
return
x
.
take
(
indices
,
axis
=
axis
)
class
RepeatOp
(
theano
.
Op
):
# See the repeat function for docstring
...
...
theano/tensor/tests/test_extra_ops.py
浏览文件 @
72faef33
...
...
@@ -7,7 +7,7 @@ from theano.tests import unittest_tools as utt
from
theano.tensor.extra_ops
import
(
CumsumOp
,
cumsum
,
CumprodOp
,
cumprod
,
BinCountOp
,
bincount
,
DiffOp
,
diff
,
squeeze
,
RepeatOp
,
repeat
,
squeeze
,
compress
,
RepeatOp
,
repeat
,
Bartlett
,
bartlett
,
FillDiagonal
,
fill_diagonal
,
FillDiagonalOffset
,
fill_diagonal_offset
,
...
...
@@ -344,6 +344,45 @@ class SqueezeTester(utt.InferShapeTester):
assert
numpy
.
allclose
(
tested
,
expected
)
class
CompressTester
(
utt
.
InferShapeTester
):
axis_list
=
[
None
,
-
1
,
0
,
0
,
0
,
1
]
cond_list
=
[[
1
,
0
,
1
,
0
,
0
,
1
],
[
0
,
1
,
1
,
0
],
[
0
,
1
,
1
,
0
],
[],
[
0
,
0
,
0
,
0
],
[
1
,
1
,
0
,
1
,
0
]]
shape_list
=
[(
2
,
3
),
(
4
,
3
),
(
4
,
3
),
(
4
,
3
),
(
4
,
3
),
(
3
,
5
)]
def
setUp
(
self
):
super
(
CompressTester
,
self
)
.
setUp
()
self
.
op
=
compress
def
test_op
(
self
):
for
axis
,
cond
,
shape
in
zip
(
self
.
axis_list
,
self
.
cond_list
,
self
.
shape_list
):
cond_var
=
theano
.
tensor
.
ivector
()
data
=
numpy
.
random
.
random
(
size
=
shape
)
.
astype
(
theano
.
config
.
floatX
)
data_var
=
theano
.
tensor
.
matrix
()
f
=
theano
.
function
([
cond_var
,
data_var
],
self
.
op
(
cond_var
,
data_var
,
axis
=
axis
))
expected
=
numpy
.
compress
(
cond
,
data
,
axis
=
axis
)
tested
=
f
(
cond
,
data
)
assert
tested
.
shape
==
expected
.
shape
assert
numpy
.
allclose
(
tested
,
expected
)
class
TestRepeatOp
(
utt
.
InferShapeTester
):
def
_possible_axis
(
self
,
ndim
):
return
[
None
]
+
range
(
ndim
)
+
[
-
i
for
i
in
range
(
ndim
)]
...
...
theano/tensor/var.py
浏览文件 @
72faef33
...
...
@@ -596,6 +596,11 @@ class _tensor_py_operators:
"""
return
theano
.
tensor
.
extra_ops
.
squeeze
(
self
)
def
compress
(
self
,
a
,
axis
=
None
):
"""Return selected slices only
"""
return
theano
.
tensor
.
extra_ops
.
compress
(
self
,
a
,
axis
=
axis
)
class
TensorVariable
(
_tensor_py_operators
,
Variable
):
"""Subclass to add the tensor operators to the basic `Variable` class."""
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论