[mlpack-svn] r10767 - in mlpack/trunk/src/mlpack: . core/io core/utilities methods/emst methods/gmm methods/naive_bayes methods/neighbor_search methods/range_search
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Wed Dec 14 07:11:41 EST 2011
Author: rcurtin
Date: 2011-12-14 07:11:41 -0500 (Wed, 14 Dec 2011)
New Revision: 10767
Added:
mlpack/trunk/src/mlpack/core/io/timers.cpp
mlpack/trunk/src/mlpack/core/io/timers.hpp
Removed:
mlpack/trunk/src/mlpack/core/utilities/timers.cpp
mlpack/trunk/src/mlpack/core/utilities/timers.hpp
Modified:
mlpack/trunk/src/mlpack/core.hpp
mlpack/trunk/src/mlpack/core/io/CMakeLists.txt
mlpack/trunk/src/mlpack/core/io/cli.cpp
mlpack/trunk/src/mlpack/core/io/cli.hpp
mlpack/trunk/src/mlpack/core/io/cli_impl.hpp
mlpack/trunk/src/mlpack/core/utilities/CMakeLists.txt
mlpack/trunk/src/mlpack/methods/emst/dtb_impl.hpp
mlpack/trunk/src/mlpack/methods/gmm/gmm_main.cpp
mlpack/trunk/src/mlpack/methods/naive_bayes/nbc_main.cpp
mlpack/trunk/src/mlpack/methods/neighbor_search/allkfn_main.cpp
mlpack/trunk/src/mlpack/methods/neighbor_search/allknn_main.cpp
mlpack/trunk/src/mlpack/methods/neighbor_search/neighbor_search_impl.hpp
mlpack/trunk/src/mlpack/methods/range_search/range_search_impl.hpp
Log:
Clean up CLI output again and again. Then change how Timers works because it
was being destructed before CLI in some cases. That's the danger of
singletons...
Modified: mlpack/trunk/src/mlpack/core/io/CMakeLists.txt
===================================================================
--- mlpack/trunk/src/mlpack/core/io/CMakeLists.txt 2011-12-14 11:42:54 UTC (rev 10766)
+++ mlpack/trunk/src/mlpack/core/io/CMakeLists.txt 2011-12-14 12:11:41 UTC (rev 10767)
@@ -17,6 +17,8 @@
prefixedoutstream.hpp
prefixedoutstream.cpp
prefixedoutstream_impl.hpp
+ timers.hpp
+ timers.cpp
)
# add directory name to sources
Modified: mlpack/trunk/src/mlpack/core/io/cli.cpp
===================================================================
--- mlpack/trunk/src/mlpack/core/io/cli.cpp 2011-12-14 11:42:54 UTC (rev 10766)
+++ mlpack/trunk/src/mlpack/core/io/cli.cpp 2011-12-14 12:11:41 UTC (rev 10767)
@@ -27,7 +27,6 @@
#include "cli.hpp"
#include "log.hpp"
-#include "../utilities/timers.hpp"
#include "option.hpp"
@@ -44,8 +43,7 @@
/* Constructors, Destructors, Copy */
/* Make the constructor private, to preclude unauthorized instances */
-CLI::CLI() : desc("Allowed Options") , did_parse(false),
- doc(&empty_program_doc)
+CLI::CLI() : desc("Allowed Options") , did_parse(false), doc(&empty_program_doc)
{
return;
}
@@ -71,22 +69,23 @@
CLI::~CLI()
{
// Terminate the program timer.
- Timers::StopTimer("total_time");
+ Timer::Stop("total_time");
// Did the user ask for verbose output? If so we need to print everything.
// But only if the user did not ask for help or info.
- if (HasParam("verbose"))
+ if (HasParam("verbose") && !HasParam("help") && !HasParam("info"))
{
- Log::Info << "Execution parameters:" << std::endl;
+ Log::Info << std::endl << "Execution parameters:" << std::endl;
Print();
Log::Info << "Program timers:" << std::endl;
- std::map<std::string, timeval> times = Timers::GetAllTimers();
- std::map<std::string, timeval>::iterator iter;
- for (iter = times.begin(); iter != times.end(); iter++)
+ std::map<std::string, timeval>::iterator it;
+ for (it = timer.GetAllTimers().begin(); it != timer.GetAllTimers().end();
+ ++it)
{
- Log::Info << "\t" << iter->first << ": ";
- Timers::PrintTimer(iter->first.c_str());
+ std::string i = (*it).first;
+ Log::Info << " " << i << ": ";
+ timer.PrintTimer((*it).first.c_str());
}
}
@@ -120,20 +119,19 @@
std::string tmp = TYPENAME(bool);
std::string path = identifier;
std::string stringAlias = alias;
- std::string prog_opt_id = path; //Use boost's syntax for aliasing.
+ std::string prog_opt_id = path; // Use boost's syntax for aliasing.
- //deal with a required alias
+ // Deal with a required alias.
if (stringAlias.length()) {
amap_t& amap = GetSingleton().aliasValues;
amap[stringAlias] = path;
prog_opt_id = path + "," + alias;
}
- //Add the option to boost::program_options.
- desc.add_options()
- (prog_opt_id.c_str(), description);
+ // Add the option to boost::program_options.
+ desc.add_options()(prog_opt_id.c_str(), description);
- //Make sure the description etc ends up in gmap
+ // Make sure the description, etc. ends up in gmap.
gmap_t& gmap = GetSingleton().globalValues;
ParamData data;
data.desc = description;
@@ -198,21 +196,21 @@
gmap_t& gmap = GetSingleton().globalValues;
std::string key = identifier;
- //Take any possible alias into account
- amap_t& amap = GetSingleton().aliasValues;
+ // Take any possible alias into account.
+ amap_t& amap = GetSingleton().aliasValues;
if (amap.count(key))
- key = amap[key];
+ key = amap[key];
- //Does the parameter exist at all?
+ // Does the parameter exist at all?
int isInGmap = gmap.count(key);
// Check if the parameter is boolean; if it is, we just want to see if it was
- if(isInGmap && gmap[key].isFlag)
+ // passed.
+ if(isInGmap)
return gmap[key].wasPassed;
-
-
- // Return true if we have a defined value for identifier.
- return isInGmap != 0;
+
+ // The parameter was not passed in; return false.
+ return false;
}
/**
@@ -229,14 +227,14 @@
//Take any possible alias into account
amap_t& amap = GetSingleton().aliasValues;
if (amap.count(name))
- name = amap[name];
+ name = amap[name];
if(gmap.count(name))
return gmap[name].desc;
else
return "";
-
+
}
// Returns the sole instance of this class.
@@ -256,6 +254,8 @@
*/
void CLI::ParseCommandLine(int argc, char** line)
{
+ Timer::Start("total_time");
+
po::variables_map& vmap = GetSingleton().vmap;
po::options_description& desc = GetSingleton().desc;
@@ -274,8 +274,6 @@
UpdateGmap();
DefaultMessages();
RequiredOptions();
-
- Timers::StartTimer("total_time");
}
/**
@@ -305,7 +303,7 @@
DefaultMessages();
RequiredOptions();
- Timers::StartTimer("total_time");
+ Timer::Start("total_time");
}
/**
@@ -378,6 +376,7 @@
{
Log::Info.ignoreInput = false;
std::string str = GetParam<std::string>("info");
+
// The info node should always be there, but the user may not have specified
// anything.
if (str != "")
@@ -385,10 +384,17 @@
PrintHelp(str);
exit(0);
}
+
+ // Otherwise just print the generalized help.
+ PrintHelp();
+ exit(0);
}
if (GetParam<bool>("verbose"))
+ {
+ // Give [INFO ] output.
Log::Info.ignoreInput = false;
+ }
// Notify the user if we are debugging. This is not done in the constructor
// because the output streams may not be set up yet. We also don't want this
@@ -412,7 +418,6 @@
std::string str = *iter;
if (!vmap.count(str))
{ // If a required option isn't there...
- Timers::StopTimer("total_time"); // Execution stops here, pretty much.
Log::Fatal << "Required option --" << str.c_str() << " is undefined."
<< std::endl;
}
@@ -426,23 +431,20 @@
gmap_t::iterator iter;
// Print out all the values.
- Log::Info << std::endl << "Values: " << std::endl;
for (iter = gmap.begin(); iter != gmap.end(); iter++)
{
std::string key = iter->first;
- std::string alias = AliasReverseLookup(key);
- alias = alias.length() ? ", -" + alias : alias;
- Log::Info << " --" << key << alias << " : ";
+ Log::Info << " " << key << ": ";
- //Now, figure out what type it is, and print it.
- //We can handle strings, ints, bools, floats, doubles.
+ // Now, figure out what type it is, and print it.
+ // We can handle strings, ints, bools, floats, doubles.
ParamData data = iter->second;
if (data.tname == TYPENAME(std::string))
{
std::string value = GetParam<std::string>(key.c_str());
if(value == "")
- Log::Info << "\" \"";
+ Log::Info << "\"\"";
Log::Info << value;
}
else if (data.tname == TYPENAME(int))
@@ -621,7 +623,8 @@
* @param str String to hyphenate (splits are on ' ').
* @param padding Amount of padding on the left for each new line.
*/
-std::string CLI::HyphenateString(std::string str, int padding) {
+std::string CLI::HyphenateString(std::string str, int padding)
+{
size_t margin = 80 - padding;
if (str.length() < margin)
return str;
@@ -633,7 +636,8 @@
size_t splitpos;
// Check that we don't have a newline first.
splitpos = str.find('\n', pos);
- if (splitpos == std::string::npos || splitpos > (pos + margin)) {
+ if (splitpos == std::string::npos || splitpos > (pos + margin))
+ {
// We did not find a newline.
if (str.length() - pos < margin)
{
@@ -667,11 +671,12 @@
for (iter = amap.begin(); iter != amap.end(); iter++)
if (iter->second == value) // Found our match.
return iter->first;
+
return ""; // Nothing found.
}
// Add help parameter.
-PARAM_FLAG("help", "Default help info.", "");
+PARAM_FLAG("help", "Default help info.", "h");
PARAM_STRING("info", "Get help on a specific module or option.", "", "");
PARAM_FLAG("verbose", "Display informational messages and the full list of "
"parameters and timers at the end of execution.", "");
Modified: mlpack/trunk/src/mlpack/core/io/cli.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/io/cli.hpp 2011-12-14 11:42:54 UTC (rev 10766)
+++ mlpack/trunk/src/mlpack/core/io/cli.hpp 2011-12-14 12:11:41 UTC (rev 10767)
@@ -17,11 +17,12 @@
#include <boost/any.hpp>
#include <boost/program_options.hpp>
+#include "timers.hpp"
#include "cli_deleter.hpp" // To make sure we can delete the singleton.
/**
- * Document an executable. Only one instance of this macro should be
- * present in your program! Therefore, use it in the main.cpp
+ * Document an executable. Only one instance of this macro should be
+ * present in your program! Therefore, use it in the main.cpp
* (or corresponding executable) in your program.
*
* @see mlpack::CLI, PARAM_FLAG(), PARAM_INT(), PARAM_DOUBLE(), PARAM_STRING(),
@@ -41,7 +42,7 @@
*
* @param ID Name of the parameter.
* @param DESC Quick description of the parameter (1-2 sentences).
- * @param ALIAS An alias for the parameter
+ * @param ALIAS An alias for the parameter
*
* @see mlpack::CLI, PROGRAM_INFO()
*
@@ -84,7 +85,7 @@
* Define a floating-point parameter. You should use PARAM_DOUBLE instead.
*
* The parameter can then be specified on the command line with
- * --ID=value.
+ * --ID=value.
*
* @param ID Name of the parameter.
* @param DESC Quick description of the parameter (1-2 sentences).
@@ -157,7 +158,7 @@
* Define a vector parameter.
*
* The parameter can then be specified on the command line with
- * --ID=value.
+ * --ID=value.
*
* @param ID Name of the parameter.
* @param DESC Quick description of the parameter (1-2 sentences).
@@ -183,11 +184,11 @@
* Define a required integer parameter.
*
* The parameter must then be specified on the command line with
- * --ID=value.
+ * --ID=value.
*
* @param ID Name of the parameter.
* @param DESC Quick description of the parameter (1-2 sentences).
- * @param ALIAS An alias for the parameter.
+ * @param ALIAS An alias for the parameter.
*
* @see mlpack::CLI, PROGRAM_INFO()
*
@@ -230,7 +231,7 @@
* Define a required double parameter.
*
* The parameter must then be specified on the command line with
- * --ID=value.
+ * --ID=value.
*
* @param ID Name of the parameter.
* @param DESC Quick description of the parameter (1-2 sentences).
@@ -253,7 +254,7 @@
* Define a required string parameter.
*
* The parameter must then be specified on the command line with
- * --ID=value.
+ * --ID=value.
*
* @param ID Name of the parameter.
* @param DESC Quick description of the parameter (1-2 sentences).
@@ -276,7 +277,7 @@
* Define a required vector parameter.
*
* The parameter must then be specified on the command line with
- * --ID=value.
+ * --ID=value.
*
* @param ID Name of the parameter.
* @param DESC Quick description of the parameter (1-2 sentences).
@@ -711,13 +712,19 @@
//! True, if CLI was used to parse command line options.
bool did_parse;
+ //! Holds the timer objects.
+ Timers timer;
+
+ //! So that Timer::Start() and Timer::Stop() can access the timer variable.
+ friend class Timer;
+
public:
//! Pointer to the ProgramDoc object.
io::ProgramDoc *doc;
private:
- /**
+ /**
* Returns an alias, if given the name of the original.
*
* @param value The value in a key:value pair where the key
@@ -725,7 +732,7 @@
* @return The alias associated with value.
*/
static std::string AliasReverseLookup(std::string value);
-
+
/**
* Retrieve the singleton.
*
Modified: mlpack/trunk/src/mlpack/core/io/cli_impl.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/io/cli_impl.hpp 2011-12-14 11:42:54 UTC (rev 10766)
+++ mlpack/trunk/src/mlpack/core/io/cli_impl.hpp 2011-12-14 12:11:41 UTC (rev 10767)
@@ -46,14 +46,14 @@
amap[stringAlias] = path;
prog_opt_id = path + "," + alias;
}
-
+
// Add the option to boost program_options.
desc.add_options()
(prog_opt_id.c_str(), po::value<T>(), description);
// Make sure the appropriate metadata is inserted into gmap.
gmap_t& gmap = GetSingleton().globalValues;
-
+
ParamData data;
T tmp = T();
@@ -61,6 +61,7 @@
data.name = path;
data.tname = TYPENAME(T);
data.value = boost::any(tmp);
+ data.wasPassed = false;
gmap[path] = data;
// If the option is required, add it to the required options list.
@@ -105,10 +106,10 @@
//What if we have meta-data, but no data?
boost::any val = gmap[key].value;
- if(val.empty())
+ if(val.empty())
gmap[key].value = boost::any(tmp);
-
+
return *boost::any_cast<T>(&gmap[key].value);
}
Copied: mlpack/trunk/src/mlpack/core/io/timers.cpp (from rev 10737, mlpack/trunk/src/mlpack/core/utilities/timers.cpp)
===================================================================
--- mlpack/trunk/src/mlpack/core/io/timers.cpp (rev 0)
+++ mlpack/trunk/src/mlpack/core/io/timers.cpp 2011-12-14 12:11:41 UTC (rev 10767)
@@ -0,0 +1,153 @@
+/**
+ * @file timers.cpp
+ * @author Matthew Amidon
+ *
+ * Implementation of timers.
+ */
+#include "timers.hpp"
+#include "../io/cli.hpp"
+#include "../io/log.hpp"
+
+#include <map>
+#include <string>
+
+using namespace mlpack;
+
+/**
+ * Start the given timer.
+ */
+void Timer::Start(const std::string name)
+{
+ CLI::GetSingleton().timer.StartTimer(name);
+}
+
+/**
+ * Stop the given timer.
+ */
+void Timer::Stop(const std::string name)
+{
+ CLI::GetSingleton().timer.StopTimer(name);
+}
+
+/**
+ * Get the given timer.
+ */
+timeval Timer::Get(const std::string name)
+{
+ return CLI::GetSingleton().timer.GetTimer(name);
+}
+
+std::map<std::string, timeval>& Timers::GetAllTimers()
+{
+ return timers;
+}
+
+timeval Timers::GetTimer(const std::string timerName)
+{
+ std::string name(timerName);
+ return timers[name];
+}
+
+void Timers::PrintTimer(const std::string timerName)
+{
+ timeval& t = timers[timerName];
+ Log::Info << t.tv_sec << "." << std::setw(6) << std::setfill('0')
+ << t.tv_usec << "s";
+
+ // Also output convenient day/hr/min/sec.
+ int days = t.tv_sec / 86400; // Integer division rounds down.
+ int hours = (t.tv_sec % 86400) / 3600;
+ int minutes = (t.tv_sec % 3600) / 60;
+ int seconds = (t.tv_sec % 60);
+ // No output if it didn't even take a minute.
+ if (!(days == 0 && hours == 0 && minutes == 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)
+ {
+ Log::Info << days << " days";
+ output = true;
+ }
+
+ if (hours > 0)
+ {
+ if (output)
+ Log::Info << ", ";
+ Log::Info << hours << " hrs";
+ output = true;
+ }
+
+ if (minutes > 0)
+ {
+ if (output)
+ Log::Info << ", ";
+ Log::Info << minutes << " mins";
+ output = true;
+ }
+
+ if (seconds > 0)
+ {
+ if (output)
+ Log::Info << ",";
+ Log::Info << seconds << "." << std::setw(1) << (t.tv_usec / 100000) <<
+ "secs";
+ output = true;
+ }
+
+ Log::Info << ")";
+ }
+
+ Log::Info << std::endl;
+}
+
+void Timers::StartTimer(const std::string timerName)
+{
+ timeval tmp;
+
+ tmp.tv_sec = 0;
+ tmp.tv_usec = 0;
+
+#ifndef _WIN32
+ gettimeofday(&tmp, NULL);
+#else
+ FileTimeToTimeVal(&tmp);
+#endif
+ timers[timerName] = tmp;
+}
+
+void Timers::StopTimer(const std::string timerName)
+{
+ timeval delta, b, a = timers[timerName];
+
+#ifndef _WIN32
+ gettimeofday(&b, NULL);
+#else
+ FileTimeToTimeVal(&b);
+#endif
+ // Calculate the delta time.
+ timersub(&b, &a, &delta);
+ timers[timerName] = delta;
+}
+
+#ifdef _WIN32
+void Timers::FileTimeToTimeVal(timeval* tv)
+{
+ FILETIME ftime;
+ uint64_t ptime = 0;
+ // Acquire the file time.
+ GetSystemTimeAsFileTime(&ftime);
+ // Now convert FILETIME to timeval.
+ ptime |= ftime.dwHighDateTime;
+ ptime = ptime << 32;
+ ptime |= ftime.dwLowDateTime;
+ ptime /= 10;
+ ptime -= DELTA_EPOC_IN_MICROSECONDS;
+
+ tv.tv_sec = (long) (ptime / 1000000UL);
+ tv.tv_usec = (long) (ptime % 1000000UL);
+}
+
+#endif // _WIN32
Copied: mlpack/trunk/src/mlpack/core/io/timers.hpp (from rev 10737, mlpack/trunk/src/mlpack/core/utilities/timers.hpp)
===================================================================
--- mlpack/trunk/src/mlpack/core/io/timers.hpp (rev 0)
+++ mlpack/trunk/src/mlpack/core/io/timers.hpp 2011-12-14 12:11:41 UTC (rev 10767)
@@ -0,0 +1,104 @@
+/**
+ * @file timers.hpp
+ * @author Matthew Amidon
+ *
+ * Timers for MLPACK.
+ */
+#ifndef __MLPACK_CORE_UTILITIES_TIMERS_HPP
+#define __MLPACK_CORE_UTILITIES_TIMERS_HPP
+
+#include <map>
+#include <string>
+
+#ifndef _WIN32
+ #include <sys/time.h> //linux
+#else
+ #include <winsock.h> //timeval on windows
+ #include <windows.h> //GetSystemTimeAsFileTime on windows
+//gettimeofday has no equivalent will need to write extra code for that.
+ #if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
+ #define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
+ #else
+ #define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
+ #endif
+#endif //_WIN32
+
+namespace mlpack {
+
+class Timers
+{
+ public:
+ //! Nothing to do for the constructor.
+ Timers() { }
+
+ /**
+ * Returns a copy of all the timers used via this interface.
+ */
+ std::map<std::string, timeval>& GetAllTimers();
+
+ /**
+ * Returns a copy of the timer specified.
+ *
+ * @param timerName The name of the timer in question.
+ */
+ timeval GetTimer(const std::string timerName);
+
+ /**
+ * Prints the specified timer. If it took longer than a minute to complete
+ * the timer will be displayed in days, hours, and minutes as well.
+ *
+ * @param timerName The name of the timer in question.
+ */
+ void PrintTimer(const std::string timerName);
+
+ /**
+ * Initializes a timer, available like a normal value specified on
+ * the command line. Timers are of type timval
+ *
+ * @param timerName The name of the timer in question.
+ */
+ void StartTimer(const std::string timerName);
+
+ /**
+ * Halts the timer, and replaces it's value with
+ * the delta time from it's start
+ *
+ * @param timerName The name of the timer in question.
+ */
+ void StopTimer(const std::string timerName);
+
+ private:
+ std::map<std::string, timeval> timers;
+
+ void FileTimeToTimeVal(timeval* tv);
+};
+
+// Static access methods.
+class Timer
+{
+ public:
+ /**
+ * Start the given timer.
+ *
+ * @param name Name of timer to be started.
+ */
+ static void Start(const std::string name);
+
+ /**
+ * Stop the given timer.
+ *
+ * @param name Name of timer to be stopped.
+ */
+ static void Stop(const std::string name);
+
+ /**
+ * Get the value of the given timer.
+ *
+ * @param name Name of timer to return value of.
+ */
+ static timeval Get(const std::string name);
+};
+
+}; // namespace mlpack
+
+#endif // __MLPACK_CORE_UTILITIES_TIMERS_HPP
Modified: mlpack/trunk/src/mlpack/core/utilities/CMakeLists.txt
===================================================================
--- mlpack/trunk/src/mlpack/core/utilities/CMakeLists.txt 2011-12-14 11:42:54 UTC (rev 10766)
+++ mlpack/trunk/src/mlpack/core/utilities/CMakeLists.txt 2011-12-14 12:11:41 UTC (rev 10767)
@@ -5,8 +5,6 @@
set(SOURCES
save_restore_utility.cpp
save_restore_utility.hpp
- timers.hpp
- timers.cpp
)
# add directory name to sources
Deleted: mlpack/trunk/src/mlpack/core/utilities/timers.cpp
===================================================================
--- mlpack/trunk/src/mlpack/core/utilities/timers.cpp 2011-12-14 11:42:54 UTC (rev 10766)
+++ mlpack/trunk/src/mlpack/core/utilities/timers.cpp 2011-12-14 12:11:41 UTC (rev 10767)
@@ -1,134 +0,0 @@
-/**
- * @file timers.cpp
- * @author Matthew Amidon
- *
- * Implementation of timers.
- */
-#include "timers.hpp"
-#include "../io/cli.hpp"
-#include "../io/log.hpp"
-
-#include <map>
-#include <string>
-
-using namespace mlpack;
-
-std::map<std::string, timeval> Timers::timers;
-
-std::map<std::string, timeval> Timers::GetAllTimers()
-{
- return timers;
-}
-
-timeval Timers::GetTimer(const char* timerName)
-{
- std::string name(timerName);
- return timers[name];
-}
-
-void Timers::PrintTimer(const char* timerName)
-{
- std::string name=timerName;
- timeval& t = timers[name];
- Log::Info << t.tv_sec << "." << std::setw(6) << std::setfill('0')
- << t.tv_usec << "s";
-
- // Also output convenient day/hr/min/sec.
- int days = t.tv_sec / 86400; // Integer division rounds down.
- int hours = (t.tv_sec % 86400) / 3600;
- int minutes = (t.tv_sec % 3600) / 60;
- int seconds = (t.tv_sec % 60);
- // No output if it didn't even take a minute.
- if (!(days == 0 && hours == 0 && minutes == 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)
- {
- Log::Info << days << " days";
- output = true;
- }
-
- if (hours > 0)
- {
- if (output)
- Log::Info << ", ";
- Log::Info << hours << " hrs";
- output = true;
- }
-
- if (minutes > 0)
- {
- if (output)
- Log::Info << ", ";
- Log::Info << minutes << " mins";
- output = true;
- }
-
- if (seconds > 0)
- {
- if (output)
- Log::Info << ",";
- Log::Info << seconds << "." << std::setw(1) << (t.tv_usec / 100000) <<
- "secs";
- output = true;
- }
-
- Log::Info << ")";
- }
-
- Log::Info << std::endl;
-}
-
-void Timers::StartTimer(const char* timerName)
-{
- // Convert the name to std::string.
- std::string name(timerName);
- timeval tmp;
-
- tmp.tv_sec = 0;
- tmp.tv_usec = 0;
-
-#ifndef _WIN32
- gettimeofday(&tmp, NULL);
-#else
- FileTimeToTimeVal(&tmp);
-#endif
- timers[name] = tmp;
-}
-
-void Timers::StopTimer(const char* timerName)
-{
- std::string name(timerName);
- timeval delta, b, a = timers[name];
-
-#ifndef _WIN32
- gettimeofday(&b, NULL);
-#else
- FileTimeToTimeVal(&b);
-#endif
- // Calculate the delta time.
- timersub(&b, &a, &delta);
- timers[name] = delta;
-}
-
-#ifdef _WIN32
-void Timers::FileTimeToTimeVal(timeval* tv)
-{
- FILETIME ftime;
- uint64_t ptime = 0;
- // Acquire the file time.
- GetSystemTimeAsFileTime(&ftime);
- // Now convert FILETIME to timeval.
- ptime |= ftime.dwHighDateTime;
- ptime = ptime << 32;
- ptime |= ftime.dwLowDateTime;
- ptime /= 10;
- ptime -= DELTA_EPOC_IN_MICROSECONDS;
-
- tv.tv_sec = (long) (ptime / 1000000UL);
- tv.tv_usec = (long) (ptime % 1000000UL);
-}
-#endif // _WIN32
Deleted: mlpack/trunk/src/mlpack/core/utilities/timers.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/utilities/timers.hpp 2011-12-14 11:42:54 UTC (rev 10766)
+++ mlpack/trunk/src/mlpack/core/utilities/timers.hpp 2011-12-14 12:11:41 UTC (rev 10767)
@@ -1,79 +0,0 @@
-/**
- * @file timers.hpp
- * @author Matthew Amidon
- *
- * Timers for MLPACK.
- */
-#ifndef __MLPACK_CORE_UTILITIES_TIMERS_HPP
-#define __MLPACK_CORE_UTILITIES_TIMERS_HPP
-
-#include <map>
-#include <string>
-
-#ifndef _WIN32
- #include <sys/time.h> //linux
-#else
- #include <winsock.h> //timeval on windows
- #include <windows.h> //GetSystemTimeAsFileTime on windows
-//gettimeofday has no equivalent will need to write extra code for that.
- #if defined(_MSC_VER) || defined(_MSC_EXTENSCLINS)
- #define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
- #else
- #define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
- #endif
-#endif //_WIN32
-
-namespace mlpack {
-
-class Timers
-{
- public:
- /**
- * Returns a copy of all the timers used via this interface.
- */
- static std::map<std::string, timeval> GetAllTimers();
-
- /**
- * Returns a copy of the timer specified.
- *
- * @param timerName The name of the timer in question.
- */
- static timeval GetTimer(const char* timerName);
-
- /**
- * Prints the specified timer. If it took longer than a minute to complete
- * the timer will be displayed in days, hours, and minutes as well.
- *
- * @param timerName The name of the timer in question.
- */
- static void PrintTimer(const char* timerName);
-
- /**
- * Initializes a timer, available like a normal value specified on
- * the command line. Timers are of type timval
- *
- * @param timerName The name of the timer in question.
- */
- static void StartTimer(const char* timerName);
-
- /**
- * Halts the timer, and replaces it's value with
- * the delta time from it's start
- *
- * @param timerName The name of the timer in question.
- */
- static void StopTimer(const char* timerName);
-
- private:
- static std::map<std::string, timeval> timers;
-
- void FileTimeToTimeVal(timeval* tv);
-
- // Don't want any instances floating around.
- Timers();
- ~Timers();
-};
-
-}; // namespace mlpack
-
-#endif // __MLPACK_CORE_UTILITIES_TIMERS_HPP
Modified: mlpack/trunk/src/mlpack/core.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core.hpp 2011-12-14 11:42:54 UTC (rev 10766)
+++ mlpack/trunk/src/mlpack/core.hpp 2011-12-14 12:11:41 UTC (rev 10767)
@@ -95,6 +95,5 @@
#include <mlpack/core/math/math_misc.hpp>
#include <mlpack/core/math/range.hpp>
#include <mlpack/core/utilities/save_restore_utility.hpp>
-#include <mlpack/core/utilities/timers.hpp>
#endif
Modified: mlpack/trunk/src/mlpack/methods/emst/dtb_impl.hpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/emst/dtb_impl.hpp 2011-12-14 11:42:54 UTC (rev 10766)
+++ mlpack/trunk/src/mlpack/methods/emst/dtb_impl.hpp 2011-12-14 12:11:41 UTC (rev 10767)
@@ -69,7 +69,7 @@
connections(data.n_cols),
totalDist(0.0)
{
- Timers::StartTimer("emst/treebuilding");
+ Timer::Start("emst/treebuilding");
if (!naive)
{
@@ -83,7 +83,7 @@
tree = new TreeType(data, oldFromNew, data.n_cols);
}
- Timers::StopTimer("emst/treebuilding");
+ Timer::Stop("emst/treebuilding");
edges.reserve(data.n_cols - 1); // Set size.
@@ -126,7 +126,7 @@
template<typename TreeType>
void DualTreeBoruvka<TreeType>::ComputeMST(arma::mat& results)
{
- Timers::StartTimer("emst/mst_computation");
+ Timer::Start("emst/mst_computation");
while (edges.size() < (data.n_cols - 1))
{
@@ -147,7 +147,7 @@
Log::Info << edges.size() << " edges found so far.\n";
}
- Timers::StopTimer("emst/mst_computation");
+ Timer::Stop("emst/mst_computation");
EmitResults(results);
Modified: mlpack/trunk/src/mlpack/methods/gmm/gmm_main.cpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/gmm/gmm_main.cpp 2011-12-14 11:42:54 UTC (rev 10766)
+++ mlpack/trunk/src/mlpack/methods/gmm/gmm_main.cpp 2011-12-14 12:11:41 UTC (rev 10767)
@@ -28,9 +28,9 @@
GMM gmm(CLI::GetParam<int>("gaussians"), data_points.n_rows);
////// Computing the parameters of the model using the EM algorithm //////
- Timers::StartTimer("em");
+ Timer::Start("em");
gmm.Estimate(data_points);
- Timers::StopTimer("em");
+ Timer::Stop("em");
////// OUTPUT RESULTS //////
// We need a better solution for this. So, currently, we do nothing.
Modified: mlpack/trunk/src/mlpack/methods/naive_bayes/nbc_main.cpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/naive_bayes/nbc_main.cpp 2011-12-14 11:42:54 UTC (rev 10766)
+++ mlpack/trunk/src/mlpack/methods/naive_bayes/nbc_main.cpp 2011-12-14 12:11:41 UTC (rev 10767)
@@ -58,15 +58,15 @@
size_t number_of_classes_ = CLI::GetParam<size_t>("classes");
// Create and train the classifier.
- Timers::StartTimer("training");
+ Timer::Start("training");
NaiveBayesClassifier<> nbc(training_data, number_of_classes_);
- Timers::StopTimer("training");
+ Timer::Stop("training");
// Timing the running of the Naive Bayes Classifier.
arma::Col<size_t> results;
- Timers::StartTimer("testing");
+ Timer::Start("testing");
nbc.Classify(testing_data, results);
- Timers::StopTimer("testing");
+ Timer::Stop("testing");
// Output results.
std::string output_filename = CLI::GetParam<std::string>("output");
Modified: mlpack/trunk/src/mlpack/methods/neighbor_search/allkfn_main.cpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/neighbor_search/allkfn_main.cpp 2011-12-14 11:42:54 UTC (rev 10766)
+++ mlpack/trunk/src/mlpack/methods/neighbor_search/allkfn_main.cpp 2011-12-14 12:11:41 UTC (rev 10767)
@@ -108,12 +108,12 @@
// Build trees by hand, so we can save memory: if we pass a tree to
// NeighborSearch, it does not copy the matrix.
Log::Info << "Building reference tree..." << endl;
- Timers::StartTimer("tree_building");
+ Timer::Start("tree_building");
BinarySpaceTree<bound::HRectBound<2>, QueryStat<FurthestNeighborSort> >
refTree(referenceData, oldFromNewRefs);
- Timers::StopTimer("tree_building");
+ Timer::Stop("tree_building");
std::vector<size_t> oldFromNewQueries;
@@ -131,12 +131,12 @@
// Build trees by hand, so we can save memory: if we pass a tree to
// NeighborSearch, it does not copy the matrix.
- Timers::StartTimer("tree_building");
+ Timer::Start("tree_building");
BinarySpaceTree<bound::HRectBound<2>, QueryStat<FurthestNeighborSort> >
queryTree(queryData, oldFromNewRefs);
- Timers::StopTimer("tree_building");
+ Timer::Stop("tree_building");
allkfn = new AllkFN(referenceData, queryData, naive, singleMode, 20,
&refTree, &queryTree);
Modified: mlpack/trunk/src/mlpack/methods/neighbor_search/allknn_main.cpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/neighbor_search/allknn_main.cpp 2011-12-14 11:42:54 UTC (rev 10766)
+++ mlpack/trunk/src/mlpack/methods/neighbor_search/allknn_main.cpp 2011-12-14 12:11:41 UTC (rev 10767)
@@ -110,12 +110,12 @@
// Build trees by hand, so we can save memory: if we pass a tree to
// NeighborSearch, it does not copy the matrix.
Log::Info << "Building reference tree..." << endl;
- Timers::StartTimer("tree_building");
+ Timer::Start("tree_building");
BinarySpaceTree<bound::HRectBound<2>, QueryStat<NearestNeighborSort> >
refTree(referenceData, oldFromNewRefs, leafSize);
- Timers::StopTimer("tree_building");
+ Timer::Stop("tree_building");
std::vector<size_t> oldFromNewQueries;
@@ -133,12 +133,12 @@
// Build trees by hand, so we can save memory: if we pass a tree to
// NeighborSearch, it does not copy the matrix.
- Timers::StartTimer("tree_building");
+ Timer::Start("tree_building");
BinarySpaceTree<bound::HRectBound<2>, QueryStat<NearestNeighborSort> >
queryTree(queryData, oldFromNewRefs, leafSize);
- Timers::StopTimer("tree_building");
+ Timer::Stop("tree_building");
allknn = new AllkNN(referenceData, queryData, naive, singleMode, 20,
&refTree, &queryTree);
Modified: mlpack/trunk/src/mlpack/methods/neighbor_search/neighbor_search_impl.hpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/neighbor_search/neighbor_search_impl.hpp 2011-12-14 11:42:54 UTC (rev 10766)
+++ mlpack/trunk/src/mlpack/methods/neighbor_search/neighbor_search_impl.hpp 2011-12-14 12:11:41 UTC (rev 10767)
@@ -41,7 +41,7 @@
// We'll time tree building, but only if we are building trees.
if (!referenceTree || !queryTree)
- Timers::StartTimer("tree_building");
+ Timer::Start("tree_building");
if (!referenceTree)
{
@@ -66,7 +66,7 @@
// Stop the timer we started above (if we need to).
if (!referenceTree || !queryTree)
- Timers::StopTimer("tree_building");
+ Timer::Stop("tree_building");
}
// Construct the object.
@@ -93,7 +93,7 @@
// We'll time tree building, but only if we are building trees.
if (!referenceTree)
{
- Timers::StartTimer("tree_building");
+ Timer::Start("tree_building");
// Construct as a naive object if we need to.
if (naive)
@@ -104,7 +104,7 @@
leafSize);
// Stop the timer we started above.
- Timers::StopTimer("tree_building");
+ Timer::Stop("tree_building");
}
}
@@ -131,7 +131,7 @@
arma::Mat<size_t>& resultingNeighbors,
arma::mat& distances)
{
- Timers::StartTimer("computing_neighbors");
+ Timer::Start("computing_neighbors");
// If we have built the trees ourselves, then we will have to map all the
// indices back to their original indices when this computation is finished.
@@ -203,7 +203,7 @@
}
}
- Timers::StopTimer("computing_neighbors");
+ Timer::Stop("computing_neighbors");
// Now, do we need to do mapping of indices?
if (!ownReferenceTree && !ownQueryTree)
Modified: mlpack/trunk/src/mlpack/methods/range_search/range_search_impl.hpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/range_search/range_search_impl.hpp 2011-12-14 11:42:54 UTC (rev 10766)
+++ mlpack/trunk/src/mlpack/methods/range_search/range_search_impl.hpp 2011-12-14 12:11:41 UTC (rev 10767)
@@ -33,7 +33,7 @@
numberOfPrunes(0)
{
// Build the trees.
- Timers::StartTimer("range_search/tree_building");
+ Timer::Start("range_search/tree_building");
// Naive sets the leaf size such that the entire tree is one node.
referenceTree = new TreeType(referenceCopy, oldFromNewReferences,
@@ -42,7 +42,7 @@
queryTree = new TreeType(queryCopy, oldFromNewQueries,
(naive ? queryCopy.n_cols : leafSize));
- Timers::StopTimer("range_search/tree_building");
+ Timer::Stop("range_search/tree_building");
}
template<typename MetricType, typename TreeType>
@@ -64,13 +64,13 @@
numberOfPrunes(0)
{
// Build the trees.
- Timers::StartTimer("range_search/tree_building");
+ Timer::Start("range_search/tree_building");
// Naive sets the leaf size such that the entire tree is one node.
referenceTree = new TreeType(referenceCopy, oldFromNewReferences,
(naive ? referenceCopy.n_cols : leafSize));
- Timers::StopTimer("range_search/tree_building");
+ Timer::Stop("range_search/tree_building");
}
template<typename MetricType, typename TreeType>
@@ -130,7 +130,7 @@
std::vector<std::vector<size_t> >& neighbors,
std::vector<std::vector<double> >& distances)
{
- Timers::StartTimer("range_search/computing_neighbors");
+ Timer::Start("range_search/computing_neighbors");
// Set size of prunes to 0.
numberOfPrunes = 0;
@@ -182,7 +182,7 @@
*distancePtr);
}
- Timers::StopTimer("range_search/computing_neighbors");
+ Timer::Stop("range_search/computing_neighbors");
// Output number of prunes.
Log::Info << "Number of pruned nodes during computation: " << numberOfPrunes
More information about the mlpack-svn
mailing list