Caffe2 - C++ API
A deep learning, cross platform ML framework
reverse_packed_segs_op.cc
1 
17 #include "caffe2/operators/reverse_packed_segs_op.h"
18 
19 namespace caffe2 {
20 REGISTER_CPU_OPERATOR(ReversePackedSegs, ReversePackedSegsOp<CPUContext>);
21 
22 OPERATOR_SCHEMA(ReversePackedSegs)
23  .NumInputs(2)
24  .NumOutputs(1)
25  .SetDoc(R"DOC(
26 Reverse segments in a 3-D tensor (lengths, segments, embeddings,), leaving
27 paddings unchanged. This operator is used to reverse input of a recurrent neural
28 network to make it a BRNN.
29  )DOC")
30  .Input(0, "data", "a 3-D (lengths, segments, embeddings,) tensor.")
31  .Input(1, "lengths", "length of each segment.")
32  .Output(
33  0,
34  "reversed data",
35  "a (lengths, segments, embeddings,) tensor with each segment reversed"
36  "and paddings unchanged.");
37 
39  using GradientMakerBase::GradientMakerBase;
40  vector<OperatorDef> GetGradientDefs() override {
41  return SingleGradientDef(
42  "ReversePackedSegs",
43  "",
44  vector<string>{GO(0), I(1)},
45  vector<string>{GI(0)});
46  }
47 };
48 REGISTER_GRADIENT(ReversePackedSegs, GetReversePackedSegsGradient);
49 } // 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 ...