[mlpack-git] master: Fix test issues and handling of duplicate vector options. (259deeb)
gitdub at mlpack.org
gitdub at mlpack.org
Tue Nov 1 17:46:33 EDT 2016
Repository : https://github.com/mlpack/mlpack
On branch : master
Link : https://github.com/mlpack/mlpack/compare/981ffa2d67d8fe38df6c699589005835fef710ea...04551164d9950dbdb3738f0c9d87e2d498fd8192
>---------------------------------------------------------------
commit 259deeb6d7bee475b9d0419929528311834717b9
Author: Ryan Curtin <ryan at ratml.org>
Date: Tue Nov 1 17:46:33 2016 -0400
Fix test issues and handling of duplicate vector options.
>---------------------------------------------------------------
259deeb6d7bee475b9d0419929528311834717b9
src/mlpack/core/util/cli.cpp | 7 +++++--
src/mlpack/core/util/cli.hpp | 4 ++--
src/mlpack/core/util/cli_impl.hpp | 3 +--
src/mlpack/tests/cli_test.cpp | 12 ++++++++----
4 files changed, 16 insertions(+), 10 deletions(-)
diff --git a/src/mlpack/core/util/cli.cpp b/src/mlpack/core/util/cli.cpp
index d51d75f..63aa1b1 100644
--- a/src/mlpack/core/util/cli.cpp
+++ b/src/mlpack/core/util/cli.cpp
@@ -331,12 +331,15 @@ void CLI::ParseCommandLine(int argc, char** line)
po::parse_command_line(argc, line, desc));
// Iterate over all the program_options, looking for duplicate parameters.
- // If we find any, remove the duplicates.
+ // If we find any, remove the duplicates. Note that vector options can have
+ // duplicates so we check for those with max_tokens().
for (unsigned int i = 0; i < bpo.options.size(); i++)
{
for (unsigned int j = i + 1; j < bpo.options.size(); j++)
{
- if (bpo.options[i].string_key == bpo.options[j].string_key)
+ if ((bpo.options[i].string_key == bpo.options[j].string_key) &&
+ (desc.find(bpo.options[i].string_key, false).
+ semantic()->max_tokens() <= 1))
{
// If a duplicate is found, check to see if either one has a value.
if (bpo.options[i].value.size() == 0 &&
diff --git a/src/mlpack/core/util/cli.hpp b/src/mlpack/core/util/cli.hpp
index c38a01b..d1e7d7c 100644
--- a/src/mlpack/core/util/cli.hpp
+++ b/src/mlpack/core/util/cli.hpp
@@ -446,8 +446,8 @@ class CLI
struct IsStdVector { const static bool value = false; };
//! Metaprogramming structure for vector detection.
- template<typename eT>
- struct IsStdVector<std::vector<eT>> { const static bool value = true; };
+ template<typename T, typename A>
+ struct IsStdVector<std::vector<T, A>> { const static bool value = true; };
/**
* Add an option if it is not a vector type. This is a utility function used
diff --git a/src/mlpack/core/util/cli_impl.hpp b/src/mlpack/core/util/cli_impl.hpp
index 6ae9c1c..c3e0e2e 100644
--- a/src/mlpack/core/util/cli_impl.hpp
+++ b/src/mlpack/core/util/cli_impl.hpp
@@ -137,8 +137,7 @@ void CLI::Add(const T& defaultValue,
if (data.isFlag)
desc.add_options()(progOptId.c_str(), description.c_str());
else
- desc.add_options()(progOptId.c_str(),
- po::value<typename util::ParameterType<T>::type>(),
+ GetSingleton().AddOption<typename util::ParameterType<T>::type>(progOptId.c_str(),
description.c_str());
// If the option is required, add it to the required options list.
diff --git a/src/mlpack/tests/cli_test.cpp b/src/mlpack/tests/cli_test.cpp
index ca53256..086a74c 100644
--- a/src/mlpack/tests/cli_test.cpp
+++ b/src/mlpack/tests/cli_test.cpp
@@ -206,6 +206,8 @@ BOOST_AUTO_TEST_CASE(TestBooleanOption)
*/
BOOST_AUTO_TEST_CASE(TestVectorOption)
{
+ AddRequiredCLIOptions();
+
PARAM_VECTOR_IN(size_t, "test_vec", "test description", "t");
int argc = 5;
@@ -235,6 +237,8 @@ BOOST_AUTO_TEST_CASE(TestVectorOption)
*/
BOOST_AUTO_TEST_CASE(TestVectorOption2)
{
+ AddRequiredCLIOptions();
+
PARAM_VECTOR_IN(size_t, "test2_vec", "test description", "T");
int argc = 7;
@@ -247,13 +251,13 @@ BOOST_AUTO_TEST_CASE(TestVectorOption2)
argv[5] = "--test2_vec";
argv[6] = "4";
- Log::Fatal.ignoreInput = true;
+// Log::Fatal.ignoreInput = true;
CLI::ParseCommandLine(argc, const_cast<char**>(argv));
- Log::Fatal.ignoreInput = false;
+// Log::Fatal.ignoreInput = false;
- BOOST_REQUIRE(CLI::HasParam("test_vec"));
+ BOOST_REQUIRE(CLI::HasParam("test2_vec"));
- std::vector<size_t> v = CLI::GetParam<std::vector<size_t>>("test_vec");
+ std::vector<size_t> v = CLI::GetParam<std::vector<size_t>>("test2_vec");
BOOST_REQUIRE_EQUAL(v.size(), 3);
BOOST_REQUIRE_EQUAL(v[0], 1);
More information about the mlpack-git
mailing list