Caffe2 - C++ API
A deep learning, cross platform ML framework
normalize_l1_op.h
1 
17 #ifndef CAFFE2_OPERATORS_NORMALIZE_L1_OP_H_
18 #define CAFFE2_OPERATORS_NORMALIZE_L1_OP_H_
19 
20 #include "caffe2/core/context.h"
21 #include "caffe2/core/operator.h"
22 #include "caffe2/utils/math.h"
23 
24 namespace caffe2 {
25 
26 template <typename T, class Context>
27 class NormalizeL1Op final : public Operator<Context> {
28  public:
29  USE_OPERATOR_CONTEXT_FUNCTIONS;
30  USE_SIMPLE_CTOR_DTOR(NormalizeL1Op)
31 
32  bool RunOnDevice() override {
33  const auto& x = Input(0);
34  auto* y = Output(0);
35  const auto* xData = x.template data<T>();
36  y->ResizeLike(x);
37  auto* yData = y->template mutable_data<T>();
38 
39  const auto canonical_axis = x.canonical_axis_index(
40  OperatorBase::GetSingleArgument<int>("axis", -1));
41  const int m = x.dim32(canonical_axis);
42  const int n = x.size() / m;
43  const int sf = x.size_from_dim(canonical_axis + 1);
44  DoNormalize(xData, yData, m, n, sf);
45  return true;
46  }
47 
48  private:
49  void
50  DoNormalize(const T* xData, T* yData, const int m, const int n, const int sf);
51 };
52 
53 } // namespace caffe2
54 
55 #endif // CAFFE2_OPERATORS_NORMALIZE_L1_OP_H_
Copyright (c) 2016-present, Facebook, Inc.