Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
330dd345
提交
330dd345
authored
6月 16, 2017
作者:
Adam Becker
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add ``sorted`` to TopKOp.__props__
上级
c5848291
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
29 行增加
和
17 行删除
+29
-17
sort.py
theano/gpuarray/sort.py
+8
-7
sort.py
theano/tensor/sort.py
+21
-10
没有找到文件。
theano/gpuarray/sort.py
浏览文件 @
330dd345
...
@@ -33,6 +33,7 @@ class GpuTopKOp(GpuKernelBase, TopKOp):
...
@@ -33,6 +33,7 @@ class GpuTopKOp(GpuKernelBase, TopKOp):
def
__init__
(
def
__init__
(
self
,
axis
=-
1
,
self
,
axis
=-
1
,
sorted
=
True
,
idx_dtype
=
'int64'
,
idx_dtype
=
'int64'
,
return_values
=
True
,
return_values
=
True
,
return_indices
=
True
return_indices
=
True
...
@@ -40,6 +41,7 @@ class GpuTopKOp(GpuKernelBase, TopKOp):
...
@@ -40,6 +41,7 @@ class GpuTopKOp(GpuKernelBase, TopKOp):
GpuKernelBase
.
__init__
(
self
)
GpuKernelBase
.
__init__
(
self
)
TopKOp
.
__init__
(
TopKOp
.
__init__
(
self
,
axis
=
axis
,
self
,
axis
=
axis
,
sorted
=
sorted
,
idx_dtype
=
idx_dtype
,
idx_dtype
=
idx_dtype
,
return_values
=
return_values
,
return_values
=
return_values
,
return_indices
=
return_indices
)
return_indices
=
return_indices
)
...
@@ -205,12 +207,12 @@ class GpuTopKOp(GpuKernelBase, TopKOp):
...
@@ -205,12 +207,12 @@ class GpuTopKOp(GpuKernelBase, TopKOp):
} else if (dims[
%(axis)
d] < odims[
%(axis)
d]){
} else if (dims[
%(axis)
d] < odims[
%(axis)
d]){
PyErr_SetString(
PyErr_SetString(
PyExc_ValueError,
PyExc_ValueError,
"topk: kth cannot
larger than size on
specified axis
%(axis)
d");
"topk: kth cannot
be larger than the size of
specified axis
%(axis)
d");
%(fail)
s;
%(fail)
s;
} else if (dims[
%(axis)
d] >= (1u << 31)) {
} else if (dims[
%(axis)
d] >= (1u << 31)) {
PyErr_SetString(
PyErr_SetString(
PyExc_ValueError,
PyExc_ValueError,
"topk: on GPU, array size o
n
specified axis cannot larger or equal than 2^31");
"topk: on GPU, array size o
f
specified axis cannot larger or equal than 2^31");
%(fail)
s;
%(fail)
s;
}
}
%(prep_output)
s
%(prep_output)
s
...
@@ -250,18 +252,16 @@ class GpuTopKOp(GpuKernelBase, TopKOp):
...
@@ -250,18 +252,16 @@ class GpuTopKOp(GpuKernelBase, TopKOp):
blk[0] =
%(MAX_TPB)
d / 2;
blk[0] =
%(MAX_TPB)
d / 2;
err = GpuKernel_call(
err = GpuKernel_call(
&k_topk_dense_large_
%(nodename)
s, 3,
&k_topk_dense_large_
%(nodename)
s, 3,
grd, blk, 0,
grd, blk, 0, args);
args);
} else {
} else {
err = GpuKernel_call(
err = GpuKernel_call(
&k_topk_dense_
%(nodename)
s, 3,
&k_topk_dense_
%(nodename)
s, 3,
grd, blk, 0,
grd, blk, 0, args);
args);
}
}
if (err != GA_NO_ERROR) {
if (err != GA_NO_ERROR) {
PyErr_SetString(
PyErr_SetString(
PyExc_RuntimeError,
PyExc_RuntimeError,
"
gpu kernel topk_
kernel failed to execute");
"
topk: gpu
kernel failed to execute");
%(fail)
s;
%(fail)
s;
}
}
}
}
...
@@ -302,6 +302,7 @@ def local_gpua_topkop(op, ctx_name, inputs, outputs):
...
@@ -302,6 +302,7 @@ def local_gpua_topkop(op, ctx_name, inputs, outputs):
gpu_op
=
GpuTopKOp
(
gpu_op
=
GpuTopKOp
(
axis
=
axis
,
axis
=
axis
,
sorted
=
op
.
sorted
,
idx_dtype
=
op
.
idx_dtype
,
idx_dtype
=
op
.
idx_dtype
,
return_values
=
rv
,
return_values
=
rv
,
return_indices
=
ri
)
return_indices
=
ri
)
...
...
theano/tensor/sort.py
浏览文件 @
330dd345
...
@@ -297,6 +297,12 @@ class TopKOp(theano.Op):
...
@@ -297,6 +297,12 @@ class TopKOp(theano.Op):
idx_dtype: string
idx_dtype: string
Specify output dtype for indices, defaults to ``int64``, must be integer type.
Specify output dtype for indices, defaults to ``int64``, must be integer type.
sorted: bool
NOTE: NOT IMPLEMENTED YET
Defaults to ``True``
If True, the result array would be sorted in descending order.
Notes
Notes
-----
-----
...
@@ -319,11 +325,6 @@ class TopKOp(theano.Op):
...
@@ -319,11 +325,6 @@ class TopKOp(theano.Op):
# TODO more params
# TODO more params
'''
'''
sorted: bool
Defaults to ``True``
If True, the result array would be sorted in descending order.
only_top_kth: bool
only_top_kth: bool
Defaults to ``False``
Defaults to ``False``
...
@@ -335,11 +336,12 @@ class TopKOp(theano.Op):
...
@@ -335,11 +336,12 @@ class TopKOp(theano.Op):
# TODO add opt, if k==1, use max/min reduce
# TODO add opt, if k==1, use max/min reduce
# also if k is axis size, just copy input tensor
# also if k is axis size, just copy input tensor
# TODO add opt, to merge argtopk / topk
# TODO add opt, to merge argtopk / topk
__props__
=
(
'axis'
,
'return_values'
,
'return_indices'
,
'idx_dtype'
)
__props__
=
(
'axis'
,
'
sorted'
,
'
return_values'
,
'return_indices'
,
'idx_dtype'
)
def
__init__
(
def
__init__
(
self
,
self
,
axis
=-
1
,
axis
=-
1
,
sorted
=
True
,
idx_dtype
=
'int64'
,
idx_dtype
=
'int64'
,
return_values
=
True
,
return_values
=
True
,
return_indices
=
True
return_indices
=
True
...
@@ -354,16 +356,19 @@ class TopKOp(theano.Op):
...
@@ -354,16 +356,19 @@ class TopKOp(theano.Op):
'"idx_dtype" parameter must be an integer dtype, got "
%
s"'
%
idx_dtype
)
'"idx_dtype" parameter must be an integer dtype, got "
%
s"'
%
idx_dtype
)
if
not
(
return_indices
or
return_values
):
if
not
(
return_indices
or
return_values
):
raise
ValueError
(
"Neither return_values nor return_indices is True, this isn't allowd"
)
raise
ValueError
(
"Neither return_values nor return_indices is True, this isn't allow
e
d"
)
self
.
axis
=
axis
self
.
axis
=
axis
self
.
sorted
=
sorted
self
.
return_values
=
return_values
self
.
return_values
=
return_values
self
.
return_indices
=
return_indices
self
.
return_indices
=
return_indices
self
.
idx_dtype
=
idx_dtype
self
.
idx_dtype
=
idx_dtype
def
__str__
(
self
):
def
__str__
(
self
):
return
'
%(op)
s{axis=
%(axis)
d}'
%
dict
(
return
'
%(op)
s{axis=
%(axis)
d, sorted=
%(sorted)
s}'
%
dict
(
op
=
self
.
__class__
.
__name__
,
axis
=
self
.
axis
)
op
=
self
.
__class__
.
__name__
,
axis
=
self
.
axis
,
sorted
=
self
.
sorted
)
def
make_node
(
self
,
inp
,
kth
):
def
make_node
(
self
,
inp
,
kth
):
inp
=
theano
.
tensor
.
as_tensor_variable
(
inp
)
inp
=
theano
.
tensor
.
as_tensor_variable
(
inp
)
...
@@ -446,6 +451,7 @@ def topk(x, kth, axis=-1, sorted=True, idx_dtype='int64'):
...
@@ -446,6 +451,7 @@ def topk(x, kth, axis=-1, sorted=True, idx_dtype='int64'):
If ``None``, works on flattened array.
If ``None``, works on flattened array.
sorted: bool
sorted: bool
NOTE: NOT IMPLEMENTED YET
Defaults to ``True``
Defaults to ``True``
If True, the result array would be sorted in descending order.
If True, the result array would be sorted in descending order.
...
@@ -469,7 +475,10 @@ def topk(x, kth, axis=-1, sorted=True, idx_dtype='int64'):
...
@@ -469,7 +475,10 @@ def topk(x, kth, axis=-1, sorted=True, idx_dtype='int64'):
if
axis
is
None
:
if
axis
is
None
:
x
=
theano
.
tensor
.
flatten
(
x
)
x
=
theano
.
tensor
.
flatten
(
x
)
axis
=
0
axis
=
0
return
TopKOp
(
axis
=
axis
,
idx_dtype
=
idx_dtype
)(
x
,
kth
)[
0
]
return
TopKOp
(
axis
=
axis
,
sorted
=
sorted
,
idx_dtype
=
idx_dtype
)(
x
,
kth
)[
0
]
def
argtopk
(
x
,
kth
,
axis
=-
1
,
sorted
=
True
,
idx_dtype
=
'int64'
):
def
argtopk
(
x
,
kth
,
axis
=-
1
,
sorted
=
True
,
idx_dtype
=
'int64'
):
...
@@ -517,6 +526,7 @@ def argtopk(x, kth, axis=-1, sorted=True, idx_dtype='int64'):
...
@@ -517,6 +526,7 @@ def argtopk(x, kth, axis=-1, sorted=True, idx_dtype='int64'):
axis
=
0
axis
=
0
return
TopKOp
(
return
TopKOp
(
axis
=
axis
,
axis
=
axis
,
sorted
=
sorted
,
idx_dtype
=
idx_dtype
)(
x
,
kth
)[
1
]
idx_dtype
=
idx_dtype
)(
x
,
kth
)[
1
]
...
@@ -539,4 +549,5 @@ def topk_and_argtopk(x, kth, axis=-1, sorted=True, idx_dtype='int64'):
...
@@ -539,4 +549,5 @@ def topk_and_argtopk(x, kth, axis=-1, sorted=True, idx_dtype='int64'):
axis
=
0
axis
=
0
return
TopKOp
(
return
TopKOp
(
axis
=
axis
,
axis
=
axis
,
sorted
=
sorted
,
idx_dtype
=
idx_dtype
)(
x
,
kth
)
idx_dtype
=
idx_dtype
)(
x
,
kth
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论