1 #include "caffe2/operators/tan_op.h" 3 #include "caffe2/utils/eigen_utils.h" 12 bool TanGradientFunctor<CPUContext>::Forward(
13 const std::vector<int>& X_dims,
14 const std::vector<int>& ,
19 const int size = std::accumulate(
20 X_dims.cbegin(), X_dims.cend(), 1, std::multiplies<int>());
21 ConstEigenVectorArrayMap<T> dY_arr(dY, size);
22 ConstEigenVectorArrayMap<T> X_arr(X, size);
23 EigenVectorMap<T>(dX, size) = dY_arr / X_arr.cos().square();
27 REGISTER_CPU_OPERATOR(
29 UnaryElementwiseOp<TensorTypes<float>, CPUContext, TanFunctor<CPUContext>>);
30 REGISTER_CPU_OPERATOR(
35 TanGradientFunctor<CPUContext>>);
40 .IdenticalTypeAndShape()
42 Calculates the tangent of the given input tensor, element-wise. 44 .Input(0, "input",
"Input tensor")
48 "The tangent of the input tensor computed element-wise");
50 OPERATOR_SCHEMA(TanGradient).NumInputs(2).NumOutputs(1).IdenticalTypeAndShape();
54 class GetTanGradient :
public GradientMakerBase {
55 using GradientMakerBase::GradientMakerBase;
56 std::vector<OperatorDef> GetGradientDefs()
override {
57 return SingleGradientDef(
60 std::vector<std::string>{I(0), GO(0)},
61 std::vector<std::string>{GI(0)});
67 REGISTER_GRADIENT(Tan, GetTanGradient);
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...