[mlpack] 112/207: Minor style fixes.

Barak A. Pearlmutter barak+git at pearlmutter.net
Thu Mar 23 17:53:45 UTC 2017


This is an automated email from the git hooks/post-receive script.

bap pushed a commit to branch master
in repository mlpack.

commit e70270d35b5036b21a6583293377347b5222fefa
Author: Ryan Curtin <ryan at ratml.org>
Date:   Sun Mar 5 20:38:19 2017 -0500

    Minor style fixes.
---
 src/mlpack/core/util/prefixedoutstream.cpp      |  1 -
 src/mlpack/core/util/prefixedoutstream.hpp      | 14 ++++++++++++--
 src/mlpack/core/util/prefixedoutstream_impl.hpp | 21 +++++++++++----------
 src/mlpack/tests/prefixedoutstream_test.cpp     | 12 ++++++------
 4 files changed, 29 insertions(+), 19 deletions(-)

diff --git a/src/mlpack/core/util/prefixedoutstream.cpp b/src/mlpack/core/util/prefixedoutstream.cpp
index 5e73efb..0db096b 100644
--- a/src/mlpack/core/util/prefixedoutstream.cpp
+++ b/src/mlpack/core/util/prefixedoutstream.cpp
@@ -94,7 +94,6 @@ PrefixedOutStream& PrefixedOutStream::operator<<(const char* str)
   return *this;
 }
 
-
 PrefixedOutStream& PrefixedOutStream::operator<<(std::string& str)
 {
   BaseLogic<std::string>(str);
diff --git a/src/mlpack/core/util/prefixedoutstream.hpp b/src/mlpack/core/util/prefixedoutstream.hpp
index dfe3bd3..c06ef03 100644
--- a/src/mlpack/core/util/prefixedoutstream.hpp
+++ b/src/mlpack/core/util/prefixedoutstream.hpp
@@ -118,8 +118,8 @@ class PrefixedOutStream
    * Conducts the base logic required in all the operator << overloads.  Mostly
    * just a good idea to reduce copy-pasta.
    *
-   * Calls 2 different overloads to be able to output arma objects with custom
-   * precision
+   * This overload is for non-Armadillo objects, which need special handling
+   * during printing.
    *
    * @tparam T The type of the data to output.
    * @param val The The data to be output.
@@ -128,6 +128,16 @@ class PrefixedOutStream
   typename std::enable_if<!arma::is_arma_type<T>::value>::type
   BaseLogic(const T& val);
 
+  /**
+   * Conducts the base logic required in all the operator << overloads.  Mostly
+   * just a good idea to reduce copy-pasta.
+   *
+   * This overload is for Armadillo objects, which need special handling during
+   * printing.
+   *
+   * @tparam T The type of the data to output.
+   * @param val The The data to be output.
+   */
   template<typename T>
   typename std::enable_if<arma::is_arma_type<T>::value>::type
   BaseLogic(const T& val);
diff --git a/src/mlpack/core/util/prefixedoutstream_impl.hpp b/src/mlpack/core/util/prefixedoutstream_impl.hpp
index 16b14b9..4abc16c 100644
--- a/src/mlpack/core/util/prefixedoutstream_impl.hpp
+++ b/src/mlpack/core/util/prefixedoutstream_impl.hpp
@@ -32,6 +32,7 @@ PrefixedOutStream& PrefixedOutStream::operator<<(const T& s)
   return *this;
 }
 
+// For non-Armadillo types.
 template<typename T>
 typename std::enable_if<!arma::is_arma_type<T>::value>::type
 PrefixedOutStream::BaseLogic(const T& val)
@@ -136,13 +137,14 @@ PrefixedOutStream::BaseLogic(const T& val)
   }
 }
 
