1 #include "caffe2/operators/cbrt_op.h" 2 #include "caffe2/utils/eigen_utils.h" 12 bool CbrtGradientFunctor<CPUContext>::Forward(
13 const std::vector<int>& dY_dims,
14 const std::vector<int>& ,
19 const int size = std::accumulate(
20 dY_dims.cbegin(), dY_dims.cend(), 1, std::multiplies<int>());
21 EigenVectorMap<T>(dX, size) = ConstEigenVectorArrayMap<T>(dY, size) /
22 ConstEigenVectorArrayMap<T>(Y, size).square() /
T(3);
26 REGISTER_CPU_OPERATOR(
31 CbrtFunctor<CPUContext>>);
32 REGISTER_CPU_OPERATOR(
37 CbrtGradientFunctor<CPUContext>>);
42 .AllowInplace({{0, 0}})
43 .IdenticalTypeAndShape()
44 .Input(0,
"X",
"*(type: Tensor`<float>`)* Input tensor.")
48 "*(type: Tensor`<float>`)* Output tensor calculated as the cbrt of the input tensor, element-wise.");
50 OPERATOR_SCHEMA(CbrtGradient)
53 .AllowInplace({{0, 0}})
54 .IdenticalTypeAndShape();
58 class GetCbrtGradient :
public GradientMakerBase {
59 using GradientMakerBase::GradientMakerBase;
60 std::vector<OperatorDef> GetGradientDefs()
override {
61 return SingleGradientDef(
64 std::vector<std::string>{GO(0), O(0)},
65 std::vector<std::string>{GI(0)});
71 REGISTER_GRADIENT(Cbrt, GetCbrtGradient);
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...