chrishkchris commented on a change in pull request #552: SINGA-496 Implement
softplus and softsign functions for tensor math
URL: https://github.com/apache/singa/pull/552#discussion_r347767285
##########
File path: test/singa/test_tensor_math.cc
##########
@@ -120,6 +120,32 @@ TEST_F(TensorMath, SignCpp) {
EXPECT_EQ(1.0f, dptr1[2]);
}
+TEST_F(TensorMath, SoftPlusCpp) {
+ Tensor aa = a.Clone();
+ Tensor cc = aa - 1.0f;
+ const float *dptr = cc.data<float>();
+ EXPECT_NEAR(0.0f, dptr[0], 1e-5);
+ EXPECT_NEAR(1.0f, dptr[1], 1e-5);
+
+ Tensor p = SoftPlus(cc);
+ const float *dptr1 = p.data<float>();
+ EXPECT_EQ(log(2.0f), dptr1[0]);
+ EXPECT_EQ(log(exp(1) + 1.0f), dptr1[1]);
+}
Review comment:
It is almost okay: there are two failed unit tests SoftPlusCpp, and
SoftPlusCuda:
```
[ RUN ] TensorMath.SoftPlusCpp
/home/ubuntu/incubator-singa/test/singa/test_tensor_math.cc:132: Failure
Value of: dptr1[0]
Actual: 0.693147
Expected: log(2.0f)
Which is: 0.693147
/home/ubuntu/incubator-singa/test/singa/test_tensor_math.cc:133: Failure
Value of: dptr1[1]
Actual: 1.31326
Expected: log(exp(1) + 1.0f)
Which is: 1.31326
[ FAILED ] TensorMath.SoftPlusCpp (0 ms)
.
.
.
[ RUN ] TensorMath.SoftPlusCuda
/home/ubuntu/incubator-singa/test/singa/test_tensor_math.cc:1243: Failure
Value of: log(2.0f)
Actual: 0.693147
Expected: dptr[0]
Which is: 0.693147
/home/ubuntu/incubator-singa/test/singa/test_tensor_math.cc:1244: Failure
Value of: log(exp(1) + 1.0f)
Actual: 1.31326
Expected: dptr[1]
Which is: 1.31326
[ FAILED ] TensorMath.SoftPlusCuda (5 ms)
.
.
.
[ FAILED ] 2 tests, listed below:
[ FAILED ] TensorMath.SoftPlusCpp
[ FAILED ] TensorMath.SoftPlusCuda
```
This can be simply solved by changing the line EXPECT_EQ to EXPECT_NEAR with
the error limit of 1e-5.
Four lines are needed to change: line 132,133, 1243, 1244
Then the test will be passed and my review is done :)
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services