1 #include "caffe2/operators/tanh_op.h" 3 #include "caffe2/utils/eigen_utils.h" 14 bool TanhGradientFunctor<CPUContext>::Forward<
float>(
15 const std::vector<int>& Y_dims,
16 const std::vector<int>& ,
21 const int size = std::accumulate(
22 Y_dims.cbegin(), Y_dims.cend(), 1, std::multiplies<int>());
23 ConstEigenVectorArrayMap<float> dY_arr(dY, size);
24 ConstEigenVectorArrayMap<float> Y_arr(Y, size);
25 EigenVectorMap<float>(dX, size) = dY_arr * (1 - Y_arr * Y_arr);
29 REGISTER_CPU_OPERATOR(
34 TanhGradientFunctor<CPUContext>>);
38 class GetTanhGradient :
public GradientMakerBase {
39 using GradientMakerBase::GradientMakerBase;
40 std::vector<OperatorDef> GetGradientDefs()
override {
41 return SingleGradientDef(
44 std::vector<std::string>{O(0), GO(0)},
45 std::vector<std::string>{GI(0)});
51 REGISTER_GRADIENT(Tanh, GetTanhGradient);
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...