Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
8857e391
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
8857e391
编写于
9月 06, 2020
作者:
W
wawltor
提交者:
GitHub
9月 06, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add the dynamic dtype check for the argmin/argma
update the check for the dtype check for the argmin, argmax
上级
041f4ab8
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
39 addition
and
1 deletion
+39
-1
paddle/fluid/operators/arg_min_max_op_base.h
paddle/fluid/operators/arg_min_max_op_base.h
+13
-1
python/paddle/fluid/tests/unittests/test_arg_min_max_v2_op.py
...on/paddle/fluid/tests/unittests/test_arg_min_max_v2_op.py
+14
-0
python/paddle/tensor/search.py
python/paddle/tensor/search.py
+12
-0
未找到文件。
paddle/fluid/operators/arg_min_max_op_base.h
浏览文件 @
8857e391
...
...
@@ -166,10 +166,22 @@ class ArgMinMaxOp : public framework::OperatorWithKernel {
platform
::
errors
::
InvalidArgument
(
"'axis'(%d) must be less than Rank(X)(%d)."
,
axis
,
x_dims
.
size
()));
const
int
&
dtype
=
ctx
->
Attrs
().
Get
<
int
>
(
"dtype"
);
PADDLE_ENFORCE_EQ
(
(
dtype
<
0
||
dtype
==
2
||
dtype
==
3
),
true
,
platform
::
errors
::
InvalidArgument
(
"The attribute of dtype in argmin/argmax must be [%s] or [%s], but "
"received [%s]"
,
paddle
::
framework
::
DataTypeToString
(
framework
::
proto
::
VarType
::
INT32
),
paddle
::
framework
::
DataTypeToString
(
framework
::
proto
::
VarType
::
INT64
),
paddle
::
framework
::
DataTypeToString
(
static_cast
<
framework
::
proto
::
VarType
::
Type
>
(
dtype
))));
auto
x_rank
=
x_dims
.
size
();
if
(
axis
<
0
)
axis
+=
x_rank
;
if
(
ctx
->
IsRuntime
())
{
const
int
&
dtype
=
ctx
->
Attrs
().
Get
<
int
>
(
"dtype"
);
if
(
dtype
==
framework
::
proto
::
VarType
::
INT32
)
{
int64_t
all_element_num
=
0
;
if
(
flatten
)
{
...
...
python/paddle/fluid/tests/unittests/test_arg_min_max_v2_op.py
浏览文件 @
8857e391
...
...
@@ -322,6 +322,20 @@ class TestArgMinMaxOpError(unittest.TestCase):
self
.
assertRaises
(
TypeError
,
test_argmin_axis_type
)
def
test_argmax_dtype_type
():
data
=
paddle
.
static
.
data
(
name
=
"test_argmax"
,
shape
=
[
10
],
dtype
=
"float32"
)
output
=
paddle
.
argmax
(
x
=
data
,
dtype
=
1
)
self
.
assertRaises
(
TypeError
,
test_argmax_dtype_type
)
def
test_argmin_dtype_type
():
data
=
paddle
.
static
.
data
(
name
=
"test_argmin"
,
shape
=
[
10
],
dtype
=
"float32"
)
output
=
paddle
.
argmin
(
x
=
data
,
dtype
=
1
)
self
.
assertRaises
(
TypeError
,
test_argmin_dtype_type
)
if
__name__
==
'__main__'
:
unittest
.
main
()
python/paddle/tensor/search.py
浏览文件 @
8857e391
...
...
@@ -166,6 +166,12 @@ def argmax(x, axis=None, keepdim=False, dtype="int64", name=None):
raise
TypeError
(
"The type of 'axis' must be int or None in argmax, but received %s."
%
(
type
(
axis
)))
if
not
(
isinstance
(
dtype
,
str
)
or
isinstance
(
dtype
,
np
.
dtype
)):
raise
TypeError
(
"the type of 'dtype' in argmax must be str or np.dtype, but received {}"
.
format
(
type
(
dtype
)))
var_dtype
=
convert_np_dtype_to_dtype_
(
dtype
)
check_dtype
(
var_dtype
,
'dtype'
,
[
'int32'
,
'int64'
],
'argmin'
)
flatten
=
False
...
...
@@ -238,6 +244,12 @@ def argmin(x, axis=None, keepdim=False, dtype="int64", name=None):
raise
TypeError
(
"The type of 'axis' must be int or None in argmin, but received %s."
%
(
type
(
axis
)))
if
not
(
isinstance
(
dtype
,
str
)
or
isinstance
(
dtype
,
np
.
dtype
)):
raise
TypeError
(
"the type of 'dtype' in argmin must be str or np.dtype, but received {}"
.
format
(
dtype
(
dtype
)))
var_dtype
=
convert_np_dtype_to_dtype_
(
dtype
)
check_dtype
(
var_dtype
,
'dtype'
,
[
'int32'
,
'int64'
],
'argmin'
)
flatten
=
False
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录