[mlpack-git] master: If gradient2 or gradient1 are zero, then BOOST_REQUIRE_CLOSE will fail, so use BOOST_REQUIRE_SMALL in those situations. (4ff522b)

gitdub at big.cc.gt.atl.ga.us gitdub at big.cc.gt.atl.ga.us
Thu Mar 5 22:02:56 EST 2015


Repository : https://github.com/mlpack/mlpack

On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/904762495c039e345beba14c1142fd719b3bd50e...f94823c800ad6f7266995c700b1b630d5ffdcf40

>---------------------------------------------------------------

commit 4ff522b05323d710bbbed360c4d3f2b6d0916468
Author: Ryan Curtin <ryan at ratml.org>
Date:   Mon Nov 10 16:56:39 2014 +0000

    If gradient2 or gradient1 are zero, then BOOST_REQUIRE_CLOSE will fail, so use
    BOOST_REQUIRE_SMALL in those situations.


>---------------------------------------------------------------

4ff522b05323d710bbbed360c4d3f2b6d0916468
 src/mlpack/tests/regularized_svd_test.cpp | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/mlpack/tests/regularized_svd_test.cpp b/src/mlpack/tests/regularized_svd_test.cpp
index 3d35c76..7b03466 100644
--- a/src/mlpack/tests/regularized_svd_test.cpp
+++ b/src/mlpack/tests/regularized_svd_test.cpp
@@ -176,8 +176,15 @@ BOOST_AUTO_TEST_CASE(RegularizedSVDFunctionGradient)
       parameters(i, j) += epsilon;
 
       // Compare numerical and backpropagation gradient values.
-      BOOST_REQUIRE_CLOSE(numGradient1, gradient1(i, j), 1e-2);
-      BOOST_REQUIRE_CLOSE(numGradient2, gradient2(i, j), 1e-2);
+      if (gradient1(i, j) == 0.0)
+        BOOST_REQUIRE_SMALL(numGradient1, 1e-5);
+      else
+        BOOST_REQUIRE_CLOSE(numGradient1, gradient1(i, j), 1e-2);
+
+      if (graident2(i, j) == 0.0)
+        BOOST_REQUIRE_SMALL(numGradient2, 1e-5);
+      else
+        BOOST_REQUIRE_CLOSE(numGradient2, gradient2(i, j), 1e-2);
     }
   }
 }



More information about the mlpack-git mailing list