Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
5ccaaab8
P
Paddle
项目概览
机器未来
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
5ccaaab8
编写于
10月 15, 2020
作者:
M
mapingshuo
提交者:
GitHub
10月 15, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
reshape support bool, test=develop (#27944)
上级
8d7908f3
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
33 addition
and
7 deletion
+33
-7
paddle/fluid/operators/reshape_op.cc
paddle/fluid/operators/reshape_op.cc
+11
-4
python/paddle/fluid/layers/nn.py
python/paddle/fluid/layers/nn.py
+2
-1
python/paddle/fluid/tests/unittests/test_reshape_op.py
python/paddle/fluid/tests/unittests/test_reshape_op.py
+19
-1
python/paddle/tensor/manipulation.py
python/paddle/tensor/manipulation.py
+1
-1
未找到文件。
paddle/fluid/operators/reshape_op.cc
浏览文件 @
5ccaaab8
...
@@ -621,15 +621,18 @@ REGISTER_OPERATOR(reshape2_grad_grad, ops::Reshape2DoubleGradOp,
...
@@ -621,15 +621,18 @@ REGISTER_OPERATOR(reshape2_grad_grad, ops::Reshape2DoubleGradOp,
REGISTER_OP_CPU_KERNEL_FUNCTOR
(
reshape2
,
float
,
ops
::
ReshapeKernel
,
double
,
REGISTER_OP_CPU_KERNEL_FUNCTOR
(
reshape2
,
float
,
ops
::
ReshapeKernel
,
double
,
ops
::
ReshapeKernel
,
int8_t
,
ops
::
ReshapeKernel
,
ops
::
ReshapeKernel
,
int8_t
,
ops
::
ReshapeKernel
,
uint8_t
,
ops
::
ReshapeKernel
,
int
,
uint8_t
,
ops
::
ReshapeKernel
,
int
,
ops
::
ReshapeKernel
,
int64_t
,
ops
::
ReshapeKernel
);
ops
::
ReshapeKernel
,
int64_t
,
ops
::
ReshapeKernel
,
bool
,
ops
::
ReshapeKernel
);
REGISTER_OP_CPU_KERNEL_FUNCTOR
(
reshape2_grad
,
float
,
ops
::
ReshapeGradKernel
,
REGISTER_OP_CPU_KERNEL_FUNCTOR
(
reshape2_grad
,
float
,
ops
::
ReshapeGradKernel
,
double
,
ops
::
ReshapeGradKernel
,
int
,
double
,
ops
::
ReshapeGradKernel
,
int
,
ops
::
ReshapeGradKernel
,
int64_t
,
ops
::
ReshapeGradKernel
,
int64_t
,
ops
::
ReshapeGradKernel
,
bool
,
ops
::
ReshapeGradKernel
);
ops
::
ReshapeGradKernel
);
REGISTER_OP_CPU_KERNEL_FUNCTOR
(
reshape2_grad_grad
,
float
,
REGISTER_OP_CPU_KERNEL_FUNCTOR
(
reshape2_grad_grad
,
float
,
ops
::
ReshapeDoubleGradKernel
,
double
,
ops
::
ReshapeDoubleGradKernel
,
double
,
ops
::
ReshapeDoubleGradKernel
,
int
,
ops
::
ReshapeDoubleGradKernel
,
int
,
ops
::
ReshapeDoubleGradKernel
,
int64_t
,
ops
::
ReshapeDoubleGradKernel
,
int64_t
,
ops
::
ReshapeDoubleGradKernel
,
bool
,
ops
::
ReshapeDoubleGradKernel
);
ops
::
ReshapeDoubleGradKernel
);
#ifdef PADDLE_WITH_CUDA
#ifdef PADDLE_WITH_CUDA
...
@@ -641,15 +644,17 @@ REGISTER_OP_CUDA_KERNEL_FUNCTOR(reshape_grad, float, ops::ReshapeGradKernel,
...
@@ -641,15 +644,17 @@ REGISTER_OP_CUDA_KERNEL_FUNCTOR(reshape_grad, float, ops::ReshapeGradKernel,
double
,
ops
::
ReshapeGradKernel
,
int
,
double
,
ops
::
ReshapeGradKernel
,
int
,
ops
::
ReshapeGradKernel
,
int64_t
,
ops
::
ReshapeGradKernel
,
int64_t
,
ops
::
ReshapeGradKernel
,
plat
::
float16
,
ops
::
ReshapeGradKernel
,
plat
::
float16
,
ops
::
ReshapeGradKernel
);
ops
::
ReshapeGradKernel
);
REGISTER_OP_CUDA_KERNEL_FUNCTOR
(
reshape2
,
float
,
ops
::
ReshapeKernel
,
double
,
REGISTER_OP_CUDA_KERNEL_FUNCTOR
(
reshape2
,
float
,
ops
::
ReshapeKernel
,
double
,
ops
::
ReshapeKernel
,
int
,
ops
::
ReshapeKernel
,
ops
::
ReshapeKernel
,
int
,
ops
::
ReshapeKernel
,
int64_t
,
ops
::
ReshapeKernel
,
plat
::
float16
,
int64_t
,
ops
::
ReshapeKernel
,
plat
::
float16
,
ops
::
ReshapeKernel
);
ops
::
ReshapeKernel
,
bool
,
ops
::
ReshapeKernel
);
REGISTER_OP_CUDA_KERNEL_FUNCTOR
(
reshape2_grad
,
float
,
ops
::
ReshapeGradKernel
,
REGISTER_OP_CUDA_KERNEL_FUNCTOR
(
reshape2_grad
,
float
,
ops
::
ReshapeGradKernel
,
double
,
ops
::
ReshapeGradKernel
,
int
,
double
,
ops
::
ReshapeGradKernel
,
int
,
ops
::
ReshapeGradKernel
,
int64_t
,
ops
::
ReshapeGradKernel
,
int64_t
,
ops
::
ReshapeGradKernel
,
plat
::
float16
,
ops
::
ReshapeGradKernel
,
plat
::
float16
,
ops
::
ReshapeGradKernel
,
bool
,
ops
::
ReshapeGradKernel
);
ops
::
ReshapeGradKernel
);
REGISTER_OP_CUDA_KERNEL_FUNCTOR
(
reshape2_grad_grad
,
float
,
REGISTER_OP_CUDA_KERNEL_FUNCTOR
(
reshape2_grad_grad
,
float
,
...
@@ -657,6 +662,7 @@ REGISTER_OP_CUDA_KERNEL_FUNCTOR(reshape2_grad_grad, float,
...
@@ -657,6 +662,7 @@ REGISTER_OP_CUDA_KERNEL_FUNCTOR(reshape2_grad_grad, float,
ops
::
ReshapeDoubleGradKernel
,
int
,
ops
::
ReshapeDoubleGradKernel
,
int
,
ops
::
ReshapeDoubleGradKernel
,
int64_t
,
ops
::
ReshapeDoubleGradKernel
,
int64_t
,
ops
::
ReshapeDoubleGradKernel
,
plat
::
float16
,
ops
::
ReshapeDoubleGradKernel
,
plat
::
float16
,
ops
::
ReshapeDoubleGradKernel
,
bool
,
ops
::
ReshapeDoubleGradKernel
);
ops
::
ReshapeDoubleGradKernel
);
#endif
#endif
...
@@ -664,10 +670,11 @@ REGISTER_OP_CUDA_KERNEL_FUNCTOR(reshape2_grad_grad, float,
...
@@ -664,10 +670,11 @@ REGISTER_OP_CUDA_KERNEL_FUNCTOR(reshape2_grad_grad, float,
REGISTER_OP_XPU_KERNEL_FUNCTOR
(
reshape2
,
float
,
ops
::
ReshapeKernel
,
double
,
REGISTER_OP_XPU_KERNEL_FUNCTOR
(
reshape2
,
float
,
ops
::
ReshapeKernel
,
double
,
ops
::
ReshapeKernel
,
int
,
ops
::
ReshapeKernel
,
ops
::
ReshapeKernel
,
int
,
ops
::
ReshapeKernel
,
int64_t
,
ops
::
ReshapeKernel
,
plat
::
float16
,
int64_t
,
ops
::
ReshapeKernel
,
plat
::
float16
,
ops
::
ReshapeKernel
);
ops
::
ReshapeKernel
,
bool
,
ops
::
ReshapeKernel
);
REGISTER_OP_XPU_KERNEL_FUNCTOR
(
reshape2_grad
,
float
,
ops
::
ReshapeGradKernel
,
REGISTER_OP_XPU_KERNEL_FUNCTOR
(
reshape2_grad
,
float
,
ops
::
ReshapeGradKernel
,
double
,
ops
::
ReshapeGradKernel
,
int
,
double
,
ops
::
ReshapeGradKernel
,
int
,
ops
::
ReshapeGradKernel
,
int64_t
,
ops
::
ReshapeGradKernel
,
int64_t
,
ops
::
ReshapeGradKernel
,
plat
::
float16
,
ops
::
ReshapeGradKernel
,
plat
::
float16
,
ops
::
ReshapeGradKernel
);
ops
::
ReshapeGradKernel
,
bool
ops
::
ReshapeGradKernel
);
#endif
#endif
python/paddle/fluid/layers/nn.py
浏览文件 @
5ccaaab8
...
@@ -6119,7 +6119,8 @@ def reshape(x, shape, actual_shape=None, act=None, inplace=False, name=None):
...
@@ -6119,7 +6119,8 @@ def reshape(x, shape, actual_shape=None, act=None, inplace=False, name=None):
return dygraph_utils._append_activation_in_dygraph(out, act)
return dygraph_utils._append_activation_in_dygraph(out, act)
check_variable_and_dtype(
check_variable_and_dtype(
x, 'x', ['float16', 'float32', 'float64', 'int32', 'int64'], 'reshape')
x, 'x', ['float16', 'float32', 'float64', 'int32', 'int64',
'bool'], 'reshape')
check_type(shape, 'shape', (list, tuple, Variable), 'reshape')
check_type(shape, 'shape', (list, tuple, Variable), 'reshape')
check_type(actual_shape, 'actual_shape', (Variable, type(None)), 'reshape')
check_type(actual_shape, 'actual_shape', (Variable, type(None)), 'reshape')
...
...
python/paddle/fluid/tests/unittests/test_reshape_op.py
浏览文件 @
5ccaaab8
...
@@ -226,6 +226,24 @@ class TestReshapeUint8Op(TestReshapeInt8Op):
...
@@ -226,6 +226,24 @@ class TestReshapeUint8Op(TestReshapeInt8Op):
self
.
dtype
=
np
.
uint8
self
.
dtype
=
np
.
uint8
class
TestReshapeOpBool
(
TestReshapeOp
):
def
setUp
(
self
):
self
.
init_data
()
self
.
op_type
=
"reshape2"
self
.
inputs
=
{
"X"
:
np
.
random
.
choice
(
[
True
,
False
],
size
=
self
.
ori_shape
)
}
self
.
attrs
=
{
"shape"
:
self
.
new_shape
}
self
.
outputs
=
{
"Out"
:
self
.
inputs
[
"X"
].
reshape
(
self
.
infered_shape
),
'XShape'
:
np
.
random
.
random
(
self
.
ori_shape
).
astype
(
"float32"
)
}
def
test_check_grad
(
self
):
pass
# Test python API
# Test python API
class
TestReshapeAPI
(
unittest
.
TestCase
):
class
TestReshapeAPI
(
unittest
.
TestCase
):
def
_set_paddle_api
(
self
):
def
_set_paddle_api
(
self
):
...
@@ -324,7 +342,7 @@ class TestReshapeOpError(unittest.TestCase):
...
@@ -324,7 +342,7 @@ class TestReshapeOpError(unittest.TestCase):
# The x dtype of reshape_op must be float16, float32, float64, int32 or int64.
# The x dtype of reshape_op must be float16, float32, float64, int32 or int64.
def
test_x_dtype
():
def
test_x_dtype
():
x2
=
self
.
data
(
name
=
"x2"
,
shape
=
[
2
,
25
],
dtype
=
"
bool
"
)
x2
=
self
.
data
(
name
=
"x2"
,
shape
=
[
2
,
25
],
dtype
=
"
int8
"
)
self
.
reshape
(
x2
,
shape
=
[
2
,
5
,
5
])
self
.
reshape
(
x2
,
shape
=
[
2
,
5
,
5
])
self
.
assertRaises
(
TypeError
,
test_x_dtype
)
self
.
assertRaises
(
TypeError
,
test_x_dtype
)
...
...
python/paddle/tensor/manipulation.py
浏览文件 @
5ccaaab8
...
@@ -1353,7 +1353,7 @@ def reshape(x, shape, name=None):
...
@@ -1353,7 +1353,7 @@ def reshape(x, shape, name=None):
the corresponding dimension of x.
the corresponding dimension of x.
Args:
Args:
x(Tensor): An N-D Tensor. The data type is ``float32``, ``float64``, ``int32``
or ``int64``.
x(Tensor): An N-D Tensor. The data type is ``float32``, ``float64``, ``int32``
, ``int64`` or ``bool``
shape(list|tuple|Tensor): Define the target shape. At most one dimension of the target shape can be -1.
shape(list|tuple|Tensor): Define the target shape. At most one dimension of the target shape can be -1.
The data type is ``int32`` . If ``shape`` is a list or tuple, the elements of it should be integers or Tensors with shape [1].
The data type is ``int32`` . If ``shape`` is a list or tuple, the elements of it should be integers or Tensors with shape [1].
If ``shape`` is an Tensor, it should be an 1-D Tensor .
If ``shape`` is an Tensor, it should be an 1-D Tensor .
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录