From bc2b521c241f903b56596b9a52d50c6f59bc9002 Mon Sep 17 00:00:00 2001 From: liaogang Date: Wed, 9 Nov 2016 12:07:19 +0800 Subject: [PATCH] Follow comments --- paddle/gserver/tests/test_LayerGrad.cpp | 18 +++++------------- paddle/math/Matrix.cpp | 12 ++++++++---- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/paddle/gserver/tests/test_LayerGrad.cpp b/paddle/gserver/tests/test_LayerGrad.cpp index 0c18611f010..d8c45040d86 100644 --- a/paddle/gserver/tests/test_LayerGrad.cpp +++ b/paddle/gserver/tests/test_LayerGrad.cpp @@ -43,22 +43,14 @@ TEST(Layer, BilinearInterpLayer) { bilinear->set_img_size_x(32); bilinear->set_img_size_y(32); - bilinear->set_out_size_x(64); - bilinear->set_out_size_y(64); bilinear->set_num_channels(4); for (auto useGpu : {false, true}) { - testLayerGrad(config, "bilinear_interp", 10, false, useGpu); - } - - bilinear->set_img_size_x(32); - bilinear->set_img_size_y(32); - bilinear->set_out_size_x(32); - bilinear->set_out_size_y(32); - bilinear->set_num_channels(4); - - for (auto useGpu : {false, true}) { - testLayerGrad(config, "bilinear_interp", 10, false, useGpu); + for (auto out_size : {32, 64, 128}) { + bilinear->set_out_size_x(out_size); + bilinear->set_out_size_y(out_size); + testLayerGrad(config, "bilinear_interp", 10, false, useGpu); + } } } diff --git a/paddle/math/Matrix.cpp b/paddle/math/Matrix.cpp index 4770a720349..80bf74bd4c5 100644 --- a/paddle/math/Matrix.cpp +++ b/paddle/math/Matrix.cpp @@ -3902,6 +3902,8 @@ void CpuMatrix::bilinearForward(const Matrix& in, size_t batchSize = getHeight(); size_t inputW = in.getWidth(); size_t inputH = in.getHeight(); + size_t inPosOffset = inImgH * inImgW; + size_t outPosOffset = outImgH * outImgW; (void)(inputH); real* outData = getData(); @@ -3931,8 +3933,8 @@ void CpuMatrix::bilinearForward(const Matrix& in, h2lambda * (w2lambda * inPos[0] + w1lambda * inPos[wid]) + h1lambda * (w2lambda * inPos[hid * inImgW] + w1lambda * inPos[hid * inImgW + wid]); - inPos += inImgH * inImgW; - outPos += outImgH * outImgW; + inPos += inPosOffset; + outPos += outPosOffset; } } } @@ -3954,6 +3956,8 @@ void CpuMatrix::bilinearBackward(const Matrix& out, size_t inputH = getHeight(); size_t outputW = out.getWidth(); size_t batchSize = out.getHeight(); + size_t inPosOffset = inImgH * inImgW; + size_t outPosOffset = outImgH * outImgW; (void)(inputH); real* inGrad = getData(); @@ -3981,8 +3985,8 @@ void CpuMatrix::bilinearBackward(const Matrix& out, inPos[wid] += h2lambda * w1lambda * outPos[0]; inPos[hid * inImgW] += h1lambda * w2lambda * outPos[0]; inPos[hid * inImgW + wid] += h1lambda * w1lambda * outPos[0]; - inPos += inImgH * inImgW; - outPos += outImgH * outImgW; + inPos += inPosOffset; + outPos += outPosOffset; } } } -- GitLab