Caffe2 - C++ API
A deep learning, cross platform ML framework
lengths_top_k_op.h
1 
2 #ifndef CAFFE2_OPERATORS_LENGTHS_TOP_K_OP_H_
3 #define CAFFE2_OPERATORS_LENGTHS_TOP_K_OP_H_
4 
5 #include "caffe2/core/context.h"
6 #include "caffe2/core/logging.h"
7 #include "caffe2/core/operator.h"
8 #include "caffe2/operators/conv_pool_op_base.h"
9 #include "caffe2/utils/math.h"
10 
11 namespace caffe2 {
12 template <typename T, class Context>
13 class LengthsTopKOp : public Operator<Context> {
14  public:
15  USE_OPERATOR_CONTEXT_FUNCTIONS;
16 
17  template <class... Args>
18  explicit LengthsTopKOp(Args&&... args)
19  : Operator<Context>(std::forward<Args>(args)...),
20  OP_SINGLE_ARG(int, "k", k_, -1) {
21  CAFFE_ENFORCE_GE(k_, 1, "k argument must be >= 1");
22  }
23 
24  bool RunOnDevice() override;
25 
26  protected:
27  int k_;
28  INPUT_TAGS(X_IN, Y_IN);
29  OUTPUT_TAGS(TOPK_VALUES_OUT, TOPK_INDICES_OUT);
30 };
31 
32 template <typename T, class Context>
33 class LengthsTopKGradientOp : public Operator<Context> {
34  public:
35  template <class... Args>
36  explicit LengthsTopKGradientOp(Args&&... args)
37  : Operator<Context>(std::forward<Args>(args)...),
38  OP_SINGLE_ARG(int, "k", k_, -1) {
39  CAFFE_ENFORCE_GE(k_, 1, "k argument must be >= 1");
40  }
41  USE_OPERATOR_CONTEXT_FUNCTIONS;
42 
43  bool RunOnDevice() override;
44 
45  protected:
46  int k_;
47  INPUT_TAGS(LENGTH_IN, INDICES_IN, DER_TOPK_IN);
48  OUTPUT_TAGS(DER_X_OUT);
49 };
50 
51 } // namespace caffe2
52 
53 #endif // CAFFE2_OPERATORS_LENGTHS_TOP_K_OP_H_
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
Definition: blob.h:13