[mlpack-git] master: Incorporated comments from pull requests for issue #498 (5354f5d)

gitdub at mlpack.org gitdub at mlpack.org
Mon Mar 14 13:42:25 EDT 2016


Repository : https://github.com/mlpack/mlpack
On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/f77416e9ab5bb5d327805f7cb61bf206431ddfed...c0886a18f63c9335a0c39dcc34c27b8925dcb91b

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

commit 5354f5d2d9918fccef1b826e1cb20a9070eb634d
Author: na1taneja2821 <namantaneja821 at gmail.com>
Date:   Mon Mar 14 23:12:25 2016 +0530

    Incorporated comments from pull requests for issue #498


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

5354f5d2d9918fccef1b826e1cb20a9070eb634d
 src/mlpack/core/util/cli.hpp    |  9 ---------
 src/mlpack/core/util/timers.cpp | 39 ++++++++++++++++++++-------------------
 src/mlpack/core/util/timers.hpp | 11 +++++------
 src/mlpack/tests/cli_test.cpp   |  1 -
 4 files changed, 25 insertions(+), 35 deletions(-)

diff --git a/src/mlpack/core/util/cli.hpp b/src/mlpack/core/util/cli.hpp
index 860e131..fc1000f 100644
--- a/src/mlpack/core/util/cli.hpp
+++ b/src/mlpack/core/util/cli.hpp
@@ -721,15 +721,6 @@ class CLI
    */
   static std::string AliasReverseLookup(const std::string& value);
 
-#ifdef _WIN32
-  /**
-   * Converts a FILETIME structure to an equivalent timeval structure.
-   * Only necessary on windows platforms.
-   * @param tv Valid timeval structure.
-   */
-  void FileTimeToTimeVal(timeval* tv);
-#endif
-
   /**
    * Checks that all required parameters have been specified on the command
    * line.  If any have not been specified, an error message is printed and the
diff --git a/src/mlpack/core/util/timers.cpp b/src/mlpack/core/util/timers.cpp
index eaf6255..d23ae8a 100644
--- a/src/mlpack/core/util/timers.cpp
+++ b/src/mlpack/core/util/timers.cpp
@@ -61,52 +61,53 @@ bool Timers::GetState(std::string timerName)
 
 void Timers::PrintTimer(const std::string& timerName)
 {
-  long long int totalDuration = timers[timerName].count();
+  std::chrono::microseconds totalDuration = timers[timerName];
   // Converting microseconds to seconds
-  long long int totalDurationSec = totalDuration / 1e6;
-  long long int totalDurationMicroSec = totalDuration % 1000000;
-  Log::Info << totalDurationSec << "." << std::setw(6) << std::setfill('0')
-      << totalDurationMicroSec << "s";
+  std::chrono::seconds totalDurationSec = std::chrono::duration_cast<std::chrono::seconds>(totalDuration);
+  std::chrono::microseconds totalDurationMicroSec = std::chrono::duration_cast<std::chrono::microseconds>(totalDuration % std::chrono::seconds(1));
+  Log::Info << totalDurationSec.count() << "." << std::setw(6) << std::setfill('0')
+      << totalDurationMicroSec.count() << "s";
 
   // Also output convenient day/hr/min/sec.
-  int days = totalDurationSec / 86400; // Integer division rounds down.
-  int hours = (totalDurationSec % 86400) / 3600;
-  int minutes = (totalDurationSec % 3600) / 60;
-  int seconds = (totalDurationSec % 60);
+  // The following line is a custom duration for a day
+  std::chrono::duration<int, std::ratio<60*60*24,1> > days = std::chrono::duration_cast<std::chrono::duration<int, std::ratio<60*60*24,1> > >(totalDuration); // Integer division rounds down.
+  std::chrono::hours hours = std::chrono::duration_cast<std::chrono::hours>(totalDuration % std::chrono::duration<int, std::ratio<60*60*24,1> >(1));
+  std::chrono::minutes minutes = std::chrono::duration_cast<std::chrono::minutes>(totalDuration % std::chrono::hours(1));
+  std::chrono::seconds seconds = std::chrono::duration_cast<std::chrono::seconds>(totalDuration % std::chrono::minutes(1));
   // No output if it didn't even take a minute.
-  if (!(days == 0 && hours == 0 && minutes == 0))
+  if (!(days.count() == 0 && hours.count() == 0 && minutes.count() == 0))
   {
     bool output = false; // Denotes if we have output anything yet.
     Log::Info << " (";
 
     // Only output units if they have nonzero values (yes, a bit tedious).
-    if (days > 0)
+    if (days.count() > 0)
     {
-      Log::Info << days << " days";
+      Log::Info << days.count() << " days";
       output = true;
     }
 
-    if (hours > 0)
+    if (hours.count() > 0)
     {
       if (output)
         Log::Info << ", ";
-      Log::Info << hours << " hrs";
+      Log::Info << hours.count() << " hrs";
       output = true;
     }
 
-    if (minutes > 0)
+    if (minutes.count() > 0)
     {
       if (output)
         Log::Info << ", ";
-      Log::Info << minutes << " mins";
+      Log::Info << minutes.count() << " mins";
       output = true;
     }
 
-    if (seconds > 0)
+    if (seconds.count() > 0)
     {
       if (output)
         Log::Info << ", ";
-      Log::Info << seconds << "." << std::setw(1) << (totalDurationMicroSec / 100000) <<
+      Log::Info << seconds.count() << "." << std::setw(1) << (totalDurationMicroSec.count() / 100000) <<
           "secs";
       output = true;
     }
@@ -137,7 +138,7 @@ void Timers::StartTimer(const std::string& timerName)
   std::chrono::high_resolution_clock::time_point currTime = GetTime();
 
   // If the timer is added first time
-  if(timers.count(timerName) == 0)
+  if (timers.count(timerName) == 0)
   {
     timers[timerName] = (std::chrono::microseconds)0;
   }
diff --git a/src/mlpack/core/util/timers.hpp b/src/mlpack/core/util/timers.hpp
index 2ec4f82..205549c 100644
--- a/src/mlpack/core/util/timers.hpp
+++ b/src/mlpack/core/util/timers.hpp
@@ -15,11 +15,11 @@
 #if defined(_WIN32)
  // uint64_t isn't defined on every windows.
   #if !defined(HAVE_UINT64_T)
-   #if SIZEOF_UNSIGNED_LONG == 8
-     typedef unsigned long uint64_t;
-   #else
-     typedef unsigned long long  uint64_t;
-   #endif  // SIZEOF_UNSIGNED_LONG
+    #if SIZEOF_UNSIGNED_LONG == 8
+      typedef unsigned long uint64_t;
+    #else
+      typedef unsigned long long  uint64_t;
+    #endif  // SIZEOF_UNSIGNED_LONG
   #endif  // HAVE_UINT64_T
 #endif
 
@@ -123,7 +123,6 @@ class Timers
   //! A map for the starting values of the timers.
   std::map<std::string, std::chrono::high_resolution_clock::time_point> timerStartTime;
 
-  void FileTimeToTimeVal(timeval* tv);
   std::chrono::high_resolution_clock::time_point GetTime();
 };
 
diff --git a/src/mlpack/tests/cli_test.cpp b/src/mlpack/tests/cli_test.cpp
index 32b2321..b8e9171 100644
--- a/src/mlpack/tests/cli_test.cpp
+++ b/src/mlpack/tests/cli_test.cpp
@@ -7,7 +7,6 @@
 
 #include <iostream>
 #include <sstream>
-#include <chrono>
 
 #ifndef _WIN32
   #include <sys/time.h>




More information about the mlpack-git mailing list