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 
31  using GradientMakerBase::GradientMakerBase;
32  vector<OperatorDef> GetGradientDefs() override {
33  return SingleGradientDef(
34  "MergeDim", "", vector<string>{GO(0)}, vector<string>{GI(0)});
35  }
36 
37  // Arguments are no longer needed in backprop.
38  bool CopyArguments() const override {
39  return false;
40  }
41 };
42 
43 REGISTER_GRADIENT(PrependDim, GetPrependDimGradient);
44 
45 } // namespace caffe2
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
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 ...