From e515f18dd857d2f9f986955cd76208a965eb5c5c Mon Sep 17 00:00:00 2001 From: qijun Date: Thu, 14 Sep 2017 10:26:41 +0800 Subject: [PATCH] add tanh and sqrt activation operators --- paddle/operators/activation_op.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/paddle/operators/activation_op.h b/paddle/operators/activation_op.h index 0b7e171e7..4421c1095 100644 --- a/paddle/operators/activation_op.h +++ b/paddle/operators/activation_op.h @@ -99,5 +99,36 @@ struct ReluGradFunctor { } }; +struct TanhFunctor { + template + void operator()(Device d, X x, Y y) { + y.device(d) = x.tanh(); + } +}; + +template +struct TanhGradFunctor { + template + void operator()(Device d, X x, Y y, dY dy, dX dx) { + dx.device(d) = dy * (T(1) - y * y); + } +}; + +struct SqrtFunctor { + template + void operator()(Device d, X x, Y y) { + y.device(d) = x.sqrt(); + } +}; + +template +struct SqrtGradFunctor { + template + void operator()(Device d, X x, Y y, dY dy, dX dx) { + const T y_conj = Eigen::numext::conj(y); + dx.device(d) = static_cast(0.5) * dy / y_conj; + } +}; + } // namespace operators } // namespace paddle -- GitLab