Caffe2 - C++ API
A deep learning, cross platform ML framework
negative_op.cc
1 #include "caffe2/operators/elementwise_op.h"
2 
3 namespace caffe2 {
4 
6  template <typename T>
7  inline void
8  operator()(const int n, const T* x, T* y, CPUContext* /*device_context*/) {
9  EigenVectorMap<T>(y, n) = -ConstEigenVectorMap<T>(x, n);
10  // for (int i = 0; i < n; ++i) {
11  // y[i] = -x[i];
12  //}
13  }
14 };
15 
16 REGISTER_CPU_OPERATOR(
17  Negative, UnaryElementwiseOp<
19 
20 // Input: X, output: Y
21 OPERATOR_SCHEMA(Negative)
22  .NumInputs(1)
23  .NumOutputs(1)
24  .AllowInplace({{0, 0}})
25  .IdenticalTypeAndShape()
26  .SetDoc(R"DOC(
27 Computes the element-wise negative of the input.
28 )DOC")
29  .Input(0, "X", "1D input tensor")
30  .Output(0, "Y", "1D input tensor")
31  .InheritOnnxSchema("Neg");
32 
34  using GradientMakerBase::GradientMakerBase;
35  vector<OperatorDef> GetGradientDefs() override {
36  return SingleGradientDef(
37  "Negative", "",
38  vector<string>{GO(0)},
39  vector<string>{GI(0)});
40  }
41 };
42 REGISTER_GRADIENT(Negative, GetNegativeGradient);
43 } // namespace caffe2
The CPU Context, representing the bare minimum of what a Context class in Caffe2 should implement...
Definition: context.h:66
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...