1 #include "caffe2/operators/negative_op.h" 10 UnaryElementwiseOp<NumericTypes, CPUContext, NegativeFunctor<CPUContext>>);
13 OPERATOR_SCHEMA(Negative)
16 .AllowInplace({{0, 0}})
17 .IdenticalTypeAndShape()
19 Computes the element-wise negative of the input. 23 - https://github.com/pytorch/pytorch/blob/master/caffe2/operators/negative_op.cc 27 <summary> <b>Example</b> </summary> 32 workspace.ResetWorkspace() 34 op = core.CreateOperator( 40 workspace.FeedBlob("X", (np.random.rand(3,3).astype(np.float32))) 41 print("X:", workspace.FetchBlob("X")) 42 workspace.RunOperatorOnce(op) 43 print("Y:", workspace.FetchBlob("Y")) 49 X: [[0.83296907 0.61407167 0.32562155] 50 [0.59304523 0.03111175 0.29365504] 51 [0.09478621 0.5424558 0.73940724]] 52 Y: [[-0.83296907 -0.61407167 -0.32562155] 53 [-0.59304523 -0.03111175 -0.29365504] 54 [-0.09478621 -0.5424558 -0.73940724]] 60 .Input(0, "X",
"*(type: Tensor`<float>`)* 1D input tensor.")
61 .Output(0,
"Y",
"*(type: Tensor`<float>`)* 1D output tensor.")
62 .InheritOnnxSchema(
"Neg");
66 class GetNegativeGradient :
public GradientMakerBase {
67 using GradientMakerBase::GradientMakerBase;
68 std::vector<OperatorDef> GetGradientDefs()
override {
69 return SingleGradientDef(
72 std::vector<std::string>{GO(0)},
73 std::vector<std::string>{GI(0)});
79 REGISTER_GRADIENT(Negative, GetNegativeGradient);
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...