Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
c6390da8
提交
c6390da8
authored
4月 02, 2012
作者:
Hani
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Applying changes following reviewers.
上级
3d0164d5
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
26 行增加
和
17 行删除
+26
-17
basic.py
theano/tensor/basic.py
+15
-12
test_basic.py
theano/tensor/tests/test_basic.py
+11
-5
没有找到文件。
theano/tensor/basic.py
浏览文件 @
c6390da8
...
...
@@ -5832,11 +5832,13 @@ class ArgSortOp(theano.Op):
This class is a wrapper for numpy argsort function
"""
def
__init__
(
self
,
kind
,
order
=
None
):
self
.
kind
=
kind
self
.
order
=
order
self
.
kind
=
kind
self
.
order
=
order
def
__eq__
(
self
,
other
):
return
type
(
self
)
==
type
(
other
)
and
self
.
order
==
other
.
order
and
self
.
kind
==
other
.
kind
return
(
type
(
self
)
==
type
(
other
)
and
self
.
order
==
other
.
order
and
self
.
kind
==
other
.
kind
)
def
__hash__
(
self
):
return
hash
(
type
(
self
))
^
hash
(
self
.
order
)
^
hash
(
self
.
kind
)
...
...
@@ -5845,11 +5847,11 @@ class ArgSortOp(theano.Op):
return
self
.
__class__
.
__name__
+
"{
%
s,
%
s}"
%
(
self
.
kind
,
str
(
self
.
order
))
def
make_node
(
self
,
input
,
axis
=-
1
):
if
axis
is
None
:
raise
ValueError
(
"Current Implementation does not sipport axis=None"
)
return
input
=
theano
.
tensor
.
as_tensor_variable
(
input
)
axis
=
theano
.
tensor
.
as_tensor_variable
(
axis
)
if
axis
is
None
:
axis
=
Constant
(
gof
.
generic
,
None
)
else
:
axis
=
theano
.
tensor
.
as_tensor_variable
(
axis
)
return
theano
.
Apply
(
self
,
[
input
,
axis
],
[
theano
.
tensor
.
TensorType
(
dtype
=
"int64"
,
broadcastable
=
input
.
type
.
broadcastable
)()])
...
...
@@ -5857,13 +5859,13 @@ class ArgSortOp(theano.Op):
a
=
inputs
[
0
]
axis
=
inputs
[
1
]
z
=
output_storage
[
0
]
z
[
0
]
=
numpy
.
argsort
(
a
,
axis
,
self
.
kind
,
self
.
order
)
z
[
0
]
=
numpy
.
argsort
(
a
,
axis
,
self
.
kind
,
self
.
order
)
def
infer_shape
(
self
,
node
,
inputs_shapes
):
return
[
inputs_shapes
[
0
]]
#**** No grad defined for intergers.
def
grad
(
self
,
inputs
,
output_grads
):
#No grad defined for intergers.
return
[
None
,
None
]
"""
def R_op(self, inputs, eval_points):
...
...
@@ -5877,10 +5879,11 @@ class ArgSortOp(theano.Op):
"""
def
arg
S
ort
(
a
,
axis
=-
1
,
kind
=
'quicksort'
,
order
=
None
):
def
arg
s
ort
(
a
,
axis
=-
1
,
kind
=
'quicksort'
,
order
=
None
):
"""
Returns the indices that would sort an array.
Perform an indirect sort along the given axis using the algorithm specified by the kind keyword.
It returns an array of indices of the same shape as a that index data along the given axis in sorted order.
"""
return
ArgSortOp
(
kind
,
order
)(
a
,
axis
)
\ No newline at end of file
return
ArgSortOp
(
kind
,
order
)(
a
,
axis
)
\ No newline at end of file
theano/tensor/tests/test_basic.py
浏览文件 @
c6390da8
...
...
@@ -34,7 +34,7 @@ from theano.tensor import (_shared, wvector, bvector, autocast_float_as,
get_constant_value
,
ivector
,
reshape
,
scalar_from_tensor
,
scal
,
iscalars
,
arange
,
dscalars
,
fvector
,
imatrix
,
numeric_grad
,
opt
,
ComplexError
,
TensorDot
,
lvector
,
true_div
,
max
,
min
,
Split
,
roll
,
tile
,
patternbroadcast
,
sort
,
SortOp
,
arg
S
ort
,
ArgSortOp
,)
tile
,
patternbroadcast
,
sort
,
SortOp
,
arg
s
ort
,
ArgSortOp
,)
from
theano.tests
import
unittest_tools
as
utt
...
...
@@ -5648,14 +5648,14 @@ def test_argsort():
#Example 1
a
=
theano
.
tensor
.
dmatrix
()
w
=
arg
S
ort
(
a
)
w
=
arg
s
ort
(
a
)
f
=
theano
.
function
([
a
],
w
)
assert
numpy
.
allclose
(
f
(
m_val
),
numpy
.
argsort
(
m_val
))
#Example 2
a
=
theano
.
tensor
.
dmatrix
()
axis
=
theano
.
tensor
.
scalar
()
w
=
arg
S
ort
(
a
,
axis
)
w
=
arg
s
ort
(
a
,
axis
)
f
=
theano
.
function
([
a
,
axis
],
w
)
for
axis_val
in
0
,
1
:
assert
numpy
.
allclose
(
...
...
@@ -5664,14 +5664,14 @@ def test_argsort():
#Example 3
a
=
theano
.
tensor
.
dvector
()
w2
=
arg
S
ort
(
a
)
w2
=
arg
s
ort
(
a
)
f
=
theano
.
function
([
a
],
w2
)
assert
numpy
.
allclose
(
f
(
v_val
),
numpy
.
argsort
(
v_val
))
#Example 4
a
=
theano
.
tensor
.
dmatrix
()
axis
=
theano
.
tensor
.
scalar
()
l
=
arg
S
ort
(
a
,
axis
,
"mergesort"
)
l
=
arg
s
ort
(
a
,
axis
,
"mergesort"
)
f
=
theano
.
function
([
a
,
axis
],
l
)
for
axis_val
in
0
,
1
:
assert
numpy
.
allclose
(
...
...
@@ -5688,6 +5688,12 @@ def test_argsort():
assert
a1
==
ArgSortOp
(
"mergesort"
,
[])
assert
a2
==
ArgSortOp
(
"quicksort"
,
[])
#Example 6: Testing axis=None
a
=
theano
.
tensor
.
dmatrix
()
w2
=
argsort
(
a
,
None
)
f
=
theano
.
function
([
a
],
w2
)
assert
numpy
.
allclose
(
f
(
m_val
),
numpy
.
argsort
(
m_val
,
None
))
if
__name__
==
'__main__'
:
if
0
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论