From abd39d5a88cd04ae09eca1ec40aa0bf4dc0744e6 Mon Sep 17 00:00:00 2001 From: Yinghai Lu Date: Mon, 11 Mar 2019 10:20:11 -0700 Subject: [PATCH] Fix compilation error (#17860) Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/17860 att Reviewed By: bddppq Differential Revision: D14402751 fbshipit-source-id: 2d53b230dfd775372addeab1d3eaf0b9552fae9f --- caffe2/operators/normalize_op.cc | 24 ------------------------ caffe2/operators/normalize_op.h | 24 ++++++++++++++++++++++-- 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/caffe2/operators/normalize_op.cc b/caffe2/operators/normalize_op.cc index 5c7d3c7..ec0600c 100644 --- a/caffe2/operators/normalize_op.cc +++ b/caffe2/operators/normalize_op.cc @@ -1,34 +1,10 @@ #include "caffe2/operators/normalize_op.h" #include "caffe2/core/tensor.h" -#include "caffe2/utils/eigen_utils.h" namespace caffe2 { template -void NormalizeOp::DoNormalize( - const T* xData, - T* yData, - const int m, - const int n, - const int sf) { - using InnerStride = Eigen::InnerStride; - using StridedVec = - Eigen::Map, 0, InnerStride>; - using ConstStridedVec = - Eigen::Map, 0, InnerStride>; - - for (int i = 0; i < n; ++i) { - auto base = (i / sf) * sf * m + (i % sf); - ConstStridedVec xVec(xData + base, 1, m, InnerStride(sf)); - auto norm = xVec.template lpNorm<2>(); - norm = std::max(norm, kEps_); - StridedVec yVec(yData + base, 1, m, InnerStride(sf)); - yVec = xVec / norm; - } -}; - -template void NormalizeGradientOp::DoNormalize( const T* xData, const T* gOutData, diff --git a/caffe2/operators/normalize_op.h b/caffe2/operators/normalize_op.h index 065484d..57c42e6 100644 --- a/caffe2/operators/normalize_op.h +++ b/caffe2/operators/normalize_op.h @@ -3,6 +3,7 @@ #include "caffe2/core/context.h" #include "caffe2/core/operator.h" +#include "caffe2/utils/eigen_utils.h" #include "caffe2/utils/math.h" #define KEPS 1e-12f @@ -35,8 +36,27 @@ class NormalizeOp final : public Operator { private: const T kEps_ = KEPS; - void - DoNormalize(const T* xData, T* yData, const int m, const int n, const int sf); + void DoNormalize( + const T* xData, + T* yData, + const int m, + const int n, + const int sf) { + using InnerStride = Eigen::InnerStride; + using StridedVec = + Eigen::Map, 0, InnerStride>; + using ConstStridedVec = + Eigen::Map, 0, InnerStride>; + + for (int i = 0; i < n; ++i) { + auto base = (i / sf) * sf * m + (i % sf); + ConstStridedVec xVec(xData + base, 1, m, InnerStride(sf)); + auto norm = xVec.template lpNorm<2>(); + norm = std::max(norm, kEps_); + StridedVec yVec(yData + base, 1, m, InnerStride(sf)); + yVec = xVec / norm; + } + } }; template -- 2.7.4