[mlpack-git] master: Update names to avoid collisions. (086a75d)

gitdub at mlpack.org gitdub at mlpack.org
Tue Mar 15 15:47:28 EDT 2016


Repository : https://github.com/mlpack/mlpack
On branch  : master
Link       : https://github.com/mlpack/mlpack/compare/386138b3172e0485aced365cb31e4f5b13c3bd7d...086a75de129a97ff575c555630084c583b8ae15c

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

commit 086a75de129a97ff575c555630084c583b8ae15c
Author: Ryan Curtin <ryan at ratml.org>
Date:   Tue Mar 15 12:47:10 2016 -0700

    Update names to avoid collisions.


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

086a75de129a97ff575c555630084c583b8ae15c
 src/mlpack/core/util/timers.cpp | 50 ++++++++++++++++++++---------------------
 1 file changed, 24 insertions(+), 26 deletions(-)

diff --git a/src/mlpack/core/util/timers.cpp b/src/mlpack/core/util/timers.cpp
index fa0fd60..4e6cd98 100644
--- a/src/mlpack/core/util/timers.cpp
+++ b/src/mlpack/core/util/timers.cpp
@@ -13,6 +13,7 @@
 #include <string>
 
 using namespace mlpack;
+using namespace std::chrono;
 
 /**
  * Start the given timer.
@@ -33,17 +34,17 @@ void Timer::Stop(const std::string& name)
 /**
  * Get the given timer.
  */
-std::chrono::microseconds Timer::Get(const std::string& name)
+microseconds Timer::Get(const std::string& name)
 {
   return CLI::GetSingleton().timer.GetTimer(name);
 }
 
-std::map<std::string, std::chrono::microseconds>& Timers::GetAllTimers()
+std::map<std::string, microseconds>& Timers::GetAllTimers()
 {
   return timers;
 }
 
-std::chrono::microseconds Timers::GetTimer(const std::string& timerName)
+microseconds Timers::GetTimer(const std::string& timerName)
 {
   return timers[timerName];
 }
@@ -55,9 +56,6 @@ bool Timers::GetState(std::string timerName)
 
 void Timers::PrintTimer(const std::string& timerName)
 {
-  // To make things shorter.
-  using std::chrono;
-
   microseconds totalDuration = timers[timerName];
   // Convert microseconds to seconds.
   seconds totalDurationSec = duration_cast<seconds>(totalDuration);
@@ -69,44 +67,44 @@ void Timers::PrintTimer(const std::string& timerName)
   // Also output convenient day/hr/min/sec.
   // The following line is a custom duration for a day.
   typedef duration<int, std::ratio<60 * 60 * 24, 1>> days;
-  days days = duration_cast<days>(totalDuration);
-  hours hours = duration_cast<hours>(totalDuration % days(1));
-  minutes minutes = duration_cast<minutes>(totalDuration % hours(1));
-  seconds seconds = duration_cast<seconds>(totalDuration % minutes(1));
+  days d = duration_cast<days>(totalDuration);
+  hours h = duration_cast<hours>(totalDuration % days(1));
+  minutes m = duration_cast<minutes>(totalDuration % hours(1));
+  seconds s = duration_cast<seconds>(totalDuration % minutes(1));
   // No output if it didn't even take a minute.
-  if (!(days.count() == 0 && hours.count() == 0 && minutes.count() == 0))
+  if (!(d.count() == 0 && h.count() == 0 && m.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.count() > 0)
+    if (d.count() > 0)
     {
-      Log::Info << days.count() << " days";
+      Log::Info << d.count() << " days";
       output = true;
     }
 
-    if (hours.count() > 0)
+    if (h.count() > 0)
     {
       if (output)
         Log::Info << ", ";
-      Log::Info << hours.count() << " hrs";
+      Log::Info << h.count() << " hrs";
       output = true;
     }
 
-    if (minutes.count() > 0)
+    if (m.count() > 0)
     {
       if (output)
         Log::Info << ", ";
-      Log::Info << minutes.count() << " mins";
+      Log::Info << m.count() << " mins";
       output = true;
     }
 
-    if (seconds.count() > 0)
+    if (s.count() > 0)
     {
       if (output)
         Log::Info << ", ";
-      Log::Info << seconds.count() << "." << std::setw(1)
+      Log::Info << s.count() << "." << std::setw(1)
           << (totalDurationMicroSec.count() / 100000) << " secs";
       output = true;
     }
@@ -117,9 +115,9 @@ void Timers::PrintTimer(const std::string& timerName)
   Log::Info << std::endl;
 }
 
-std::chrono::high_resolution_clock::time_point Timers::GetTime()
+high_resolution_clock::time_point Timers::GetTime()
 {
-  return std::chrono::high_resolution_clock::now();
+  return high_resolution_clock::now();
 }
 
 void Timers::StartTimer(const std::string& timerName)
@@ -134,12 +132,12 @@ void Timers::StartTimer(const std::string& timerName)
 
   timerState[timerName] = true;
 
-  std::chrono::high_resolution_clock::time_point currTime = GetTime();
+  high_resolution_clock::time_point currTime = GetTime();
 
   // If the timer is added first time
   if (timers.count(timerName) == 0)
   {
-    timers[timerName] = (std::chrono::microseconds)0;
+    timers[timerName] = (microseconds) 0;
   }
 
   timerStartTime[timerName] = currTime;
@@ -157,9 +155,9 @@ void Timers::StopTimer(const std::string& timerName)
 
   timerState[timerName] = false;
 
-  std::chrono::high_resolution_clock::time_point currTime = GetTime();
+  high_resolution_clock::time_point currTime = GetTime();
 
   // Calculate the delta time.
-  timers[timerName] += std::chrono::duration_cast<std::chrono::microseconds>(
-      currTime - timerStartTime[timerName])
+  timers[timerName] += duration_cast<microseconds>(currTime -
+      timerStartTime[timerName]);
 }




More information about the mlpack-git mailing list