Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
f8cba26d
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2305
Star
20932
Fork
5423
代码
文件
提交
分支
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看板
未验证
提交
f8cba26d
编写于
8月 21, 2023
作者:
R
Ryan
提交者:
GitHub
8月 21, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
【Complex op】add complex support for numel (#56412)
* add complex numel * change test && add doc
上级
0668650f
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
61 addition
and
5 deletion
+61
-5
paddle/phi/kernels/cpu/numel_kernel.cc
paddle/phi/kernels/cpu/numel_kernel.cc
+6
-2
paddle/phi/kernels/gpu/numel_kernel.cu
paddle/phi/kernels/gpu/numel_kernel.cu
+3
-1
paddle/phi/kernels/xpu/numel_kernel.cc
paddle/phi/kernels/xpu/numel_kernel.cc
+3
-1
python/paddle/tensor/stat.py
python/paddle/tensor/stat.py
+1
-1
test/legacy_test/test_numel_op.py
test/legacy_test/test_numel_op.py
+48
-0
未找到文件。
paddle/phi/kernels/cpu/numel_kernel.cc
浏览文件 @
f8cba26d
...
...
@@ -30,7 +30,9 @@ PD_REGISTER_KERNEL(numel,
phi
::
dtype
::
bfloat16
,
float
,
double
,
bool
)
{
bool
,
phi
::
dtype
::
complex
<
float
>
,
phi
::
dtype
::
complex
<
double
>
)
{
kernel
->
OutputAt
(
0
).
SetDataType
(
phi
::
DataType
::
INT64
);
}
...
...
@@ -47,7 +49,9 @@ PD_REGISTER_KERNEL(numel,
phi
::
dtype
::
bfloat16
,
float
,
double
,
bool
)
{
bool
,
phi
::
dtype
::
complex
<
float
>
,
phi
::
dtype
::
complex
<
double
>
)
{
kernel
->
OutputAt
(
0
).
SetDataType
(
phi
::
DataType
::
INT64
);
}
#endif
paddle/phi/kernels/gpu/numel_kernel.cu
浏览文件 @
f8cba26d
...
...
@@ -29,6 +29,8 @@ PD_REGISTER_KERNEL(numel,
phi
::
dtype
::
bfloat16
,
float
,
double
,
bool
)
{
bool
,
phi
::
dtype
::
complex
<
float
>
,
phi
::
dtype
::
complex
<
double
>
)
{
kernel
->
OutputAt
(
0
).
SetDataType
(
phi
::
DataType
::
INT64
);
}
paddle/phi/kernels/xpu/numel_kernel.cc
浏览文件 @
f8cba26d
...
...
@@ -27,6 +27,8 @@ PD_REGISTER_KERNEL(numel,
int64_t
,
phi
::
dtype
::
float16
,
float
,
bool
)
{
bool
,
phi
::
dtype
::
complex
<
float
>
,
phi
::
dtype
::
complex
<
double
>
)
{
kernel
->
OutputAt
(
0
).
SetDataType
(
phi
::
DataType
::
INT64
);
}
python/paddle/tensor/stat.py
浏览文件 @
f8cba26d
...
...
@@ -227,7 +227,7 @@ def numel(x, name=None):
Returns the number of elements for a tensor, which is a 0-D int64 Tensor with shape [].
Args:
x (Tensor): The input Tensor, it's data type can be bool, float16, float32, float64, int32, int64.
x (Tensor): The input Tensor, it's data type can be bool, float16, float32, float64, int32, int64
, complex64, complex128
.
name (str, optional): Name for the operation (optional, default is None).
For more information, please refer to :ref:`api_guide_Name`.
...
...
test/legacy_test/test_numel_op.py
浏览文件 @
f8cba26d
...
...
@@ -71,6 +71,54 @@ class TestNumelOp2FP16(TestNumelOp):
self
.
shape
=
(
0
,)
class
TestNumelOpComplex
(
TestNumelOp
):
def
setUp
(
self
):
self
.
op_type
=
"size"
self
.
python_api
=
paddle
.
numel
self
.
init
()
x
=
np
.
random
.
random
(
self
.
shape
).
astype
(
self
.
dtype
)
+
1j
*
np
.
random
.
random
(
self
.
shape
).
astype
(
self
.
dtype
)
self
.
inputs
=
{
'Input'
:
x
,
}
self
.
outputs
=
{
'Out'
:
np
.
array
(
np
.
size
(
x
))}
def
init
(
self
):
self
.
dtype
=
np
.
complex64
self
.
shape
=
(
6
,
56
,
8
,
55
)
class
Test1NumelOpComplex64
(
TestNumelOpComplex
):
def
init
(
self
):
self
.
dtype
=
np
.
complex64
self
.
shape
=
(
11
,
66
)
class
Test2NumelOpComplex64
(
TestNumelOpComplex
):
def
init
(
self
):
self
.
dtype
=
np
.
complex64
self
.
shape
=
(
0
,)
class
Test0NumelOpComplex128
(
TestNumelOpComplex
):
def
init
(
self
):
self
.
dtype
=
np
.
complex128
self
.
shape
=
(
6
,
56
,
8
,
55
)
class
Test1NumelOpComplex128
(
TestNumelOpComplex
):
def
init
(
self
):
self
.
dtype
=
np
.
complex128
self
.
shape
=
(
11
,
66
)
class
Test2NumelOpComple128
(
TestNumelOpComplex
):
def
init
(
self
):
self
.
dtype
=
np
.
complex128
self
.
shape
=
(
0
,)
@
unittest
.
skipIf
(
not
core
.
is_compiled_with_cuda
()
or
not
core
.
is_bfloat16_supported
(
core
.
CUDAPlace
(
0
)),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录