Caffe2 - C++ API
A deep learning, cross platform ML framework
lpnorm_op.h
1 #ifndef CAFFE2_OPERATORS_LPNORM_OP_H_
2 #define CAFFE2_OPERATORS_LPNORM_OP_H_
3 
4 #include "caffe2/core/context.h"
5 #include "caffe2/core/operator.h"
6 #include "caffe2/utils/math.h"
7 
8 namespace caffe2 {
9 
10 template <typename T, class Context>
11 class LpNormOp : public Operator<Context> {
12  public:
13  USE_OPERATOR_CONTEXT_FUNCTIONS;
14  template <class... Args>
15  explicit LpNormOp(Args&&... args)
16  : Operator<Context>(std::forward<Args>(args)...),
17  OP_SINGLE_ARG(int, "p", p_, 2),
18  OP_SINGLE_ARG(bool, "average", average_, false) {
19  CAFFE_ENFORCE(p_ == 1 || p_ == 2, "p should be either 1 or 2.");
20  }
21 
22  bool RunOnDevice() override;
23 
24  protected:
25  const int p_;
26  const bool average_;
27 };
28 
29 template <typename T, class Context>
30 class LpNormGradientOp : public Operator<Context> {
31  public:
32  USE_OPERATOR_CONTEXT_FUNCTIONS;
33  template <class... Args>
34  explicit LpNormGradientOp(Args&&... args)
35  : Operator<Context>(std::forward<Args>(args)...),
36  OP_SINGLE_ARG(int, "p", p_, 2),
37  OP_SINGLE_ARG(bool, "average", average_, false) {
38  CAFFE_ENFORCE(p_ == 1 || p_ == 2, "p should be either 1 or 2.");
39  }
40 
41  bool RunOnDevice() override;
42 
43  protected:
44  const int p_;
45  const bool average_;
46 };
47 
48 } // namespace caffe2
49 
50 #endif // CAFFE2_OPERATORS_LPNORM_OP_H_
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
Definition: blob.h:13