Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
6e5670b8
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看板
未验证
提交
6e5670b8
编写于
8月 21, 2020
作者:
Z
zhupengyang
提交者:
GitHub
8月 21, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
mean: not support int32, int64; add check for axis (#26401)
上级
6e6567f3
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
21 addition
and
16 deletion
+21
-16
paddle/fluid/operators/reduce_ops/reduce_mean_op.cc
paddle/fluid/operators/reduce_ops/reduce_mean_op.cc
+2
-8
paddle/fluid/operators/reduce_ops/reduce_mean_op.cu
paddle/fluid/operators/reduce_ops/reduce_mean_op.cu
+1
-3
paddle/fluid/operators/reduce_ops/reduce_op.h
paddle/fluid/operators/reduce_ops/reduce_op.h
+6
-0
python/paddle/fluid/tests/unittests/test_mean_op.py
python/paddle/fluid/tests/unittests/test_mean_op.py
+6
-1
python/paddle/tensor/stat.py
python/paddle/tensor/stat.py
+6
-4
未找到文件。
paddle/fluid/operators/reduce_ops/reduce_mean_op.cc
浏览文件 @
6e5670b8
...
...
@@ -103,11 +103,7 @@ REGISTER_OP_CPU_KERNEL(reduce_mean,
ops
::
ReduceKernel
<
paddle
::
platform
::
CPUDeviceContext
,
float
,
ops
::
MeanFunctor
>
,
ops
::
ReduceKernel
<
paddle
::
platform
::
CPUDeviceContext
,
double
,
ops
::
MeanFunctor
>
,
ops
::
ReduceKernel
<
paddle
::
platform
::
CPUDeviceContext
,
int
,
ops
::
MeanFunctor
>
,
ops
::
ReduceKernel
<
paddle
::
platform
::
CPUDeviceContext
,
int64_t
,
ops
::
MeanFunctor
>
);
double
,
ops
::
MeanFunctor
>
);
template
<
typename
T
>
using
CPUReduceMeanGradKernel
=
...
...
@@ -115,6 +111,4 @@ using CPUReduceMeanGradKernel =
ops
::
MeanGradFunctor
,
true
>
;
REGISTER_OP_CPU_KERNEL
(
reduce_mean_grad
,
CPUReduceMeanGradKernel
<
float
>
,
CPUReduceMeanGradKernel
<
double
>
,
CPUReduceMeanGradKernel
<
int
>
,
CPUReduceMeanGradKernel
<
int64_t
>
);
CPUReduceMeanGradKernel
<
double
>
);
paddle/fluid/operators/reduce_ops/reduce_mean_op.cu
浏览文件 @
6e5670b8
...
...
@@ -66,6 +66,4 @@ class ReduceMeanKernel : public framework::OpKernel<T> {
}
// namespace paddle
REGISTER_OP_CUDA_KERNEL
(
reduce_mean
,
ops
::
ReduceMeanKernel
<
float
>
,
ops
::
ReduceMeanKernel
<
double
>
,
ops
::
ReduceMeanKernel
<
int
>
,
ops
::
ReduceMeanKernel
<
int64_t
>
);
ops
::
ReduceMeanKernel
<
double
>
);
paddle/fluid/operators/reduce_ops/reduce_op.h
浏览文件 @
6e5670b8
...
...
@@ -334,6 +334,12 @@ class ReduceOp : public framework::OperatorWithKernel {
"range [-dimension(X), dimension(X)] "
"which dimesion = %d. But received dim index = %d."
,
i
,
x_rank
,
dims
[
i
]));
PADDLE_ENFORCE_GE
(
dims
[
i
],
-
x_rank
,
platform
::
errors
::
InvalidArgument
(
"The reduce dim index %d should be in the "
"range [-dimension(X), dimension(X)] "
"which dimesion = %d. But received dim index = %d."
,
i
,
x_rank
,
dims
[
i
]));
if
(
dims
[
i
]
<
0
)
dims
[
i
]
=
x_rank
+
dims
[
i
];
}
sort
(
dims
.
begin
(),
dims
.
end
());
...
...
python/paddle/fluid/tests/unittests/test_mean_op.py
浏览文件 @
6e5670b8
...
...
@@ -129,9 +129,14 @@ class TestMeanAPI(unittest.TestCase):
paddle
.
enable_static
()
def
test_errors
(
self
):
paddle
.
disable_static
()
x
=
np
.
random
.
uniform
(
-
1
,
1
,
[
10
,
12
]).
astype
(
'float32'
)
x
=
paddle
.
to_tensor
(
x
)
self
.
assertRaises
(
Exception
,
paddle
.
mean
,
x
,
-
3
)
self
.
assertRaises
(
Exception
,
paddle
.
mean
,
x
,
2
)
paddle
.
enable_static
()
with
paddle
.
static
.
program_guard
(
paddle
.
static
.
Program
()):
x
=
paddle
.
data
(
'X'
,
[
10
,
12
],
'int
8
'
)
x
=
paddle
.
data
(
'X'
,
[
10
,
12
],
'int
32
'
)
self
.
assertRaises
(
TypeError
,
paddle
.
mean
,
x
)
...
...
python/paddle/tensor/stat.py
浏览文件 @
6e5670b8
...
...
@@ -32,8 +32,7 @@ def mean(x, axis=None, keepdim=False, name=None):
Computes the mean of the input tensor's elements along ``axis``.
Args:
x (Tensor): The input Tensor with data type float32, float64, int32,
int64.
x (Tensor): The input Tensor with data type float32, float64.
axis (int|list|tuple, optional): The axis along which to perform mean
calculations. ``axis`` should be int, list(int) or tuple(int). If
``axis`` is a list/tuple of dimension(s), mean is calculated along
...
...
@@ -97,9 +96,12 @@ def mean(x, axis=None, keepdim=False, name=None):
return
core
.
ops
.
reduce_mean
(
x
,
'dim'
,
axis
,
'keep_dim'
,
keepdim
,
'reduce_all'
,
reduce_all
)
check_variable_and_dtype
(
x
,
'x/input'
,
[
'float32'
,
'float64'
,
'int32'
,
'int64'
],
check_variable_and_dtype
(
x
,
'x/input'
,
[
'float32'
,
'float64'
],
'mean/reduce_mean'
)
check_type
(
axis
,
'axis/dim'
,
(
int
,
list
,
tuple
),
'mean/reduce_mean'
)
if
isinstance
(
axis
,
(
list
,
tuple
)):
for
item
in
axis
:
check_type
(
item
,
'elements of axis/dim'
,
(
int
),
'mean/reduce_mean'
)
helper
=
LayerHelper
(
'mean'
,
**
locals
())
attrs
=
{
'dim'
:
axis
,
'keep_dim'
:
keepdim
,
'reduce_all'
:
reduce_all
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录