Caffe2 - C++ API
A deep learning, cross platform ML framework
prepend_dim_op.cc
1 #include "caffe2/operators/prepend_dim_op.h"
2 
3 namespace caffe2 {
4 
5 REGISTER_CPU_OPERATOR(PrependDim, PrependDimOp<CPUContext>);
6 REGISTER_CPU_OPERATOR(MergeDim, MergeDimOp<CPUContext>);
7 
8 OPERATOR_SCHEMA(PrependDim)
9  .NumInputs(1)
10  .NumOutputs(1)
11  .AllowInplace({{0, 0}})
12  .SetDoc(R"DOC(
13 Reshape the tensor by prepending a dimension of fixed size and dividing the
14 size of the next dimension by that amount.
15 )DOC")
16  .Arg("dim_size", "Size of the dimension to prepend.")
17  .Input(0, "data", "An input tensor.")
18  .Output(0, "reshaped", "Reshaped tensor.");
19 
20 OPERATOR_SCHEMA(MergeDim)
21  .NumInputs(1)
22  .NumOutputs(1)
23  .AllowInplace({{0, 0}})
24  .SetDoc(R"DOC(
25 Merge first two dimensions in a single dimension with size dim(0) * dim(1).
26 )DOC")
27  .Input(0, "data", "An input tensor.")
28  .Output(0, "reshaped", "Reshaped tensor.")
29  .InheritOnnxSchema("Reshape");
30 
32  using GradientMakerBase::GradientMakerBase;
33  vector<OperatorDef> GetGradientDefs() override {
34  return SingleGradientDef(
35  "MergeDim", "", vector<string>{GO(0)}, vector<string>{GI(0)});
36  }
37 
38  // Arguments are no longer needed in backprop.
39  bool CopyArguments() const override {
40  return false;
41  }
42 };
43 
44 REGISTER_GRADIENT(PrependDim, GetPrependDimGradient);
45 
46 } // namespace caffe2
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
Definition: blob.h:13
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 ...