1 #include "caffe2/operators/cosh_op.h" 10 bool CoshGradientFunctor<CPUContext>::Forward(
11 const std::vector<int>& ,
12 const std::vector<int>& X_dims,
17 const int size = std::accumulate(
18 X_dims.cbegin(), X_dims.cend(), 1, std::multiplies<int>());
19 ConstEigenVectorArrayMap<T> dY_arr(dY, size);
20 ConstEigenVectorArrayMap<T> X_arr(X, size);
21 EigenVectorMap<T>(dX, size) = dY_arr * (X_arr.exp() - (-X_arr).exp()) / 2;
25 REGISTER_CPU_OPERATOR(
30 CoshFunctor<CPUContext>>);
31 REGISTER_CPU_OPERATOR(
36 CoshGradientFunctor<CPUContext>>);
41 .IdenticalTypeAndShape()
43 Calculates the hyperbolic cosine of the given input tensor, element-wise. 47 - https://github.com/pytorch/pytorch/blob/master/caffe2/operators/cosh_op.cc 52 <summary> <b>Example</b> </summary> 58 workspace.ResetWorkspace() 60 op = core.CreateOperator( 66 workspace.FeedBlob("X", np.random.rand(5).astype(np.float32)) 67 print("X:", workspace.FetchBlob("X")) 68 workspace.RunOperatorOnce(op) 69 print("Y:", workspace.FetchBlob("Y")) 77 X: [0.66423494 0.32074615 0.81523746 0.90423071 0.39275789] 78 Y: [1.22883528 1.05188156 1.35112322 1.43744212 1.07812598] 85 .Input(0, "input",
"Input tensor")
89 "The hyperbolic cosine values of the input tensor, computed " 93 OPERATOR_SCHEMA(CoshGradient)
96 .IdenticalTypeAndShape();
100 class GetCoshGradient :
public GradientMakerBase {
101 using GradientMakerBase::GradientMakerBase;
102 std::vector<OperatorDef> GetGradientDefs()
override {
103 return SingleGradientDef(
106 std::vector<std::string>{GO(0), I(0)},
107 std::vector<std::string>{GI(0)});
113 REGISTER_GRADIENT(Cosh, GetCoshGradient);
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...