[mlpack-svn] r11098 - in mlpack/trunk/src/mlpack: core/util methods/gmm methods/mvu methods/pca tests
fastlab-svn at coffeetalk-1.cc.gatech.edu
fastlab-svn at coffeetalk-1.cc.gatech.edu
Fri Jan 13 16:24:57 EST 2012
Author: jcline3
Date: 2012-01-13 16:24:57 -0500 (Fri, 13 Jan 2012)
New Revision: 11098
Modified:
mlpack/trunk/src/mlpack/core/util/cli.cpp
mlpack/trunk/src/mlpack/core/util/option.cpp
mlpack/trunk/src/mlpack/core/util/option.hpp
mlpack/trunk/src/mlpack/core/util/save_restore_utility.cpp
mlpack/trunk/src/mlpack/core/util/save_restore_utility.hpp
mlpack/trunk/src/mlpack/core/util/save_restore_utility_impl.hpp
mlpack/trunk/src/mlpack/core/util/timers.cpp
mlpack/trunk/src/mlpack/core/util/timers.hpp
mlpack/trunk/src/mlpack/methods/gmm/gmm.hpp
mlpack/trunk/src/mlpack/methods/mvu/mvu_objective_function.cpp
mlpack/trunk/src/mlpack/methods/pca/pca_main.cpp
mlpack/trunk/src/mlpack/tests/cli_test.cpp
mlpack/trunk/src/mlpack/tests/save_restore_utility_test.cpp
Log:
Fix all the things cppcheck didn't like.
* not initializing a value in a constructor
* ++iterator instead of iterator++
* container.empty() instead of container.size() == 0
* remove unused variables
* minimize scope of variables
There might've been something else but I've forgotten.
Modified: mlpack/trunk/src/mlpack/core/util/cli.cpp
===================================================================
--- mlpack/trunk/src/mlpack/core/util/cli.cpp 2012-01-13 16:34:01 UTC (rev 11097)
+++ mlpack/trunk/src/mlpack/core/util/cli.cpp 2012-01-13 21:24:57 UTC (rev 11098)
@@ -116,7 +116,6 @@
{
po::options_description& desc = CLI::GetSingleton().desc;
- std::string tmp = TYPENAME(bool);
std::string path = identifier;
std::string stringAlias = alias;
// Must make use of boost option name syntax.
@@ -190,7 +189,7 @@
{
amap_t& amap = GetSingleton().aliasValues;
amap_t::iterator iter;
- for (iter = amap.begin(); iter != amap.end(); iter++)
+ for (iter = amap.begin(); iter != amap.end(); ++iter)
if (iter->second == value) // Found our match.
return iter->first;
@@ -432,7 +431,7 @@
gmap_t::iterator iter;
// Print out all the values.
- for (iter = gmap.begin(); iter != gmap.end(); iter++)
+ for (iter = gmap.begin(); iter != gmap.end(); ++iter)
{
std::string key = iter->first;
@@ -548,7 +547,7 @@
std::cout << "Options: " << std::endl << std::endl;
// Print out the descriptions of everything else.
- for (iter = gmap.begin(); iter != gmap.end(); iter++)
+ for (iter = gmap.begin(); iter != gmap.end(); ++iter)
{
std::string key = iter->first;
ParamData data = iter->second;
@@ -642,7 +641,7 @@
// Now, warn the user if they missed any required options.
std::list<std::string>::iterator iter;
- for (iter = rOpt.begin(); iter != rOpt.end(); iter++)
+ for (iter = rOpt.begin(); iter != rOpt.end(); ++iter)
{
std::string str = *iter;
if (!vmap.count(str))
@@ -664,7 +663,7 @@
// Iterate through vmap, and overwrite default values with anything found on
// command line.
po::variables_map::iterator i;
- for (i = vmap.begin(); i != vmap.end(); i++)
+ for (i = vmap.begin(); i != vmap.end(); ++i)
{
ParamData param;
if (gmap.count(i->first)) // We need to preserve certain data
Modified: mlpack/trunk/src/mlpack/core/util/option.cpp
===================================================================
--- mlpack/trunk/src/mlpack/core/util/option.cpp 2012-01-13 16:34:01 UTC (rev 11097)
+++ mlpack/trunk/src/mlpack/core/util/option.cpp 2012-01-13 21:24:57 UTC (rev 11098)
@@ -24,8 +24,8 @@
* taken care of by CLI later.
* @param defaultModule Name of the default module.
*/
-ProgramDoc::ProgramDoc(const std::string programName,
- const std::string documentation) :
+ProgramDoc::ProgramDoc(const std::string& programName,
+ const std::string& documentation) :
programName(programName),
documentation(documentation)
{
Modified: mlpack/trunk/src/mlpack/core/util/option.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/util/option.hpp 2012-01-13 16:34:01 UTC (rev 11097)
+++ mlpack/trunk/src/mlpack/core/util/option.hpp 2012-01-13 21:24:57 UTC (rev 11098)
@@ -84,8 +84,8 @@
* program and what it is. No newline characters are necessary; this is
* taken care of by CLI later.
*/
- ProgramDoc(const std::string programName,
- const std::string documentation);
+ ProgramDoc(const std::string& programName,
+ const std::string& documentation);
//! The name of the program.
std::string programName;
Modified: mlpack/trunk/src/mlpack/core/util/save_restore_utility.cpp
===================================================================
--- mlpack/trunk/src/mlpack/core/util/save_restore_utility.cpp 2012-01-13 16:34:01 UTC (rev 11097)
+++ mlpack/trunk/src/mlpack/core/util/save_restore_utility.cpp 2012-01-13 21:24:57 UTC (rev 11098)
@@ -10,7 +10,7 @@
using namespace mlpack;
using namespace utilities;
-bool SaveRestoreUtility::ReadFile(const std::string filename)
+bool SaveRestoreUtility::ReadFile(const std::string& filename)
{
xmlDocPtr xmlDocTree = NULL;
if (NULL == (xmlDocTree = xmlReadFile(filename.c_str(), NULL, 0)))
@@ -41,12 +41,11 @@
}
}
-bool SaveRestoreUtility::WriteFile(const std::string filename)
+bool SaveRestoreUtility::WriteFile(const std::string& filename)
{
bool success = false;
xmlDocPtr xmlDocTree = xmlNewDoc(BAD_CAST "1.0");
xmlNodePtr root = xmlNewNode(NULL, BAD_CAST "root");
- xmlNodePtr child = NULL;
xmlDocSetRootElement(xmlDocTree, root);
@@ -54,7 +53,7 @@
it != parameters.end();
++it)
{
- child = xmlNewChild(root, NULL,
+ xmlNodePtr child = xmlNewChild(root, NULL,
BAD_CAST(*it).first.c_str(),
BAD_CAST(*it).second.c_str());
/* TODO: perhaps we'll add more later?
@@ -67,7 +66,7 @@
}
arma::mat& SaveRestoreUtility::LoadParameter(arma::mat& matrix,
- const std::string name)
+ const std::string& name)
{
std::map<std::string, std::string>::iterator it = parameters.find(name);
if (it != parameters.end())
@@ -126,7 +125,7 @@
}
std::string SaveRestoreUtility::LoadParameter(std::string& str,
- const std::string name)
+ const std::string& name)
{
std::map<std::string, std::string>::iterator it = parameters.find(name);
if (it != parameters.end())
@@ -140,12 +139,12 @@
return "";
}
-char SaveRestoreUtility::LoadParameter(char c, const std::string name)
+char SaveRestoreUtility::LoadParameter(char c, const std::string& name)
{
- int temp;
std::map<std::string, std::string>::iterator it = parameters.find(name);
if (it != parameters.end())
{
+ int temp;
std::string value = (*it).second;
std::istringstream input (value);
input >> temp;
@@ -158,7 +157,7 @@
return 0;
}
-void SaveRestoreUtility::SaveParameter(const char c, const std::string name)
+void SaveRestoreUtility::SaveParameter(const char c, const std::string& name)
{
int temp = (int) c;
std::ostringstream output;
@@ -167,7 +166,7 @@
}
void SaveRestoreUtility::SaveParameter(const arma::mat& mat,
- const std::string name)
+ const std::string& name)
{
std::ostringstream output;
size_t columns = mat.n_cols;
@@ -190,14 +189,14 @@
template<>
arma::vec& SaveRestoreUtility::LoadParameter(arma::vec& t,
- const std::string name)
+ const std::string& name)
{
return (arma::vec&) LoadParameter((arma::mat&) t, name);
}
template<>
void SaveRestoreUtility::SaveParameter(const arma::vec& t,
- const std::string name)
+ const std::string& name)
{
SaveParameter((const arma::mat&) t, name);
}
Modified: mlpack/trunk/src/mlpack/core/util/save_restore_utility.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/util/save_restore_utility.hpp 2012-01-13 16:34:01 UTC (rev 11097)
+++ mlpack/trunk/src/mlpack/core/util/save_restore_utility.hpp 2012-01-13 21:24:57 UTC (rev 11098)
@@ -44,45 +44,45 @@
/**
* ReadFile reads an XML tree from a file.
*/
- bool ReadFile(const std::string filename);
+ bool ReadFile(const std::string& filename);
/**
* WriteFile writes the XML tree to a file.
*/
- bool WriteFile(const std::string filename);
+ bool WriteFile(const std::string& filename);
/**
* LoadParameter loads a parameter from the parameters map.
*/
template<typename T>
- T& LoadParameter(T& t, const std::string name);
+ T& LoadParameter(T& t, const std::string& name);
/**
* LoadParameter loads a parameter from the parameters map.
*/
template<typename T>
- std::vector<T>& LoadParameter(std::vector<T>& v, const std::string name);
+ std::vector<T>& LoadParameter(std::vector<T>& v, const std::string& name);
/**
* LoadParameter loads a character from the parameters map.
*/
- char LoadParameter(char c, const std::string name);
+ char LoadParameter(char c, const std::string& name);
/**
* LoadParameter loads a string from the parameters map.
*/
- std::string LoadParameter(std::string& str, const std::string name);
+ std::string LoadParameter(std::string& str, const std::string& name);
/**
* LoadParameter loads an arma::mat from the parameters map.
*/
- arma::mat& LoadParameter(arma::mat& matrix, const std::string name);
+ arma::mat& LoadParameter(arma::mat& matrix, const std::string& name);
/**
* SaveParameter saves a parameter to the parameters map.
*/
template<typename T>
- void SaveParameter(const T& t, const std::string name);
+ void SaveParameter(const T& t, const std::string& name);
@@ -90,28 +90,28 @@
* SaveParameter saves a parameter to the parameters map.
*/
template<typename T>
- void SaveParameter(const std::vector<T>& v, const std::string name);
+ void SaveParameter(const std::vector<T>& v, const std::string& name);
/**
* SaveParameter saves a character to the parameters map.
*/
- void SaveParameter(const char c, const std::string name);
+ void SaveParameter(const char c, const std::string& name);
/**
* SaveParameter saves an arma::mat to the parameters map.
*/
- void SaveParameter(const arma::mat& mat, const std::string name);
+ void SaveParameter(const arma::mat& mat, const std::string& name);
};
//! Specialization for arma::vec.
template<>
arma::vec& SaveRestoreUtility::LoadParameter(arma::vec& t,
- const std::string name);
+ const std::string& name);
//! Specialization for arma::vec.
template<>
void SaveRestoreUtility::SaveParameter(const arma::vec& t,
- const std::string name);
+ const std::string& name);
} /* namespace utilities */
} /* namespace mlpack */
Modified: mlpack/trunk/src/mlpack/core/util/save_restore_utility_impl.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/util/save_restore_utility_impl.hpp 2012-01-13 16:34:01 UTC (rev 11097)
+++ mlpack/trunk/src/mlpack/core/util/save_restore_utility_impl.hpp 2012-01-13 21:24:57 UTC (rev 11098)
@@ -15,7 +15,7 @@
namespace utilities {
template<typename T>
-T& SaveRestoreUtility::LoadParameter(T& t, const std::string name)
+T& SaveRestoreUtility::LoadParameter(T& t, const std::string& name)
{
std::map<std::string, std::string>::iterator it = parameters.find(name);
if (it != parameters.end())
@@ -34,7 +34,7 @@
template<typename T>
std::vector<T>& SaveRestoreUtility::LoadParameter(std::vector<T>& v,
- const std::string name)
+ const std::string& name)
{
std::map<std::string, std::string>::iterator it = parameters.find(name);
if (it != parameters.end())
@@ -63,7 +63,7 @@
}
template<typename T>
-void SaveRestoreUtility::SaveParameter(const T& t, const std::string name)
+void SaveRestoreUtility::SaveParameter(const T& t, const std::string& name)
{
std::ostringstream output;
output << t;
@@ -72,7 +72,7 @@
template<typename T>
void SaveRestoreUtility::SaveParameter(const std::vector<T>& t,
- const std::string name)
+ const std::string& name)
{
std::ostringstream output;
for (size_t index = 0; index < t.size(); ++index)
Modified: mlpack/trunk/src/mlpack/core/util/timers.cpp
===================================================================
--- mlpack/trunk/src/mlpack/core/util/timers.cpp 2012-01-13 16:34:01 UTC (rev 11097)
+++ mlpack/trunk/src/mlpack/core/util/timers.cpp 2012-01-13 21:24:57 UTC (rev 11098)
@@ -16,7 +16,7 @@
/**
* Start the given timer.
*/
-void Timer::Start(const std::string name)
+void Timer::Start(const std::string& name)
{
CLI::GetSingleton().timer.StartTimer(name);
}
@@ -24,7 +24,7 @@
/**
* Stop the given timer.
*/
-void Timer::Stop(const std::string name)
+void Timer::Stop(const std::string& name)
{
CLI::GetSingleton().timer.StopTimer(name);
}
@@ -32,7 +32,7 @@
/**
* Get the given timer.
*/
-timeval Timer::Get(const std::string name)
+timeval Timer::Get(const std::string& name)
{
return CLI::GetSingleton().timer.GetTimer(name);
}
@@ -42,13 +42,13 @@
return timers;
}
-timeval Timers::GetTimer(const std::string timerName)
+timeval Timers::GetTimer(const std::string& timerName)
{
std::string name(timerName);
return timers[name];
}
-void Timers::PrintTimer(const std::string timerName)
+void Timers::PrintTimer(const std::string& timerName)
{
timeval& t = timers[timerName];
Log::Info << t.tv_sec << "." << std::setw(6) << std::setfill('0')
@@ -103,7 +103,7 @@
Log::Info << std::endl;
}
-void Timers::StartTimer(const std::string timerName)
+void Timers::StartTimer(const std::string& timerName)
{
timeval tmp;
@@ -118,7 +118,7 @@
timers[timerName] = tmp;
}
-void Timers::StopTimer(const std::string timerName)
+void Timers::StopTimer(const std::string& timerName)
{
timeval delta, b, a = timers[timerName];
Modified: mlpack/trunk/src/mlpack/core/util/timers.hpp
===================================================================
--- mlpack/trunk/src/mlpack/core/util/timers.hpp 2012-01-13 16:34:01 UTC (rev 11097)
+++ mlpack/trunk/src/mlpack/core/util/timers.hpp 2012-01-13 21:24:57 UTC (rev 11098)
@@ -38,21 +38,21 @@
*
* @param name Name of timer to be started.
*/
- static void Start(const std::string name);
+ 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);
+ 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);
+ static timeval Get(const std::string& name);
};
class Timers
@@ -71,7 +71,7 @@
*
* @param timerName The name of the timer in question.
*/
- timeval GetTimer(const std::string timerName);
+ timeval GetTimer(const std::string& timerName);
/**
* Prints the specified timer. If it took longer than a minute to complete
@@ -79,7 +79,7 @@
*
* @param timerName The name of the timer in question.
*/
- void PrintTimer(const std::string timerName);
+ void PrintTimer(const std::string& timerName);
/**
* Initializes a timer, available like a normal value specified on
@@ -87,7 +87,7 @@
*
* @param timerName The name of the timer in question.
*/
- void StartTimer(const std::string timerName);
+ void StartTimer(const std::string& timerName);
/**
* Halts the timer, and replaces it's value with
@@ -95,7 +95,7 @@
*
* @param timerName The name of the timer in question.
*/
- void StopTimer(const std::string timerName);
+ void StopTimer(const std::string& timerName);
private:
std::map<std::string, timeval> timers;
Modified: mlpack/trunk/src/mlpack/methods/gmm/gmm.hpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/gmm/gmm.hpp 2012-01-13 16:34:01 UTC (rev 11097)
+++ mlpack/trunk/src/mlpack/methods/gmm/gmm.hpp 2012-01-13 21:24:57 UTC (rev 11098)
@@ -91,7 +91,7 @@
const std::vector<arma::mat>& covariances,
const arma::vec& weights) :
gaussians(means.size()),
- dimensionality((means.size() > 0) ? means[0].n_elem : 0),
+ dimensionality((!means.empty()) ? means[0].n_elem : 0),
means(means),
covariances(covariances),
weights(weights) { /* nothing to do */ }
Modified: mlpack/trunk/src/mlpack/methods/mvu/mvu_objective_function.cpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/mvu/mvu_objective_function.cpp 2012-01-13 16:34:01 UTC (rev 11097)
+++ mlpack/trunk/src/mlpack/methods/mvu/mvu_objective_function.cpp 2012-01-13 21:24:57 UTC (rev 11098)
@@ -73,7 +73,7 @@
}
// Return 0 for any constraints which are out of bounds.
- if (index >= NumConstraints() || index < 0)
+ if (index >= NumConstraints())
return 0;
// Any other constraints are the individual nearest neighbor constraints:
@@ -99,7 +99,7 @@
gradient.zeros(coordinates.n_rows, coordinates.n_cols);
// Return 0 for any constraints which are out of bounds.
- if (index >= NumConstraints() || index < 0)
+ if (index >= NumConstraints())
return;
if (index == 0)
Modified: mlpack/trunk/src/mlpack/methods/pca/pca_main.cpp
===================================================================
--- mlpack/trunk/src/mlpack/methods/pca/pca_main.cpp 2012-01-13 16:34:01 UTC (rev 11097)
+++ mlpack/trunk/src/mlpack/methods/pca/pca_main.cpp 2012-01-13 21:24:57 UTC (rev 11098)
@@ -41,7 +41,7 @@
{
// Validate the parameter.
newDimension = (size_t) CLI::GetParam<int>("new_dimensionality");
- if (newDimension < 1);
+ if (newDimension < 1)
{
Log::Fatal << "Invalid value for new dimensionality (" << newDimension
<< ")! Must be greater than or equal to 1." << std::endl;
Modified: mlpack/trunk/src/mlpack/tests/cli_test.cpp
===================================================================
--- mlpack/trunk/src/mlpack/tests/cli_test.cpp 2012-01-13 16:34:01 UTC (rev 11097)
+++ mlpack/trunk/src/mlpack/tests/cli_test.cpp 2012-01-13 21:24:57 UTC (rev 11098)
@@ -91,8 +91,6 @@
// this.
PARAM(int, "test_parent/test", "test desc", "", DEFAULT_INT, false);
- std::string desc = std::string("test desc");
-
BOOST_REQUIRE_EQUAL(CLI::GetDescription("test_parent/test"), "test desc");
BOOST_REQUIRE_EQUAL(CLI::GetParam<int>("test_parent/test"), DEFAULT_INT);
}
Modified: mlpack/trunk/src/mlpack/tests/save_restore_utility_test.cpp
===================================================================
--- mlpack/trunk/src/mlpack/tests/save_restore_utility_test.cpp 2012-01-13 16:34:01 UTC (rev 11097)
+++ mlpack/trunk/src/mlpack/tests/save_restore_utility_test.cpp 2012-01-13 21:24:57 UTC (rev 11098)
@@ -27,6 +27,7 @@
SaveRestoreTest()
{
saveRestore = SaveRestoreUtility();
+ anInt = 0;
}
bool SaveModel(std::string filename)
More information about the mlpack-svn
mailing list