+// For Armadillo types.
 template<typename T>
 typename std::enable_if<arma::is_arma_type<T>::value>::type
 PrefixedOutStream::BaseLogic(const T& val)
 {
-
-  // Extract printable object from the input
+  // Extract printable object from the input.
   auto printVal = arma::unwrap<T>(val).M;
+
   // We will use this to track whether or not we need to terminate at the end of
   // this call (only for streams which terminate after a newline).
   bool newlined = false;
@@ -153,9 +155,9 @@ PrefixedOutStream::BaseLogic(const T& val)
 
   std::ostringstream convert;
 
-  // Check if the stream is in the default state
-  if(destination.flags() == convert.flags() && 
-     destination.precision() == convert.precision())
+  // Check if the stream is in the default state.
+  if (destination.flags() == convert.flags() &&
+      destination.precision() == convert.precision())
   {
     arma::arma_ostream::print(convert, printVal, true);
   }
@@ -169,10 +171,9 @@ PrefixedOutStream::BaseLogic(const T& val)
     auto absVal = arma::abs(printVal).P.Q;
     double maxVal = absVal.max();
 
-    if(maxVal == 0.f)
-    {
-        maxVal = 1;
-    }
+    if (maxVal == 0.0)
+      maxVal = 1;
+
     int maxLog = log10(maxVal);
     maxLog = (maxLog > 0) ? floor(maxLog) + 1 : 1;
     const int padding = 4;
@@ -285,4 +286,4 @@ void PrefixedOutStream::PrefixIfNeeded()
 } // namespace util
 } // namespace mlpack
 
-#endif // MLPACK_CLI_PREFIXEDOUTSTREAM_IMPL_H
+#endif // MLPACK_CORE_UTIL_PREFIXEDOUTSTREAM_IMPL_HPP
diff --git a/src/mlpack/tests/prefixedoutstream_test.cpp b/src/mlpack/tests/prefixedoutstream_test.cpp
index e69fe48..5eabc6a 100644
--- a/src/mlpack/tests/prefixedoutstream_test.cpp
+++ b/src/mlpack/tests/prefixedoutstream_test.cpp
@@ -170,12 +170,12 @@ BOOST_AUTO_TEST_CASE(TestArmaCustomPrecision)
 {
   std::stringstream ss;
   PrefixedOutStream pss(ss, BASH_GREEN "[INFO ] " BASH_CLEAR);
-  // The vector to be tested
+  // The vector to be tested.
   arma::vec test("1.0 1.5 2.0 2.5 3.0 3.5 4.0");
-  // The matrix to be tested
+  // The matrix to be tested.
   arma::mat test2("1.0 1.5 2.0; 2.5 3.0 3.5; 4.0 4.5 4.99999");
 
-  // Try to print armadillo objects with custom precision
+  // Try to print armadillo objects with custom precision.
   ss << std::fixed;
   ss << std::setprecision(6);
   ss.str("");
@@ -200,7 +200,7 @@ BOOST_AUTO_TEST_CASE(TestArmaCustomPrecision)
       "   1.000000   1.500000   2.000000   2.500000"
       "   3.000000   3.500000   4.000000\n");
 
-  // Try printing a matrix, with higher precision
+  // Try printing a matrix, with higher precision.
   ss << std::setprecision(8);
   ss.str("");
 
@@ -214,7 +214,7 @@ BOOST_AUTO_TEST_CASE(TestArmaCustomPrecision)
       BASH_GREEN "[INFO ] " BASH_CLEAR
       "   4.00000000   4.50000000   4.99999000\n");
 
-  // Try alignment with larger values
+  // Try alignment with larger values.
   test2.at(2) = 40;
   ss.str("");
   pss << trans(test2);
@@ -227,7 +227,7 @@ BOOST_AUTO_TEST_CASE(TestArmaCustomPrecision)
       BASH_GREEN "[INFO ] " BASH_CLEAR 
       "    2.00000000    3.50000000    4.99999000\n");
 
-  // Test stream after reset
+  // Test stream after reset.
   test2.at(2) = 4;
   ss << std::setprecision(6);
   ss.unsetf(std::ios::floatfield);

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/mlpack.git



More information about the debian-science-commits mailing list