[mlpack-git] master: Be explicit with calls to arma:: functions. Although gcc accepts this as-is, we don't have a guarantee that all compilers will. (af949b5)

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


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

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

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

commit af949b58ca4e798e56e3cdc9a71424c455ccfa49
Author: Ryan Curtin <ryan at ratml.org>
Date:   Wed Nov 5 19:52:12 2014 +0000

    Be explicit with calls to arma:: functions.  Although gcc accepts this as-is, we
    don't have a guarantee that all compilers will.


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

af949b58ca4e798e56e3cdc9a71424c455ccfa49
 .../methods/sparse_coding/sparse_coding_impl.hpp       | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/src/mlpack/methods/sparse_coding/sparse_coding_impl.hpp b/src/mlpack/methods/sparse_coding/sparse_coding_impl.hpp
index 3f212b4..7919c20 100644
--- a/src/mlpack/methods/sparse_coding/sparse_coding_impl.hpp
+++ b/src/mlpack/methods/sparse_coding/sparse_coding_impl.hpp
@@ -149,7 +149,7 @@ double SparseCoding<DictionaryInitializer>::OptimizeDictionary(
 
   for (size_t j = 0; j < atoms; ++j)
   {
-    if (accu(codes.row(j) != 0) == 0)
+    if (arma::accu(codes.row(j) != 0) == 0)
       inactiveAtoms.push_back(j);
   }
 
@@ -231,11 +231,11 @@ double SparseCoding<DictionaryInitializer>::OptimizeDictionary(
     while (true)
     {
       // Calculate objective.
-      double sumDualVars = sum(dualVars);
+      double sumDualVars = arma::sum(dualVars);
       double fOld = -(-trace(trans(codesXT) * matAInvZXT) - sumDualVars);
       double fNew = -(-trace(trans(codesXT) * solve(codesZT +
           diagmat(dualVars + alpha * searchDirection), codesXT)) -
-          (sumDualVars + alpha * sum(searchDirection)));
+          (sumDualVars + alpha * arma::sum(searchDirection)));
 
       if (fNew <= fOld + alpha * sufficientDecrease)
       {
@@ -249,7 +249,7 @@ double SparseCoding<DictionaryInitializer>::OptimizeDictionary(
 
     // Take step and print useful information.
     dualVars += searchDirection;
-    normGradient = norm(gradient, 2);
+    normGradient = arma::norm(gradient, 2);
     Log::Debug << "Newton Method iteration " << t << ":" << std::endl;
     Log::Debug << "  Gradient norm: " << std::scientific << normGradient
         << "." << std::endl;
@@ -280,7 +280,7 @@ double SparseCoding<DictionaryInitializer>::OptimizeDictionary(
                              data.col(math::RandInt(data.n_cols)) +
                              data.col(math::RandInt(data.n_cols)));
 
-        dictionary.col(i) /= norm(dictionary.col(i), 2);
+        dictionary.col(i) /= arma::norm(dictionary.col(i), 2);
 
         // Increment inactive index counter.
         ++currentInactiveIndex;
@@ -302,7 +302,7 @@ void SparseCoding<DictionaryInitializer>::ProjectDictionary()
 {
   for (size_t j = 0; j < atoms; j++)
   {
-    double atomNorm = norm(dictionary.col(j), 2);
+    double atomNorm = arma::norm(dictionary.col(j), 2);
     if (atomNorm > 1)
     {
       Log::Info << "Norm of atom " << j << " exceeds 1 (" << std::scientific
@@ -316,12 +316,12 @@ void SparseCoding<DictionaryInitializer>::ProjectDictionary()
 template<typename DictionaryInitializer>
 double SparseCoding<DictionaryInitializer>::Objective() const
 {
-  double l11NormZ = sum(sum(abs(codes)));
-  double froNormResidual = norm(data - (dictionary * codes), "fro");
+  double l11NormZ = arma::sum(arma::sum(arma::abs(codes)));
+  double froNormResidual = arma::norm(data - (dictionary * codes), "fro");
 
   if (lambda2 > 0)
   {
-    double froNormZ = norm(codes, "fro");
+    double froNormZ = arma::norm(codes, "fro");
     return 0.5 * (std::pow(froNormResidual, 2.0) + (lambda2 *
         std::pow(froNormZ, 2.0))) + (lambda1 * l11NormZ);
   }



More information about the mlpack-git mailing list