1 #include "caffe2/operators/sin_op.h" 2 #include "caffe2/utils/eigen_utils.h" 11 bool SinGradientFunctor<CPUContext>::Forward(
12 const std::vector<int>& X_dims,
13 const std::vector<int>& ,
18 const int size = std::accumulate(
19 X_dims.cbegin(), X_dims.cend(), 1, std::multiplies<int>());
20 ConstEigenVectorArrayMap<T> dY_arr(dY, size);
21 ConstEigenVectorArrayMap<T> X_arr(X, size);
22 EigenVectorMap<T>(dX, size) = dY_arr * X_arr.cos();
26 REGISTER_CPU_OPERATOR(
28 UnaryElementwiseOp<TensorTypes<float>, CPUContext, SinFunctor<CPUContext>>);
29 REGISTER_CPU_OPERATOR(
34 SinGradientFunctor<CPUContext>>);
39 .IdenticalTypeAndShape()
41 Calculates the sine of the given input tensor, element-wise. 45 - https://github.com/pytorch/pytorch/blob/master/caffe2/operators/sin_op.cc 50 <summary> <b>Example</b> </summary> 56 workspace.ResetWorkspace() 58 op = core.CreateOperator( 64 workspace.FeedBlob("X", np.random.rand(5).astype(np.float32)) 65 print("X:", workspace.FetchBlob("X")) 66 workspace.RunOperatorOnce(op) 67 print("Y:", workspace.FetchBlob("Y")) 75 X: [0.8466114 0.1803606 0.5601509 0.04959291 0.64770824] 76 Y: [0.74903965 0.17938434 0.5313141 0.04957259 0.60336035] 83 .Input(0, "X",
"*(type: Tensor`<float>`)* Input tensor.")
87 "*(type: Tensor`<float>`)* Output tensor calculated as the sine of the input tensor, element-wise.");
89 OPERATOR_SCHEMA(SinGradient).NumInputs(2).NumOutputs(1).IdenticalTypeAndShape();
93 class GetSinGradient :
public GradientMakerBase {
94 using GradientMakerBase::GradientMakerBase;
95 std::vector<OperatorDef> GetGradientDefs()
override {
96 return SingleGradientDef(
99 std::vector<std::string>{I(0), GO(0)},
100 std::vector<std::string>{GI(0)});
106 REGISTER_GRADIENT(Sin, GetSinGradient);
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...