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