Caffe2 - C++ API
A deep learning, cross platform ML framework
scale_op.cc
1 
17 #include "caffe2/operators/scale_op.h"
18 
19 namespace caffe2 {
20 
21 REGISTER_CPU_OPERATOR(Scale, ScaleOp<CPUContext>);
22 OPERATOR_SCHEMA(Scale)
23  .NumInputs(1)
24  .NumOutputs(1)
25  .AllowInplace({{0, 0}})
26  .IdenticalTypeAndShape()
27  .SetDoc(R"DOC(
28 Scale takes one input data (Tensor<float>) and produces one output data
29 (Tensor<float>) whose value is the input data tensor scaled element-wise.
30 )DOC")
31  .Arg("scale", "(float, default 1.0) the scale to apply.");
32 
34  using GradientMakerBase::GradientMakerBase;
35  vector<OperatorDef> GetGradientDefs() override {
36  // CopyArguments is true by default so the "scale" arg is going to be copied
37  return SingleGradientDef(
38  "Scale", "", vector<string>{GO(0)}, vector<string>{GI(0)});
39  }
40 };
41 REGISTER_GRADIENT(Scale, GetScaleGradient);
42 } // namespace caffe2
Copyright (c) 2016-present, Facebook, Inc.
static vector< OperatorDef > SingleGradientDef(const Args &...args)
a helper function to allow one to create one single operator def, which is usually the case for many ...