Caffe2 - C++ API
A deep learning, cross platform ML framework
negative_op.cc
1 
17 #include "caffe2/operators/elementwise_op.h"
18 
19 namespace caffe2 {
20 
22  template <typename T>
23  inline void
24  operator()(const int n, const T* x, T* y, CPUContext* /*device_context*/) {
25  EigenVectorMap<T>(y, n) = -ConstEigenVectorMap<T>(x, n);
26  // for (int i = 0; i < n; ++i) {
27  // y[i] = -x[i];
28  //}
29  }
30 };
31 
32 REGISTER_CPU_OPERATOR(
33  Negative, UnaryElementwiseOp<
35 
36 // Input: X, output: Y
37 OPERATOR_SCHEMA(Negative)
38  .NumInputs(1)
39  .NumOutputs(1)
40  .AllowInplace({{0, 0}})
41  .IdenticalTypeAndShape()
42  .SetDoc(R"DOC(
43 Computes the element-wise negative of the input.
44 )DOC")
45  .Input(0, "X", "1D input tensor")
46  .Output(0, "Y", "1D input tensor");
47 
49  using GradientMakerBase::GradientMakerBase;
50  vector<OperatorDef> GetGradientDefs() override {
51  return SingleGradientDef(
52  "Negative", "",
53  vector<string>{GO(0)},
54  vector<string>{GI(0)});
55  }
56 };
57 REGISTER_GRADIENT(Negative, GetNegativeGradient);
58 } // namespace caffe2
The CPU Context, representing the bare minimum of what a Context class in Caffe2 should implement...
Definition: context.h:82
Copyright (c) 2016-present, Facebook, Inc.