1 #include "caffe2/operators/reciprocal_op.h" 3 #include "caffe2/utils/eigen_utils.h" 14 bool ReciprocalGradientFunctor<CPUContext>::Forward(
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<T> dY_arr(dY, size);
24 ConstEigenVectorArrayMap<T> Y_arr(Y, size);
25 EigenVectorMap<T>(dX, size) = dY_arr * (-Y_arr.square());
29 REGISTER_CPU_OPERATOR(
34 ReciprocalGradientFunctor<CPUContext>>);
38 class GetReciprocalGradient :
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(Reciprocal, GetReciprocalGradient);
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...