1 #include "caffe2/operators/sinh_op.h" 10 bool SinhGradientFunctor<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 SinhFunctor<CPUContext>>);
31 REGISTER_CPU_OPERATOR(
36 SinhGradientFunctor<CPUContext>>);
41 .IdenticalTypeAndShape()
43 Calculates the hyperbolic sine of the given input tensor, element-wise. 47 - https://github.com/pytorch/pytorch/blob/master/caffe2/operators/sinh_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.98907769 0.52907848 0.03216429 0.94983935 0.47881418] 78 Y: [1.15841695 0.5541099 0.03216984 1.09924557 0.49732079] 85 .Input(0, "input",
"Input tensor")
89 "The hyperbolic sine values of the input tensor, computed " 93 OPERATOR_SCHEMA(SinhGradient)
96 .IdenticalTypeAndShape();
100 class GetSinhGradient :
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(Sinh, GetSinhGradient);
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...