[mlpack-git] master: Throw a runtime_error exception for start/stop (607a132)
gitdub at big.cc.gt.atl.ga.us
gitdub at big.cc.gt.atl.ga.us
Thu Nov 19 11:34:54 EST 2015
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/713fa60a06f709bc715c4dd88f6ba585796f73a0...319205b2f3103187c584db302b1a3683aa2fbfdf
>---------------------------------------------------------------
commit 607a1328ff83fcccd620472ce14cb2e5a580aaea
Author: Grzegorz Krajewski <krajekg at gmail.com>
Date: Tue Nov 17 23:01:50 2015 +0100
Throw a runtime_error exception for start/stop
Throwing a runtime_error exception after Timer::Start or Timer::Stop has been called twice.
>---------------------------------------------------------------
607a1328ff83fcccd620472ce14cb2e5a580aaea
src/mlpack/core/util/timers.cpp | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/src/mlpack/core/util/timers.cpp b/src/mlpack/core/util/timers.cpp
index 0dbd7d5..4c649b2 100644
--- a/src/mlpack/core/util/timers.cpp
+++ b/src/mlpack/core/util/timers.cpp
@@ -33,6 +33,17 @@ inline void timersub(const timeval* tvp, const timeval* uvp, timeval* vvp)
*/
void Timer::Start(const std::string& name)
{
+ if((timerState[name] == 1) && (name != "total_time"))
+ {
+ std::ostringstream error;
+ error << "Timer::Start(): timer '" << name
+ << "' has already been " << "started";
+
+ throw std::runtime_error(error.str());
+ }
+
+ timerState[name] = true;
+
CLI::GetSingleton().timer.StartTimer(name);
}
@@ -41,6 +52,17 @@ void Timer::Start(const std::string& name)
*/
void Timer::Stop(const std::string& name)
{
+ if((timerState[name] == 0) && (name != "total_time"))
+ {
+ std::ostringstream error;
+ error << "Timer::Stop(): timer '" << name
+ << "' has already been " << "stopped";
+
+ throw std::runtime_error(error.str());
+ }
+
+ timerState[name] = false;
+
CLI::GetSingleton().timer.StopTimer(name);
}
More information about the mlpack-git
mailing list