1 #include "caffe2/operators/cube_op.h" 2 #include "caffe2/utils/eigen_utils.h" 12 bool CubeGradientFunctor<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>(X, size).square() *
T(3);
26 REGISTER_CPU_OPERATOR(
28 UnaryElementwiseOp<NumericTypes, CPUContext, CubeFunctor<CPUContext>>);
29 REGISTER_CPU_OPERATOR(
34 CubeGradientFunctor<CPUContext>>);
39 .IdenticalTypeAndShape()
40 .Input(0,
"X",
"*(type: Tensor`<float>`)* Input tensor.")
44 "*(type: Tensor`<float>`)* Output tensor calculated as the cube of the input tensor, element-wise.");
46 OPERATOR_SCHEMA(CubeGradient)
49 .IdenticalTypeAndShape();
53 class GetCubeGradient :
public GradientMakerBase {
54 using GradientMakerBase::GradientMakerBase;
55 std::vector<OperatorDef> GetGradientDefs()
override {
56 return SingleGradientDef(
59 std::vector<std::string>{GO(0), I(0)},
60 std::vector<std::string>{GI(0)});
66 REGISTER_GRADIENT(Cube, GetCubeGradient);
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...