Caffe2 - C++ API
A deep learning, cross platform ML framework
normalize_l1_op.cc
1 #include "caffe2/operators/normalize_l1_op.h"
2 
3 #include "caffe2/core/tensor.h"
4 #include "caffe2/utils/eigen_utils.h"
5 
6 namespace caffe2 {
7 
8 template <typename T, class Context>
9 void NormalizeL1Op<T, Context>::DoNormalize(
10  const T* xData,
11  T* yData,
12  const int m,
13  const int n,
14  const int sf) {
15  using InnerStride = Eigen::InnerStride<Eigen::Dynamic>;
16  using StridedVec =
17  Eigen::Map<Eigen::Matrix<T, 1, Eigen::Dynamic>, 0, InnerStride>;
18  using ConstStridedVec =
19  Eigen::Map<const Eigen::Matrix<T, 1, Eigen::Dynamic>, 0, InnerStride>;
20 
21  for (int i = 0; i < n; ++i) {
22  auto base = (i / sf) * sf * m + (i % sf);
23  ConstStridedVec xVec(xData + base, 1, m, InnerStride(sf));
24  auto norm = xVec.template lpNorm<1>();
25  if (norm != 0) {
26  StridedVec yVec(yData + base, 1, m, InnerStride(sf));
27  yVec = xVec / norm;
28  }
29  }
30 };
31 
32 REGISTER_CPU_OPERATOR(NormalizeL1, NormalizeL1Op<float, CPUContext>);
33 OPERATOR_SCHEMA(NormalizeL1)
34  .NumInputs(1)
35  .NumOutputs(1)
36  .Arg("axis", "axis to normalize")
37  .SetDoc(R"DOC(
38 Given a matrix, apply L1-normalization along the specified axis.
39 )DOC");
40 
41 } // namespace caffe2
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
Definition: blob.h:13