Caffe2 - C++ API
A deep learning, cross platform ML framework
lengths_tile_op.cc
1 #include "caffe2/operators/lengths_tile_op.h"
2 
3 namespace caffe2 {
4 REGISTER_CPU_OPERATOR(LengthsTile, LengthsTileOp<CPUContext>);
5 
6 OPERATOR_SCHEMA(LengthsTile)
7  .NumInputs(2)
8  .NumOutputs(1)
9  .SetDoc(R"DOC(
10 Given DATA tensor of rank r >= 1, and LENGTHS tensor of rank 1, duplicate each
11 entry of the outer-most dimension of DATA according to LENGTHS, and concatenate
12 them in an output tensor of rank r.
13 
14 Example:
15  DATA = [
16  [1.0, 1.2],
17  [2.3, 3.4],
18  [4.5, 5.7],
19  [6.8, 7.9],
20  ]
21  LENGTHS = [0, 1, 3, 2]
22  OUTPUT = [
23  [2.3, 3.4],
24  [4.5, 5.7],
25  [4.5, 5.7],
26  [4.5, 5.7],
27  [6.8, 7.9],
28  [6.8, 7.9],
29  ]
30 )DOC")
31  .Input(
32  0,
33  "DATA",
34  "Tensor of rank r >= 1. First dimension must be equal to the size of "
35  "lengths")
36  .Input(1, "LENGTHS", "Tensor of int32 lengths of rank 1")
37  .Output(0, "OUTPUT", "Tensor of rank r");
38 
39 class GetLengthsTileGradient : public GradientMakerBase {
40  using GradientMakerBase::GradientMakerBase;
41  vector<OperatorDef> GetGradientDefs() override {
42  CAFFE_ENFORCE_EQ(def_.input_size(), 2);
43  return SingleGradientDef(
44  "LengthsSum",
45  "",
46  // input 1 is the lengths used to repeat
47  // DATA in the forward pass
48  vector<string>{GO(0), I(1)},
49  // only concerned with the gradient on "DATA"
50  vector<string>{GI(0)});
51  }
52 };
53 REGISTER_GRADIENT(LengthsTile, GetLengthsTileGradient);
54 } // namespace caffe2
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...