Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
2e577379
P
Paddle
项目概览
PaddlePaddle
/
Paddle
12 个月 前同步成功
通知
2292
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
2e577379
编写于
3月 28, 2018
作者:
C
chengduoZH
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add cos
上级
25317bd3
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
84 addition
and
0 deletion
+84
-0
paddle/fluid/operators/activation_op.cc
paddle/fluid/operators/activation_op.cc
+18
-0
paddle/fluid/operators/activation_op.h
paddle/fluid/operators/activation_op.h
+49
-0
paddle/function/EigenGemm.cpp
paddle/function/EigenGemm.cpp
+1
-0
python/paddle/fluid/layers/ops.py
python/paddle/fluid/layers/ops.py
+1
-0
python/paddle/fluid/tests/unittests/test_activation_op.py
python/paddle/fluid/tests/unittests/test_activation_op.py
+15
-0
未找到文件。
paddle/fluid/operators/activation_op.cc
浏览文件 @
2e577379
...
...
@@ -260,6 +260,21 @@ $out = floor(x)$
}
};
class
CosOpMaker
:
public
framework
::
OpProtoAndCheckerMaker
{
public:
CosOpMaker
(
OpProto
*
proto
,
OpAttrChecker
*
op_checker
)
:
framework
::
OpProtoAndCheckerMaker
(
proto
,
op_checker
)
{
AddInput
(
"X"
,
"Input of Floor operator"
);
AddOutput
(
"Out"
,
"Output of Floor operator"
);
AddComment
(
R"DOC(
Floor Activation Operator.
$out = cos(x)$
)DOC"
);
}
};
class
RoundOpMaker
:
public
framework
::
OpProtoAndCheckerMaker
{
public:
RoundOpMaker
(
OpProto
*
proto
,
OpAttrChecker
*
op_checker
)
...
...
@@ -561,6 +576,9 @@ REGISTER_OP(ceil, ops::ActivationOp, ops::CeilOpMaker, ceil_grad,
REGISTER_OP
(
floor
,
ops
::
ActivationOp
,
ops
::
FloorOpMaker
,
floor_grad
,
ops
::
ActivationOpGrad
);
REGISTER_OP
(
cos
,
ops
::
ActivationOp
,
ops
::
CosOpMaker
,
cos_grad
,
ops
::
ActivationOpGrad
);
REGISTER_OP
(
round
,
ops
::
ActivationOp
,
ops
::
RoundOpMaker
,
round_grad
,
ops
::
ActivationOpGrad
);
...
...
paddle/fluid/operators/activation_op.h
浏览文件 @
2e577379
...
...
@@ -331,6 +331,54 @@ struct FloorFunctor : public BaseActivationFunctor<T> {
}
};
template
<
typename
T
>
struct
Sine
{
HOSTDEVICE
T
operator
()(
const
T
&
val
)
const
{
return
sin
(
val
);
}
};
template
<
typename
T
>
struct
Cosine
{
HOSTDEVICE
T
operator
()(
const
T
&
val
)
const
{
return
cos
(
val
);
}
};
// cosine'(x) = -sin(x)
template
<
typename
T
>
struct
CosGradFunctor
:
public
BaseActivationFunctor
<
T
>
{
template
<
typename
Device
,
typename
X
,
typename
Out
,
typename
dOut
,
typename
dX
>
void
operator
()(
Device
d
,
X
x
,
Out
out
,
dOut
dout
,
dX
dx
)
const
{
dx
.
device
(
d
)
=
-
dout
*
x
.
unaryExpr
(
Sine
<
T
>
());
}
};
// cosine(x) = cos(x)
template
<
typename
T
>
struct
CosFunctor
:
public
BaseActivationFunctor
<
T
>
{
template
<
typename
Device
,
typename
X
,
typename
Out
>
void
operator
()(
Device
d
,
X
x
,
Out
out
)
const
{
out
.
device
(
d
)
=
x
.
unaryExpr
(
Cosine
<
T
>
());
}
};
// sine'(x) = cos(x)
template
<
typename
T
>
struct
SinGradFunctor
:
public
BaseActivationFunctor
<
T
>
{
template
<
typename
Device
,
typename
X
,
typename
Out
,
typename
dOut
,
typename
dX
>
void
operator
()(
Device
d
,
X
x
,
Out
out
,
dOut
dout
,
dX
dx
)
const
{
dx
.
device
(
d
)
=
dout
*
x
.
unaryExpr
(
Cosine
<
T
>
());
}
};
// sine(x) = sin(x)
template
<
typename
T
>
struct
SinFunctor
:
public
BaseActivationFunctor
<
T
>
{
template
<
typename
Device
,
typename
X
,
typename
Out
>
void
operator
()(
Device
d
,
X
x
,
Out
out
)
const
{
out
.
device
(
d
)
=
x
.
unaryExpr
(
Sine
<
T
>
());
}
};
// round(x) = [x]
template
<
typename
T
>
struct
RoundFunctor
:
public
BaseActivationFunctor
<
T
>
{
...
...
@@ -782,6 +830,7 @@ struct SwishGradFunctor : public BaseActivationFunctor<T> {
__macro(abs, AbsFunctor, AbsGradFunctor); \
__macro(ceil, CeilFunctor, ZeroGradFunctor); \
__macro(floor, FloorFunctor, ZeroGradFunctor); \
__macro(cos, CosFunctor, CosGradFunctor); \
__macro(round, RoundFunctor, ZeroGradFunctor); \
__macro(reciprocal, ReciprocalFunctor, ReciprocalGradFunctor); \
__macro(log, LogFunctor, LogGradFunctor); \
...
...
paddle/function/EigenGemm.cpp
浏览文件 @
2e577379
...
...
@@ -63,6 +63,7 @@ struct EigenBlasGemm {
const
EigenMatrix
a
(
const_cast
<
T
*>
(
A
),
sizeA
);
const
EigenMatrix
b
(
const_cast
<
T
*>
(
B
),
sizeB
);
EigenMatrix
c
(
C
,
sizeC
);
Eigen
::
Tensor
<
T
,
2
,
Eigen
::
RowMajor
,
int
>
ss
;
typedef
typename
Eigen
::
Tensor
<
T
,
2
>::
DimensionPair
DimPair
;
Eigen
::
array
<
DimPair
,
1
>
dims
;
...
...
python/paddle/fluid/layers/ops.py
浏览文件 @
2e577379
...
...
@@ -25,6 +25,7 @@ __activations__ = [
'abs'
,
'ceil'
,
'floor'
,
'cos'
,
'round'
,
'reciprocal'
,
'log'
,
...
...
python/paddle/fluid/tests/unittests/test_activation_op.py
浏览文件 @
2e577379
...
...
@@ -14,6 +14,7 @@
import
unittest
import
numpy
as
np
import
math
import
paddle.fluid.core
as
core
from
op_test
import
OpTest
from
scipy.special
import
expit
...
...
@@ -196,6 +197,20 @@ class TestFloor(OpTest):
self
.
check_grad
([
'X'
],
'Out'
,
max_relative_error
=
0.007
)
class
TestCos
(
OpTest
):
def
setUp
(
self
):
self
.
op_type
=
"cos"
x
=
np
.
random
.
uniform
(
-
1
,
1
,
[
4
,
4
]).
astype
(
"float32"
)
self
.
inputs
=
{
'X'
:
x
}
self
.
outputs
=
{
'Out'
:
math
.
cos
(
self
.
inputs
[
'X'
])}
def
test_check_output
(
self
):
self
.
check_output
()
def
test_check_grad
(
self
):
self
.
check_grad
([
'X'
],
'Out'
,
max_relative_error
=
0.007
)
class
TestRound
(
OpTest
):
def
setUp
(
self
):
self
.
op_type
=
"round"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录