You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@singa.apache.org by wa...@apache.org on 2019/03/13 15:35:44 UTC

[incubator-singa] branch master updated: hf:reshape error

This is an automated email from the ASF dual-hosted git repository.

wangwei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-singa.git


The following commit(s) were added to refs/heads/master by this push:
     new 819d16c  hf:reshape error
     new 37d8717  Merge pull request #440 from dcslin/dcs/hf
819d16c is described below

commit 819d16cfa928f7e5b7d69b9162392d38d7d93107
Author: dcslin <sh...@comp.nus.edu.sg>
AuthorDate: Wed Mar 13 08:53:55 2019 +0000

    hf:reshape error
---
 src/model/operation/batchnorm.cc | 7 +++++--
 test/singa/test_cross_entropy.cc | 2 +-
 test/singa/test_tensor.cc        | 8 ++++----
 3 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/src/model/operation/batchnorm.cc b/src/model/operation/batchnorm.cc
index 6e0416e..d187420 100755
--- a/src/model/operation/batchnorm.cc
+++ b/src/model/operation/batchnorm.cc
@@ -195,8 +195,11 @@ const std::vector<Tensor> CpuBatchNormBackwardx(const BatchNormHandle &bnh,
   }, {x.block(), dy.block(), mean.block(), var.block()},
   {dx.block(), dw.block()});
 
-  Tensor dbnScale = CopyRows(dw, 0, bnScale.Size()).Reshape({bnScale.Size()});
-  Tensor dbnBias = CopyRows(dw, 1, bnBias.Size()).Reshape({bnBias.Size()});
+  singa::Tensor dbnScale(bnScale.shape());
+  CopyDataToFrom(&dbnScale, dw, bnScale.Size(), 0, 0);
+  singa::Tensor dbnBias(bnBias.shape());
+  CopyDataToFrom(&dbnBias, dw, bnBias.Size(), 0, bnScale.Size());
+
   CHECK(dbnScale.nDim() == bnScale.nDim()) << "dbnScale ndim not match bnScale";
   CHECK(dbnBias.nDim() == bnBias.nDim()) << "dbnScale ndim not match bnScale";
   CHECK(dbnScale.shape()[0] == bnScale.shape()[0]) << "dbnScale shape not match bnScale";
diff --git a/test/singa/test_cross_entropy.cc b/test/singa/test_cross_entropy.cc
index a4904f0..7a412dc 100644
--- a/test/singa/test_cross_entropy.cc
+++ b/test/singa/test_cross_entropy.cc
@@ -31,7 +31,7 @@ class TestSoftmaxCrossEntropy : public ::testing::Test {
   virtual void SetUp() {
     p.SetShape(singa::Shape{2, 4});
     t.SetShape(singa::Shape{2, 1});
-    ta.Reshape(singa::Shape{2, 4});
+    ta.SetShape(singa::Shape{2, 4});
   }
   const float pdat[8] = {0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f, 0.1f };
   const int tdat[2] = {0, 2};
diff --git a/test/singa/test_tensor.cc b/test/singa/test_tensor.cc
index c8df3ee..e31d99b 100644
--- a/test/singa/test_tensor.cc
+++ b/test/singa/test_tensor.cc
@@ -53,18 +53,18 @@ TEST(TensorTest, TestConstructor) {
 
 TEST(TensorClass, Reshape) {
   Tensor t;
-  t.Reshape(Shape{2,3});
+  t.SetShape(Shape{2,3});
   EXPECT_TRUE((Shape{2,3} == t.shape()));
 
-  t.Reshape(Shape{3,3, 4});
+  t.SetShape(Shape{3,3, 4});
   EXPECT_TRUE((Shape{3,3, 4} == t.shape()));
 
-  t.Reshape(Shape{12});
+  t.SetShape(Shape{12});
   EXPECT_TRUE((Shape{12} == t.shape()));
 
   Tensor o;
   EXPECT_TRUE(o.shape() != t.shape());
-  o.Reshape(Shape{3, 3});
+  o.SetShape(Shape{3, 3});
   EXPECT_TRUE(o.shape() != t.shape());
 }