Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
aa9383f3
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
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看板
提交
aa9383f3
编写于
6月 06, 2018
作者:
F
fengjiayi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add unit tests
上级
e2bb4d07
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
87 addition
and
5 deletion
+87
-5
paddle/fluid/operators/reverse_op.cc
paddle/fluid/operators/reverse_op.cc
+17
-3
paddle/fluid/operators/reverse_op.cu
paddle/fluid/operators/reverse_op.cu
+2
-2
python/paddle/fluid/layers/ops.py
python/paddle/fluid/layers/ops.py
+1
-0
python/paddle/fluid/tests/unittests/test_reverse_op.py
python/paddle/fluid/tests/unittests/test_reverse_op.py
+67
-0
未找到文件。
paddle/fluid/operators/reverse_op.cc
浏览文件 @
aa9383f3
...
@@ -77,23 +77,37 @@ class ReverseOpMaker : public framework::OpProtoAndCheckerMaker {
...
@@ -77,23 +77,37 @@ class ReverseOpMaker : public framework::OpProtoAndCheckerMaker {
}
}
};
};
class
ReverseGradMaker
:
public
framework
::
SingleGradOpDescMaker
{
public:
using
framework
::
SingleGradOpDescMaker
::
SingleGradOpDescMaker
;
std
::
unique_ptr
<
framework
::
OpDesc
>
Apply
()
const
override
{
auto
*
grad_op
=
new
framework
::
OpDesc
();
grad_op
->
SetType
(
"reverse"
);
grad_op
->
SetInput
(
"X"
,
OutputGrad
(
"Out"
));
grad_op
->
SetOutput
(
"Out"
,
InputGrad
(
"X"
));
grad_op
->
SetAttr
(
"axis"
,
GetAttr
(
"axis"
));
return
std
::
unique_ptr
<
framework
::
OpDesc
>
(
grad_op
);
}
};
}
// namespace operators
}
// namespace operators
}
// namespace paddle
}
// namespace paddle
namespace
ops
=
paddle
::
operators
;
namespace
ops
=
paddle
::
operators
;
REGISTER_OPERATOR
(
reverse
,
ops
::
ReverseOp
,
ops
::
ReverseOpMaker
,
REGISTER_OPERATOR
(
reverse
,
ops
::
ReverseOp
,
ops
::
ReverseOpMaker
,
paddle
::
framework
::
DefaultGradOpDescMaker
<
true
>
);
ops
::
ReverseGradMaker
);
REGISTER_OPERATOR
(
reverse_grad
,
ops
::
ReverseOp
);
REGISTER_OPERATOR
(
reverse_grad
,
ops
::
ReverseOp
);
REGISTER_OP_CPU_KERNEL
(
REGISTER_OP_CPU_KERNEL
(
reverse
,
ops
::
ReverseKernel
<
paddle
::
platform
::
CPUDeviceContext
,
int
>
,
reverse
,
ops
::
ReverseKernel
<
paddle
::
platform
::
CPUDeviceContext
,
int
>
,
ops
::
ReverseKernel
<
paddle
::
platform
::
CPUDeviceContext
,
int8_t
>
,
ops
::
ReverseKernel
<
paddle
::
platform
::
CPUDeviceContext
,
u
int8_t
>
,
ops
::
ReverseKernel
<
paddle
::
platform
::
CPUDeviceContext
,
int64_t
>
,
ops
::
ReverseKernel
<
paddle
::
platform
::
CPUDeviceContext
,
int64_t
>
,
ops
::
ReverseKernel
<
paddle
::
platform
::
CPUDeviceContext
,
bool
>
,
ops
::
ReverseKernel
<
paddle
::
platform
::
CPUDeviceContext
,
bool
>
,
ops
::
ReverseKernel
<
paddle
::
platform
::
CPUDeviceContext
,
float
>
,
ops
::
ReverseKernel
<
paddle
::
platform
::
CPUDeviceContext
,
float
>
,
ops
::
ReverseKernel
<
paddle
::
platform
::
CPUDeviceContext
,
double
>
)
ops
::
ReverseKernel
<
paddle
::
platform
::
CPUDeviceContext
,
double
>
)
REGISTER_OP_CPU_KERNEL
(
REGISTER_OP_CPU_KERNEL
(
reverse_grad
,
ops
::
ReverseKernel
<
paddle
::
platform
::
CPUDeviceContext
,
int
>
,
reverse_grad
,
ops
::
ReverseKernel
<
paddle
::
platform
::
CPUDeviceContext
,
int
>
,
ops
::
ReverseKernel
<
paddle
::
platform
::
CPUDeviceContext
,
int8_t
>
,
ops
::
ReverseKernel
<
paddle
::
platform
::
CPUDeviceContext
,
u
int8_t
>
,
ops
::
ReverseKernel
<
paddle
::
platform
::
CPUDeviceContext
,
int64_t
>
,
ops
::
ReverseKernel
<
paddle
::
platform
::
CPUDeviceContext
,
int64_t
>
,
ops
::
ReverseKernel
<
paddle
::
platform
::
CPUDeviceContext
,
bool
>
,
ops
::
ReverseKernel
<
paddle
::
platform
::
CPUDeviceContext
,
bool
>
,
ops
::
ReverseKernel
<
paddle
::
platform
::
CPUDeviceContext
,
float
>
,
ops
::
ReverseKernel
<
paddle
::
platform
::
CPUDeviceContext
,
float
>
,
...
...
paddle/fluid/operators/reverse_op.cu
浏览文件 @
aa9383f3
...
@@ -17,14 +17,14 @@
...
@@ -17,14 +17,14 @@
namespace
ops
=
paddle
::
operators
;
namespace
ops
=
paddle
::
operators
;
REGISTER_OP_CUDA_KERNEL
(
REGISTER_OP_CUDA_KERNEL
(
reverse
,
ops
::
ReverseKernel
<
paddle
::
platform
::
CUDADeviceContext
,
int
>
,
reverse
,
ops
::
ReverseKernel
<
paddle
::
platform
::
CUDADeviceContext
,
int
>
,
ops
::
ReverseKernel
<
paddle
::
platform
::
CUDADeviceContext
,
int8_t
>
,
ops
::
ReverseKernel
<
paddle
::
platform
::
CUDADeviceContext
,
u
int8_t
>
,
ops
::
ReverseKernel
<
paddle
::
platform
::
CUDADeviceContext
,
int64_t
>
,
ops
::
ReverseKernel
<
paddle
::
platform
::
CUDADeviceContext
,
int64_t
>
,
ops
::
ReverseKernel
<
paddle
::
platform
::
CUDADeviceContext
,
bool
>
,
ops
::
ReverseKernel
<
paddle
::
platform
::
CUDADeviceContext
,
bool
>
,
ops
::
ReverseKernel
<
paddle
::
platform
::
CUDADeviceContext
,
float
>
,
ops
::
ReverseKernel
<
paddle
::
platform
::
CUDADeviceContext
,
float
>
,
ops
::
ReverseKernel
<
paddle
::
platform
::
CUDADeviceContext
,
double
>
)
ops
::
ReverseKernel
<
paddle
::
platform
::
CUDADeviceContext
,
double
>
)
REGISTER_OP_CUDA_KERNEL
(
REGISTER_OP_CUDA_KERNEL
(
reverse_grad
,
ops
::
ReverseKernel
<
paddle
::
platform
::
CUDADeviceContext
,
int
>
,
reverse_grad
,
ops
::
ReverseKernel
<
paddle
::
platform
::
CUDADeviceContext
,
int
>
,
ops
::
ReverseKernel
<
paddle
::
platform
::
CUDADeviceContext
,
int8_t
>
,
ops
::
ReverseKernel
<
paddle
::
platform
::
CUDADeviceContext
,
u
int8_t
>
,
ops
::
ReverseKernel
<
paddle
::
platform
::
CUDADeviceContext
,
int64_t
>
,
ops
::
ReverseKernel
<
paddle
::
platform
::
CUDADeviceContext
,
int64_t
>
,
ops
::
ReverseKernel
<
paddle
::
platform
::
CUDADeviceContext
,
bool
>
,
ops
::
ReverseKernel
<
paddle
::
platform
::
CUDADeviceContext
,
bool
>
,
ops
::
ReverseKernel
<
paddle
::
platform
::
CUDADeviceContext
,
float
>
,
ops
::
ReverseKernel
<
paddle
::
platform
::
CUDADeviceContext
,
float
>
,
...
...
python/paddle/fluid/layers/ops.py
浏览文件 @
aa9383f3
...
@@ -60,6 +60,7 @@ __all__ = [
...
@@ -60,6 +60,7 @@ __all__ = [
'elementwise_pow'
,
'elementwise_pow'
,
'clip'
,
'clip'
,
'clip_by_norm'
,
'clip_by_norm'
,
'reverse'
,
'logical_and'
,
'logical_and'
,
'logical_or'
,
'logical_or'
,
'logical_xor'
,
'logical_xor'
,
...
...
python/paddle/fluid/tests/unittests/test_reverse_op.py
0 → 100644
浏览文件 @
aa9383f3
# Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import
unittest
import
numpy
as
np
from
op_test
import
OpTest
class
TestReverseOp
(
OpTest
):
def
initTestCase
(
self
):
self
.
x
=
np
.
random
.
random
((
3
,
4
)).
astype
(
'float32'
)
self
.
axis
=
[
0
]
def
setUp
(
self
):
self
.
initTestCase
()
self
.
op_type
=
"reverse"
self
.
inputs
=
{
"X"
:
self
.
x
}
self
.
attrs
=
{
'axis'
:
self
.
axis
}
out
=
self
.
x
for
a
in
self
.
axis
:
out
=
np
.
flip
(
out
,
axis
=
a
)
self
.
outputs
=
{
'Out'
:
out
}
def
test_check_output
(
self
):
self
.
check_output
()
def
test_check_grad
(
self
):
self
.
check_grad
([
'X'
],
'Out'
)
class
TestCase0
(
TestReverseOp
):
def
initTestCase
(
self
):
self
.
x
=
np
.
random
.
random
((
3
,
4
)).
astype
(
'float32'
)
self
.
axis
=
[
1
]
class
TestCase1
(
TestReverseOp
):
def
initTestCase
(
self
):
self
.
x
=
np
.
random
.
random
((
3
,
4
)).
astype
(
'float32'
)
self
.
axis
=
[
0
,
1
]
class
TestCase2
(
TestReverseOp
):
def
initTestCase
(
self
):
self
.
x
=
np
.
random
.
random
((
3
,
4
,
5
)).
astype
(
'float32'
)
self
.
axis
=
[
0
,
2
]
class
TestCase3
(
TestReverseOp
):
def
initTestCase
(
self
):
self
.
x
=
np
.
random
.
random
((
3
,
4
,
5
)).
astype
(
'float32'
)
self
.
axis
=
[
1
,
2
]
if
__name__
==
'__main__'
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录