Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
aec1e4ce
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
aec1e4ce
编写于
2月 08, 2023
作者:
Z
Zhong Hui
提交者:
GitHub
2月 08, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Zero-Dim] Fix 0d axis support for argmin/argmax (#50293)
上级
b3888614
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
10 addition
and
9 deletion
+10
-9
paddle/phi/infermeta/unary.cc
paddle/phi/infermeta/unary.cc
+4
-3
python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py
python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py
+4
-4
python/paddle/fluid/tests/unittests/xpu/test_zero_dim_tensor_xpu.py
...dle/fluid/tests/unittests/xpu/test_zero_dim_tensor_xpu.py
+2
-2
未找到文件。
paddle/phi/infermeta/unary.cc
浏览文件 @
aec1e4ce
...
...
@@ -161,6 +161,7 @@ void ArgMinMaxInferMeta(const MetaTensor& x,
const
auto
&
x_dims
=
x
.
dims
();
auto
x_rank
=
x
.
dims
().
size
();
auto
zero_dim_tensor
=
x_rank
==
0
;
if
(
x_rank
>
0
)
{
PADDLE_ENFORCE_GE
(
int_axis
,
-
x_rank
,
...
...
@@ -178,11 +179,11 @@ void ArgMinMaxInferMeta(const MetaTensor& x,
x_rank
));
}
else
{
// 0-dim tensor
PADDLE_ENFORCE_EQ
(
(
int_axis
==
0
||
int_axis
==
-
1
)
&&
flatten
,
PADDLE_ENFORCE_EQ
(
int_axis
==
0
||
int_axis
==
-
1
,
true
,
phi
::
errors
::
InvalidArgument
(
"'axis'(%d) must be 0 or -1 if input tensor is "
"0-dim.
and flatten should be true.
"
,
"0-dim."
,
int_axis
));
}
...
...
@@ -191,7 +192,7 @@ void ArgMinMaxInferMeta(const MetaTensor& x,
if
(
config
.
is_runtime
)
{
if
(
dtype
==
phi
::
TransToProtoVarType
(
DataType
::
INT32
))
{
int64_t
all_element_num
=
0
;
if
(
flatten
)
{
if
(
flatten
||
zero_dim_tensor
)
{
all_element_num
=
phi
::
product
(
x_dims
);
}
else
{
all_element_num
=
x_dims
[
int_axis
];
...
...
python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py
浏览文件 @
aec1e4ce
...
...
@@ -571,7 +571,7 @@ class TestSundryAPI(unittest.TestCase):
paddle
.
disable_static
()
self
.
x
=
paddle
.
rand
([])
def
_
test_argmin
(
self
):
def
test_argmin
(
self
):
x
=
paddle
.
rand
([])
out1
=
paddle
.
argmin
(
x
,
0
)
out2
=
paddle
.
argmin
(
x
,
-
1
)
...
...
@@ -585,7 +585,7 @@ class TestSundryAPI(unittest.TestCase):
self
.
assertEqual
(
out3
.
shape
,
[])
np
.
testing
.
assert_allclose
(
out3
,
0.0
)
def
_
test_argmax
(
self
):
def
test_argmax
(
self
):
x
=
paddle
.
rand
([])
out1
=
paddle
.
argmax
(
x
,
0
)
out2
=
paddle
.
argmax
(
x
,
-
1
)
...
...
@@ -1641,7 +1641,7 @@ class TestSundryAPIStatic(unittest.TestCase):
self
.
exe
=
paddle
.
static
.
Executor
()
@
prog_scope
()
def
_
test_argmin
(
self
):
def
test_argmin
(
self
):
x
=
paddle
.
rand
([])
out1
=
paddle
.
argmin
(
x
,
0
)
out2
=
paddle
.
argmin
(
x
,
-
1
)
...
...
@@ -1664,7 +1664,7 @@ class TestSundryAPIStatic(unittest.TestCase):
np
.
testing
.
assert_allclose
(
res
[
2
],
0.0
)
@
prog_scope
()
def
_
test_argmax
(
self
):
def
test_argmax
(
self
):
x
=
paddle
.
rand
([])
out1
=
paddle
.
argmax
(
x
,
0
)
out2
=
paddle
.
argmax
(
x
,
-
1
)
...
...
python/paddle/fluid/tests/unittests/xpu/test_zero_dim_tensor_xpu.py
浏览文件 @
aec1e4ce
...
...
@@ -328,7 +328,7 @@ class TestSundryAPI(unittest.TestCase):
paddle
.
disable_static
()
self
.
x
=
paddle
.
rand
([])
def
_
test_argmin
(
self
):
def
test_argmin
(
self
):
x
=
paddle
.
rand
([])
out1
=
paddle
.
argmin
(
x
,
0
)
out2
=
paddle
.
argmin
(
x
,
-
1
)
...
...
@@ -342,7 +342,7 @@ class TestSundryAPI(unittest.TestCase):
self
.
assertEqual
(
out3
.
shape
,
[])
np
.
testing
.
assert_allclose
(
out3
,
0.0
)
def
_
test_argmax
(
self
):
def
test_argmax
(
self
):
x
=
paddle
.
rand
([])
out1
=
paddle
.
argmax
(
x
,
0
)
out2
=
paddle
.
argmax
(
x
,
-
1
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录