From cefa6ab75006195b8f2352e6d1c947812532bc25 Mon Sep 17 00:00:00 2001 From: NippunSharma Date: Tue, 27 Apr 2021 16:04:06 +0530 Subject: [PATCH 01/11] initial commit --- src/mlpack/bindings/cli/add_to_cli11.hpp | 4 +-- src/mlpack/bindings/cli/cli_option.hpp | 5 ++- src/mlpack/bindings/cli/get_param.hpp | 12 +++++-- .../bindings/cli/get_printable_param_impl.hpp | 8 ++--- src/mlpack/bindings/cli/get_raw_param.hpp | 2 +- src/mlpack/bindings/cli/in_place_copy.hpp | 34 +++++++++++++++---- src/mlpack/bindings/cli/output_param_impl.hpp | 4 +-- src/mlpack/bindings/cli/set_param.hpp | 2 +- 8 files changed, 50 insertions(+), 21 deletions(-) diff --git a/src/mlpack/bindings/cli/add_to_cli11.hpp b/src/mlpack/bindings/cli/add_to_cli11.hpp index f4ae48a608..0e2c93ea0e 100644 --- a/src/mlpack/bindings/cli/add_to_cli11.hpp +++ b/src/mlpack/bindings/cli/add_to_cli11.hpp @@ -46,7 +46,7 @@ void AddToCLI11(const std::string& cliName, app.add_option_function(cliName.c_str(), [¶m](const std::string& value) { - using TupleType = std::tuple::type>; + using TupleType = std::tuple::type, size_t, size_t>; TupleType& tuple = *boost::any_cast(¶m.value); std::get<1>(tuple) = boost::any_cast(value); param.wasPassed = true; @@ -108,7 +108,7 @@ void AddToCLI11(const std::string& cliName, app.add_option_function(cliName.c_str(), [¶m](const std::string& value) { - using TupleType = std::tuple::type>; + using TupleType = std::tuple::type, size_t, size_t>; TupleType& tuple = *boost::any_cast(¶m.value); std::get<1>(tuple) = boost::any_cast(value); param.wasPassed = true; diff --git a/src/mlpack/bindings/cli/cli_option.hpp b/src/mlpack/bindings/cli/cli_option.hpp index eeebc2d7cc..37339cf979 100644 --- a/src/mlpack/bindings/cli/cli_option.hpp +++ b/src/mlpack/bindings/cli/cli_option.hpp @@ -100,7 +100,10 @@ class CLIOption else { typename ParameterType::type>::type tmp; - data.value = boost::any(std::tuple(defaultValue, tmp)); + if(arma::is_arma_type::value) + data.value = boost::any(std::tuple(defaultValue, tmp, 0, 0)); + else + data.value = boost::any(std::tuple(defaultValue, tmp)); } const std::string tname = data.tname; diff --git a/src/mlpack/bindings/cli/get_param.hpp b/src/mlpack/bindings/cli/get_param.hpp index eaaa813d61..b5b23f65ee 100644 --- a/src/mlpack/bindings/cli/get_param.hpp +++ b/src/mlpack/bindings/cli/get_param.hpp @@ -51,10 +51,12 @@ T& GetParam( // contains the filename. It's possible we could load empty matrices many // times, but I am not bothered by that---it shouldn't be something that // happens. - typedef std::tuple::type> TupleType; + typedef std::tuple::type, size_t, size_t> TupleType; TupleType& tuple = *boost::any_cast(&d.value); const std::string& value = std::get<1>(tuple); T& matrix = std::get<0>(tuple); + size_t& n_rows = std::get<2>(tuple); + size_t& n_cols = std::get<3>(tuple); if (d.input && !d.loaded) { // Call correct data::Load() function. @@ -62,6 +64,8 @@ T& GetParam( data::Load(value, matrix, true); else data::Load(value, matrix, true, !d.noTranspose); + n_rows = matrix.n_rows; + n_cols = matrix.n_cols; d.loaded = true; } @@ -81,13 +85,17 @@ T& GetParam( { // If this is an input parameter, we need to load both the matrix and the // dataset info. - typedef std::tuple TupleType; + typedef std::tuple TupleType; TupleType* tuple = boost::any_cast(&d.value); const std::string& value = std::get<1>(*tuple); T& t = std::get<0>(*tuple); + size_t& n_rows = std::get<2>(*tuple); + size_t& n_cols = std::get<3>(*tuple); if (d.input && !d.loaded) { data::Load(value, std::get<1>(t), std::get<0>(t), true, !d.noTranspose); + n_rows = std::get<1>(t).n_rows; + n_cols = std::get<1>(t).n_cols; d.loaded = true; } diff --git a/src/mlpack/bindings/cli/get_printable_param_impl.hpp b/src/mlpack/bindings/cli/get_printable_param_impl.hpp index 9e2584f6b5..b679b2afdf 100644 --- a/src/mlpack/bindings/cli/get_printable_param_impl.hpp +++ b/src/mlpack/bindings/cli/get_printable_param_impl.hpp @@ -79,7 +79,7 @@ std::string GetPrintableParam( std::tuple>::value>::type* /* junk */) { // Extract the string from the tuple that's being held. - typedef std::tuple::type> TupleType; + typedef std::tuple::type, size_t, size_t> TupleType; const TupleType* tuple = boost::any_cast(&data.value); std::ostringstream oss; @@ -87,10 +87,8 @@ std::string GetPrintableParam( if (std::get<1>(*tuple) != "") { - // Make sure the matrix is loaded so that we can print its size. - T& mat = GetParam(const_cast(data)); - std::string matDescription = GetMatrixSize(mat); - + std::string matDescription = std::to_string(std::get<2>(*tuple)) + "x"; + matDescription += std::to_string(std::get<3>(*tuple)) + " matrix"; oss << " (" << matDescription << ")"; } diff --git a/src/mlpack/bindings/cli/get_raw_param.hpp b/src/mlpack/bindings/cli/get_raw_param.hpp index 35d544f08b..a0305df23c 100644 --- a/src/mlpack/bindings/cli/get_raw_param.hpp +++ b/src/mlpack/bindings/cli/get_raw_param.hpp @@ -48,7 +48,7 @@ T& GetRawParam( arma::mat>>::value>::type* = 0) { // Don't load the matrix. - typedef std::tuple TupleType; + typedef std::tuple TupleType; T& value = std::get<0>(*boost::any_cast(&d.value)); return value; } diff --git a/src/mlpack/bindings/cli/in_place_copy.hpp b/src/mlpack/bindings/cli/in_place_copy.hpp index ca0d7667f5..97ce2430b9 100644 --- a/src/mlpack/bindings/cli/in_place_copy.hpp +++ b/src/mlpack/bindings/cli/in_place_copy.hpp @@ -41,7 +41,7 @@ void InPlaceCopyInternal( /** * Modify the filename for any type that needs to be loaded from disk to match - * the filename of the input parameter. + * the filename of the input parameter. For matrix/dataset info. * * @param d ParamData object we want to make into an in-place copy. * @param input ParamData object whose filename we should copy. @@ -50,14 +50,34 @@ template void InPlaceCopyInternal( util::ParamData& d, util::ParamData& input, - const typename std::enable_if< - arma::is_arma_type::value || - std::is_same>::value || - data::HasSerialize::value>::type* = 0) + const typename std::enable_if::value || + std::is_same>::value>::type* = 0) { // Make the output filename the same as the input filename. - typedef std::tuple::type> TupleType; + typedef std::tuple::type, size_t, size_t> TupleType; + TupleType& tuple = *boost::any_cast(&d.value); + std::string& value = std::get<1>(tuple); + + const TupleType& inputTuple = *boost::any_cast(&input.value); + value = std::get<1>(inputTuple); +} + +/** + * Modify the filename for any type that needs to be loaded from disk to match + * the filename of the input parameter. For serializable object. + * + * @param d ParamData object we want to make into an in-place copy. + * @param input ParamData object whose filename we should copy. + */ +template +void InPlaceCopyInternal( + util::ParamData& d, + util::ParamData& input, + const typename std::enable_if::value>::type* = 0) +{ + // Make the output filename the same as the input filename. + typedef std::tuple::type> TupleType; TupleType& tuple = *boost::any_cast(&d.value); std::string& value = std::get<1>(tuple); diff --git a/src/mlpack/bindings/cli/output_param_impl.hpp b/src/mlpack/bindings/cli/output_param_impl.hpp index c4dcfddbf4..0bc0a5a75c 100644 --- a/src/mlpack/bindings/cli/output_param_impl.hpp +++ b/src/mlpack/bindings/cli/output_param_impl.hpp @@ -53,7 +53,7 @@ void OutputParamImpl( util::ParamData& data, const typename boost::enable_if>::type* /* junk */) { - typedef std::tuple TupleType; + typedef std::tuple TupleType; const T& output = std::get<0>(*boost::any_cast(&data.value)); const std::string& filename = std::get<1>(*boost::any_cast(&data.value)); @@ -95,7 +95,7 @@ void OutputParamImpl( std::tuple>>::type* /* junk */) { // Output the matrix with the mappings. - typedef std::tuple TupleType; + typedef std::tuple TupleType; const T& tuple = std::get<0>(*boost::any_cast(&data.value)); const std::string& filename = std::get<1>(*boost::any_cast(&data.value)); diff --git a/src/mlpack/bindings/cli/set_param.hpp b/src/mlpack/bindings/cli/set_param.hpp index 8295b51242..8a7695e6a9 100644 --- a/src/mlpack/bindings/cli/set_param.hpp +++ b/src/mlpack/bindings/cli/set_param.hpp @@ -63,7 +63,7 @@ void SetParam( std::tuple>::value>::type* = 0) { // We're setting the string filename. - typedef std::tuple::type> TupleType; + typedef std::tuple::type, size_t, size_t> TupleType; TupleType& tuple = *boost::any_cast(&d.value); std::get<1>(tuple) = boost::any_cast(value); } From 46982228b962bacafec244b4eec38afd5aa391bb Mon Sep 17 00:00:00 2001 From: NippunSharma Date: Tue, 27 Apr 2021 21:15:32 +0530 Subject: [PATCH 02/11] fixing tests --- src/mlpack/bindings/cli/set_param.hpp | 4 +-- src/mlpack/tests/cli_binding_test.cpp | 36 +++++++++++++-------------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/mlpack/bindings/cli/set_param.hpp b/src/mlpack/bindings/cli/set_param.hpp index 8a7695e6a9..10e265d52d 100644 --- a/src/mlpack/bindings/cli/set_param.hpp +++ b/src/mlpack/bindings/cli/set_param.hpp @@ -51,8 +51,8 @@ void SetParam( } /** - * Set a matrix parameter, a matrix/dataset info parameter, or a serializable - * object. These set the filename referring to the parameter. + * Set a matrix parameter, a matrix/dataset info parameter. + * These set the filename referring to the parameter. */ template void SetParam( diff --git a/src/mlpack/tests/cli_binding_test.cpp b/src/mlpack/tests/cli_binding_test.cpp index 391a0bfe1a..10532572a0 100644 --- a/src/mlpack/tests/cli_binding_test.cpp +++ b/src/mlpack/tests/cli_binding_test.cpp @@ -82,7 +82,7 @@ TEST_CASE("GetParamLoadedMatTest", "[CLIOptionTest]") // Create value. string filename = "hello.csv"; arma::mat m(5, 5, arma::fill::ones); - tuple tuple = make_tuple(m, filename); + tuple tuple = make_tuple(m, filename, 0, 0); d.value = boost::any(tuple); // Mark it as already loaded. d.input = true; @@ -106,7 +106,7 @@ TEST_CASE("GetParamUnloadedMatTest", "[CLIOptionTest]") arma::mat test(5, 5, arma::fill::ones); data::Save("test.csv", test); arma::mat m; - tuple tuple = make_tuple(m, filename); + tuple tuple = make_tuple(m, filename, 0, 0); d.value = boost::any(tuple); // Make sure it is not loaded yet. d.input = true; @@ -132,7 +132,7 @@ TEST_CASE("GetParamUmatTest", "[CLIOptionTest]") // Create value. string filename = "hello.csv"; arma::Mat m(5, 5, arma::fill::ones); - tuple, string> tuple = make_tuple(m, filename); + tuple, string, size_t, size_t> tuple = make_tuple(m, filename, 0, 0); d.value = boost::any(tuple); // Mark it as already loaded. d.input = true; @@ -157,7 +157,7 @@ TEST_CASE("GetParamUnloadedUmatTest", "[CLIOptionTest]") arma::Mat test(5, 5, arma::fill::ones); data::Save("test.csv", test); arma::Mat m; - tuple, string> tuple = make_tuple(m, filename); + tuple, string, size_t, size_t> tuple = make_tuple(m, filename, 0, 0); d.value = boost::any(tuple); // Make sure it is not loaded yet. d.input = true; @@ -200,7 +200,7 @@ TEST_CASE("GetParamDatasetInfoMatTest", "[CLIOptionTest]") arma::mat m; tuple tuple1 = make_tuple(dd, m); - tuple tuple2 = make_tuple(tuple1, filename); + tuple tuple2 = make_tuple(tuple1, filename, 0, 0); d.value = boost::any(tuple2); // Make sure it is not loaded yet. @@ -274,7 +274,7 @@ TEST_CASE("RawParamMatTest", "[CLIOptionTest]") // Create value. string filename = "hello.csv"; arma::mat m(5, 5, arma::fill::ones); - tuple tuple = make_tuple(m, filename); + tuple tuple = make_tuple(m, filename, 0, 0); d.value = boost::any(tuple); d.input = true; d.loaded = false; @@ -324,7 +324,7 @@ TEST_CASE("GetRawParamDatasetInfoTest", "[CLIOptionTest]") arma::mat m(3, 3, arma::fill::randu); tuple tuple1 = make_tuple(dd, m); - tuple tuple2 = make_tuple(tuple1, filename); + tuple tuple2 = make_tuple(tuple1, filename, 0, 0); d.value = boost::any(tuple2); // Make sure it is not loaded yet. @@ -350,7 +350,7 @@ TEST_CASE("OutputParamMatTest", "[CLIOptionTest]") // Create value. string filename = "test.csv"; arma::mat m(3, 3, arma::fill::randu); - tuple t = make_tuple(m, filename); + tuple t = make_tuple(m, filename, 0, 0); d.value = boost::any(t); d.input = false; @@ -376,7 +376,7 @@ TEST_CASE("OutputParamUmatTest", "[CLIOptionTest]") // Create value. string filename = "test.csv"; arma::Mat m(3, 3, arma::fill::randu); - tuple, string> t = make_tuple(m, filename); + tuple, string, size_t, size_t> t = make_tuple(m, filename, 0, 0); d.value = boost::any(t); d.input = false; @@ -467,7 +467,7 @@ TEST_CASE("SetParamMatrixTest", "[CLIOptionTest]") // Create initial value. string filename = "hello.csv"; arma::mat m(5, 5, arma::fill::randu); - d.value = boost::any(make_tuple(m, filename)); + d.value = boost::any(make_tuple(m, filename, size_t(0), size_t(0))); // Get a new string. string newFilename = "new.csv"; @@ -475,10 +475,9 @@ TEST_CASE("SetParamMatrixTest", "[CLIOptionTest]") SetParam((util::ParamData&) d, (const void*) &a2, (void*) NULL); - // Make sure the change went through. - tuple& t = - *boost::any_cast>(&d.value); + tuple& t = + *boost::any_cast>(&d.value); REQUIRE(get<1>(t) == "new.csv"); } @@ -518,7 +517,8 @@ TEST_CASE("SetParamDatasetInfoMatTest", "[CLIOptionTest]") arma::mat m(3, 3, arma::fill::randu); DatasetInfo di(3); tuple t1 = make_tuple(di, m); - tuple, string> t2 = make_tuple(t1, filename); + tuple, string, size_t, size_t> t2 = make_tuple(t1, filename, + size_t(0), size_t(0)); d.value = boost::any(t2); d.noTranspose = false; @@ -530,8 +530,8 @@ TEST_CASE("SetParamDatasetInfoMatTest", "[CLIOptionTest]") (const void*) &a2, (void*) NULL); // Check that the name is right. - tuple, string>& t3 = - *boost::any_cast, string>>(&d.value); + tuple, string, size_t, size_t>& t3 = + *boost::any_cast, string, size_t, size_t>>(&d.value); REQUIRE(get<1>(t3) == "new_filename.csv"); } @@ -556,7 +556,7 @@ TEST_CASE("GetAllocatedMemoryNonModelTest", "[CLIOptionTest]") // Also test with a matrix type. arma::mat test(10, 10, arma::fill::ones); string filename = "test.csv"; - tuple t = make_tuple(test, filename); + tuple t = make_tuple(test, filename, 0, 0); d.value = boost::any(t); result = (void*) 1; @@ -602,7 +602,7 @@ TEST_CASE("DeleteAllocatedMemoryNonModelTest", "[CLIOptionTest]") arma::mat test(10, 10, arma::fill::ones); string filename = "test.csv"; - tuple t = make_tuple(test, filename); + tuple t = make_tuple(test, filename, 0, 0); d.value = boost::any(t); DeleteAllocatedMemory((util::ParamData&) d, From 7cfff7d5aad7e2e0dc27ede874922ed8192c90c3 Mon Sep 17 00:00:00 2001 From: NippunSharma Date: Wed, 28 Apr 2021 00:09:57 +0530 Subject: [PATCH 03/11] fixing tests 2 --- src/mlpack/bindings/cli/cli_option.hpp | 3 ++- src/mlpack/bindings/cli/get_printable_param_impl.hpp | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/mlpack/bindings/cli/cli_option.hpp b/src/mlpack/bindings/cli/cli_option.hpp index 37339cf979..10ae7ddc1b 100644 --- a/src/mlpack/bindings/cli/cli_option.hpp +++ b/src/mlpack/bindings/cli/cli_option.hpp @@ -100,7 +100,8 @@ class CLIOption else { typename ParameterType::type>::type tmp; - if(arma::is_arma_type::value) + if(arma::is_arma_type::value || + std::is_same>::value) data.value = boost::any(std::tuple(defaultValue, tmp, 0, 0)); else data.value = boost::any(std::tuple(defaultValue, tmp)); diff --git a/src/mlpack/bindings/cli/get_printable_param_impl.hpp b/src/mlpack/bindings/cli/get_printable_param_impl.hpp index b679b2afdf..89e0c75fe7 100644 --- a/src/mlpack/bindings/cli/get_printable_param_impl.hpp +++ b/src/mlpack/bindings/cli/get_printable_param_impl.hpp @@ -87,6 +87,8 @@ std::string GetPrintableParam( if (std::get<1>(*tuple) != "") { + // make sure that the matrix is loaded, so that we can print its size. + GetParam(const_cast(data)); std::string matDescription = std::to_string(std::get<2>(*tuple)) + "x"; matDescription += std::to_string(std::get<3>(*tuple)) + " matrix"; oss << " (" << matDescription << ")"; From dbd882707b2d880429b89abf80ce4b0bded08192 Mon Sep 17 00:00:00 2001 From: NippunSharma Date: Wed, 5 May 2021 09:50:30 +0530 Subject: [PATCH 04/11] undo changes --- src/mlpack/bindings/cli/add_to_cli11.hpp | 4 +-- src/mlpack/bindings/cli/cli_option.hpp | 6 +--- src/mlpack/bindings/cli/get_param.hpp | 12 ++----- .../bindings/cli/get_printable_param_impl.hpp | 10 +++--- src/mlpack/bindings/cli/get_raw_param.hpp | 2 +- src/mlpack/bindings/cli/in_place_copy.hpp | 34 ++++-------------- src/mlpack/bindings/cli/output_param_impl.hpp | 4 +-- src/mlpack/bindings/cli/set_param.hpp | 6 ++-- src/mlpack/tests/cli_binding_test.cpp | 36 +++++++++---------- 9 files changed, 41 insertions(+), 73 deletions(-) diff --git a/src/mlpack/bindings/cli/add_to_cli11.hpp b/src/mlpack/bindings/cli/add_to_cli11.hpp index 0e2c93ea0e..f4ae48a608 100644 --- a/src/mlpack/bindings/cli/add_to_cli11.hpp +++ b/src/mlpack/bindings/cli/add_to_cli11.hpp @@ -46,7 +46,7 @@ void AddToCLI11(const std::string& cliName, app.add_option_function(cliName.c_str(), [¶m](const std::string& value) { - using TupleType = std::tuple::type, size_t, size_t>; + using TupleType = std::tuple::type>; TupleType& tuple = *boost::any_cast(¶m.value); std::get<1>(tuple) = boost::any_cast(value); param.wasPassed = true; @@ -108,7 +108,7 @@ void AddToCLI11(const std::string& cliName, app.add_option_function(cliName.c_str(), [¶m](const std::string& value) { - using TupleType = std::tuple::type, size_t, size_t>; + using TupleType = std::tuple::type>; TupleType& tuple = *boost::any_cast(¶m.value); std::get<1>(tuple) = boost::any_cast(value); param.wasPassed = true; diff --git a/src/mlpack/bindings/cli/cli_option.hpp b/src/mlpack/bindings/cli/cli_option.hpp index 10ae7ddc1b..eeebc2d7cc 100644 --- a/src/mlpack/bindings/cli/cli_option.hpp +++ b/src/mlpack/bindings/cli/cli_option.hpp @@ -100,11 +100,7 @@ class CLIOption else { typename ParameterType::type>::type tmp; - if(arma::is_arma_type::value || - std::is_same>::value) - data.value = boost::any(std::tuple(defaultValue, tmp, 0, 0)); - else - data.value = boost::any(std::tuple(defaultValue, tmp)); + data.value = boost::any(std::tuple(defaultValue, tmp)); } const std::string tname = data.tname; diff --git a/src/mlpack/bindings/cli/get_param.hpp b/src/mlpack/bindings/cli/get_param.hpp index b5b23f65ee..eaaa813d61 100644 --- a/src/mlpack/bindings/cli/get_param.hpp +++ b/src/mlpack/bindings/cli/get_param.hpp @@ -51,12 +51,10 @@ T& GetParam( // contains the filename. It's possible we could load empty matrices many // times, but I am not bothered by that---it shouldn't be something that // happens. - typedef std::tuple::type, size_t, size_t> TupleType; + typedef std::tuple::type> TupleType; TupleType& tuple = *boost::any_cast(&d.value); const std::string& value = std::get<1>(tuple); T& matrix = std::get<0>(tuple); - size_t& n_rows = std::get<2>(tuple); - size_t& n_cols = std::get<3>(tuple); if (d.input && !d.loaded) { // Call correct data::Load() function. @@ -64,8 +62,6 @@ T& GetParam( data::Load(value, matrix, true); else data::Load(value, matrix, true, !d.noTranspose); - n_rows = matrix.n_rows; - n_cols = matrix.n_cols; d.loaded = true; } @@ -85,17 +81,13 @@ T& GetParam( { // If this is an input parameter, we need to load both the matrix and the // dataset info. - typedef std::tuple TupleType; + typedef std::tuple TupleType; TupleType* tuple = boost::any_cast(&d.value); const std::string& value = std::get<1>(*tuple); T& t = std::get<0>(*tuple); - size_t& n_rows = std::get<2>(*tuple); - size_t& n_cols = std::get<3>(*tuple); if (d.input && !d.loaded) { data::Load(value, std::get<1>(t), std::get<0>(t), true, !d.noTranspose); - n_rows = std::get<1>(t).n_rows; - n_cols = std::get<1>(t).n_cols; d.loaded = true; } diff --git a/src/mlpack/bindings/cli/get_printable_param_impl.hpp b/src/mlpack/bindings/cli/get_printable_param_impl.hpp index 89e0c75fe7..9e2584f6b5 100644 --- a/src/mlpack/bindings/cli/get_printable_param_impl.hpp +++ b/src/mlpack/bindings/cli/get_printable_param_impl.hpp @@ -79,7 +79,7 @@ std::string GetPrintableParam( std::tuple>::value>::type* /* junk */) { // Extract the string from the tuple that's being held. - typedef std::tuple::type, size_t, size_t> TupleType; + typedef std::tuple::type> TupleType; const TupleType* tuple = boost::any_cast(&data.value); std::ostringstream oss; @@ -87,10 +87,10 @@ std::string GetPrintableParam( if (std::get<1>(*tuple) != "") { - // make sure that the matrix is loaded, so that we can print its size. - GetParam(const_cast(data)); - std::string matDescription = std::to_string(std::get<2>(*tuple)) + "x"; - matDescription += std::to_string(std::get<3>(*tuple)) + " matrix"; + // Make sure the matrix is loaded so that we can print its size. + T& mat = GetParam(const_cast(data)); + std::string matDescription = GetMatrixSize(mat); + oss << " (" << matDescription << ")"; } diff --git a/src/mlpack/bindings/cli/get_raw_param.hpp b/src/mlpack/bindings/cli/get_raw_param.hpp index a0305df23c..35d544f08b 100644 --- a/src/mlpack/bindings/cli/get_raw_param.hpp +++ b/src/mlpack/bindings/cli/get_raw_param.hpp @@ -48,7 +48,7 @@ T& GetRawParam( arma::mat>>::value>::type* = 0) { // Don't load the matrix. - typedef std::tuple TupleType; + typedef std::tuple TupleType; T& value = std::get<0>(*boost::any_cast(&d.value)); return value; } diff --git a/src/mlpack/bindings/cli/in_place_copy.hpp b/src/mlpack/bindings/cli/in_place_copy.hpp index 97ce2430b9..ca0d7667f5 100644 --- a/src/mlpack/bindings/cli/in_place_copy.hpp +++ b/src/mlpack/bindings/cli/in_place_copy.hpp @@ -41,7 +41,7 @@ void InPlaceCopyInternal( /** * Modify the filename for any type that needs to be loaded from disk to match - * the filename of the input parameter. For matrix/dataset info. + * the filename of the input parameter. * * @param d ParamData object we want to make into an in-place copy. * @param input ParamData object whose filename we should copy. @@ -50,34 +50,14 @@ template void InPlaceCopyInternal( util::ParamData& d, util::ParamData& input, - const typename std::enable_if::value || - std::is_same>::value>::type* = 0) + const typename std::enable_if< + arma::is_arma_type::value || + std::is_same>::value || + data::HasSerialize::value>::type* = 0) { // Make the output filename the same as the input filename. - typedef std::tuple::type, size_t, size_t> TupleType; - TupleType& tuple = *boost::any_cast(&d.value); - std::string& value = std::get<1>(tuple); - - const TupleType& inputTuple = *boost::any_cast(&input.value); - value = std::get<1>(inputTuple); -} - -/** - * Modify the filename for any type that needs to be loaded from disk to match - * the filename of the input parameter. For serializable object. - * - * @param d ParamData object we want to make into an in-place copy. - * @param input ParamData object whose filename we should copy. - */ -template -void InPlaceCopyInternal( - util::ParamData& d, - util::ParamData& input, - const typename std::enable_if::value>::type* = 0) -{ - // Make the output filename the same as the input filename. - typedef std::tuple::type> TupleType; + typedef std::tuple::type> TupleType; TupleType& tuple = *boost::any_cast(&d.value); std::string& value = std::get<1>(tuple); diff --git a/src/mlpack/bindings/cli/output_param_impl.hpp b/src/mlpack/bindings/cli/output_param_impl.hpp index 0bc0a5a75c..c4dcfddbf4 100644 --- a/src/mlpack/bindings/cli/output_param_impl.hpp +++ b/src/mlpack/bindings/cli/output_param_impl.hpp @@ -53,7 +53,7 @@ void OutputParamImpl( util::ParamData& data, const typename boost::enable_if>::type* /* junk */) { - typedef std::tuple TupleType; + typedef std::tuple TupleType; const T& output = std::get<0>(*boost::any_cast(&data.value)); const std::string& filename = std::get<1>(*boost::any_cast(&data.value)); @@ -95,7 +95,7 @@ void OutputParamImpl( std::tuple>>::type* /* junk */) { // Output the matrix with the mappings. - typedef std::tuple TupleType; + typedef std::tuple TupleType; const T& tuple = std::get<0>(*boost::any_cast(&data.value)); const std::string& filename = std::get<1>(*boost::any_cast(&data.value)); diff --git a/src/mlpack/bindings/cli/set_param.hpp b/src/mlpack/bindings/cli/set_param.hpp index 10e265d52d..8295b51242 100644 --- a/src/mlpack/bindings/cli/set_param.hpp +++ b/src/mlpack/bindings/cli/set_param.hpp @@ -51,8 +51,8 @@ void SetParam( } /** - * Set a matrix parameter, a matrix/dataset info parameter. - * These set the filename referring to the parameter. + * Set a matrix parameter, a matrix/dataset info parameter, or a serializable + * object. These set the filename referring to the parameter. */ template void SetParam( @@ -63,7 +63,7 @@ void SetParam( std::tuple>::value>::type* = 0) { // We're setting the string filename. - typedef std::tuple::type, size_t, size_t> TupleType; + typedef std::tuple::type> TupleType; TupleType& tuple = *boost::any_cast(&d.value); std::get<1>(tuple) = boost::any_cast(value); } diff --git a/src/mlpack/tests/cli_binding_test.cpp b/src/mlpack/tests/cli_binding_test.cpp index 10532572a0..391a0bfe1a 100644 --- a/src/mlpack/tests/cli_binding_test.cpp +++ b/src/mlpack/tests/cli_binding_test.cpp @@ -82,7 +82,7 @@ TEST_CASE("GetParamLoadedMatTest", "[CLIOptionTest]") // Create value. string filename = "hello.csv"; arma::mat m(5, 5, arma::fill::ones); - tuple tuple = make_tuple(m, filename, 0, 0); + tuple tuple = make_tuple(m, filename); d.value = boost::any(tuple); // Mark it as already loaded. d.input = true; @@ -106,7 +106,7 @@ TEST_CASE("GetParamUnloadedMatTest", "[CLIOptionTest]") arma::mat test(5, 5, arma::fill::ones); data::Save("test.csv", test); arma::mat m; - tuple tuple = make_tuple(m, filename, 0, 0); + tuple tuple = make_tuple(m, filename); d.value = boost::any(tuple); // Make sure it is not loaded yet. d.input = true; @@ -132,7 +132,7 @@ TEST_CASE("GetParamUmatTest", "[CLIOptionTest]") // Create value. string filename = "hello.csv"; arma::Mat m(5, 5, arma::fill::ones); - tuple, string, size_t, size_t> tuple = make_tuple(m, filename, 0, 0); + tuple, string> tuple = make_tuple(m, filename); d.value = boost::any(tuple); // Mark it as already loaded. d.input = true; @@ -157,7 +157,7 @@ TEST_CASE("GetParamUnloadedUmatTest", "[CLIOptionTest]") arma::Mat test(5, 5, arma::fill::ones); data::Save("test.csv", test); arma::Mat m; - tuple, string, size_t, size_t> tuple = make_tuple(m, filename, 0, 0); + tuple, string> tuple = make_tuple(m, filename); d.value = boost::any(tuple); // Make sure it is not loaded yet. d.input = true; @@ -200,7 +200,7 @@ TEST_CASE("GetParamDatasetInfoMatTest", "[CLIOptionTest]") arma::mat m; tuple tuple1 = make_tuple(dd, m); - tuple tuple2 = make_tuple(tuple1, filename, 0, 0); + tuple tuple2 = make_tuple(tuple1, filename); d.value = boost::any(tuple2); // Make sure it is not loaded yet. @@ -274,7 +274,7 @@ TEST_CASE("RawParamMatTest", "[CLIOptionTest]") // Create value. string filename = "hello.csv"; arma::mat m(5, 5, arma::fill::ones); - tuple tuple = make_tuple(m, filename, 0, 0); + tuple tuple = make_tuple(m, filename); d.value = boost::any(tuple); d.input = true; d.loaded = false; @@ -324,7 +324,7 @@ TEST_CASE("GetRawParamDatasetInfoTest", "[CLIOptionTest]") arma::mat m(3, 3, arma::fill::randu); tuple tuple1 = make_tuple(dd, m); - tuple tuple2 = make_tuple(tuple1, filename, 0, 0); + tuple tuple2 = make_tuple(tuple1, filename); d.value = boost::any(tuple2); // Make sure it is not loaded yet. @@ -350,7 +350,7 @@ TEST_CASE("OutputParamMatTest", "[CLIOptionTest]") // Create value. string filename = "test.csv"; arma::mat m(3, 3, arma::fill::randu); - tuple t = make_tuple(m, filename, 0, 0); + tuple t = make_tuple(m, filename); d.value = boost::any(t); d.input = false; @@ -376,7 +376,7 @@ TEST_CASE("OutputParamUmatTest", "[CLIOptionTest]") // Create value. string filename = "test.csv"; arma::Mat m(3, 3, arma::fill::randu); - tuple, string, size_t, size_t> t = make_tuple(m, filename, 0, 0); + tuple, string> t = make_tuple(m, filename); d.value = boost::any(t); d.input = false; @@ -467,7 +467,7 @@ TEST_CASE("SetParamMatrixTest", "[CLIOptionTest]") // Create initial value. string filename = "hello.csv"; arma::mat m(5, 5, arma::fill::randu); - d.value = boost::any(make_tuple(m, filename, size_t(0), size_t(0))); + d.value = boost::any(make_tuple(m, filename)); // Get a new string. string newFilename = "new.csv"; @@ -475,9 +475,10 @@ TEST_CASE("SetParamMatrixTest", "[CLIOptionTest]") SetParam((util::ParamData&) d, (const void*) &a2, (void*) NULL); + // Make sure the change went through. - tuple& t = - *boost::any_cast>(&d.value); + tuple& t = + *boost::any_cast>(&d.value); REQUIRE(get<1>(t) == "new.csv"); } @@ -517,8 +518,7 @@ TEST_CASE("SetParamDatasetInfoMatTest", "[CLIOptionTest]") arma::mat m(3, 3, arma::fill::randu); DatasetInfo di(3); tuple t1 = make_tuple(di, m); - tuple, string, size_t, size_t> t2 = make_tuple(t1, filename, - size_t(0), size_t(0)); + tuple, string> t2 = make_tuple(t1, filename); d.value = boost::any(t2); d.noTranspose = false; @@ -530,8 +530,8 @@ TEST_CASE("SetParamDatasetInfoMatTest", "[CLIOptionTest]") (const void*) &a2, (void*) NULL); // Check that the name is right. - tuple, string, size_t, size_t>& t3 = - *boost::any_cast, string, size_t, size_t>>(&d.value); + tuple, string>& t3 = + *boost::any_cast, string>>(&d.value); REQUIRE(get<1>(t3) == "new_filename.csv"); } @@ -556,7 +556,7 @@ TEST_CASE("GetAllocatedMemoryNonModelTest", "[CLIOptionTest]") // Also test with a matrix type. arma::mat test(10, 10, arma::fill::ones); string filename = "test.csv"; - tuple t = make_tuple(test, filename, 0, 0); + tuple t = make_tuple(test, filename); d.value = boost::any(t); result = (void*) 1; @@ -602,7 +602,7 @@ TEST_CASE("DeleteAllocatedMemoryNonModelTest", "[CLIOptionTest]") arma::mat test(10, 10, arma::fill::ones); string filename = "test.csv"; - tuple t = make_tuple(test, filename, 0, 0); + tuple t = make_tuple(test, filename); d.value = boost::any(t); DeleteAllocatedMemory((util::ParamData&) d, From c53ab383487d893629ebf2c8e27074ea0df3e927 Mon Sep 17 00:00:00 2001 From: NippunSharma Date: Wed, 5 May 2021 19:00:16 +0530 Subject: [PATCH 05/11] made recommended changes --- src/mlpack/bindings/cli/add_to_cli11.hpp | 4 +-- src/mlpack/bindings/cli/get_param.hpp | 14 ++++++++-- .../bindings/cli/get_printable_param_impl.hpp | 9 +++--- src/mlpack/bindings/cli/get_raw_param.hpp | 2 +- src/mlpack/bindings/cli/in_place_copy.hpp | 28 +++++++++++++++++-- src/mlpack/bindings/cli/output_param_impl.hpp | 8 +++--- src/mlpack/bindings/cli/parameter_type.hpp | 8 +++--- src/mlpack/bindings/cli/set_param.hpp | 6 ++-- 8 files changed, 55 insertions(+), 24 deletions(-) diff --git a/src/mlpack/bindings/cli/add_to_cli11.hpp b/src/mlpack/bindings/cli/add_to_cli11.hpp index f4ae48a608..ceb03c64e2 100644 --- a/src/mlpack/bindings/cli/add_to_cli11.hpp +++ b/src/mlpack/bindings/cli/add_to_cli11.hpp @@ -48,7 +48,7 @@ void AddToCLI11(const std::string& cliName, { using TupleType = std::tuple::type>; TupleType& tuple = *boost::any_cast(¶m.value); - std::get<1>(tuple) = boost::any_cast(value); + std::get<0>(std::get<1>(tuple)) = boost::any_cast(value); param.wasPassed = true; }, param.desc.c_str()); @@ -110,7 +110,7 @@ void AddToCLI11(const std::string& cliName, { using TupleType = std::tuple::type>; TupleType& tuple = *boost::any_cast(¶m.value); - std::get<1>(tuple) = boost::any_cast(value); + std::get<0>(std::get<1>(tuple)) = boost::any_cast(value); param.wasPassed = true; }, param.desc.c_str()); diff --git a/src/mlpack/bindings/cli/get_param.hpp b/src/mlpack/bindings/cli/get_param.hpp index eaaa813d61..d401e0e554 100644 --- a/src/mlpack/bindings/cli/get_param.hpp +++ b/src/mlpack/bindings/cli/get_param.hpp @@ -53,8 +53,10 @@ T& GetParam( // happens. typedef std::tuple::type> TupleType; TupleType& tuple = *boost::any_cast(&d.value); - const std::string& value = std::get<1>(tuple); + const std::string& value = std::get<0>(std::get<1>(tuple)); T& matrix = std::get<0>(tuple); + size_t& n_rows = std::get<1>(std::get<1>(tuple)); + size_t& n_cols = std::get<2>(std::get<1>(tuple)); if (d.input && !d.loaded) { // Call correct data::Load() function. @@ -62,6 +64,8 @@ T& GetParam( data::Load(value, matrix, true); else data::Load(value, matrix, true, !d.noTranspose); + n_rows = matrix.n_rows; + n_cols = matrix.n_cols; d.loaded = true; } @@ -81,13 +85,17 @@ T& GetParam( { // If this is an input parameter, we need to load both the matrix and the // dataset info. - typedef std::tuple TupleType; + typedef std::tuple> TupleType; TupleType* tuple = boost::any_cast(&d.value); - const std::string& value = std::get<1>(*tuple); + const std::string& value = std::get<0>(std::get<1>(*tuple)); T& t = std::get<0>(*tuple); + size_t& n_rows = std::get<1>(std::get<1>(*tuple)); + size_t& n_cols = std::get<2>(std::get<1>(*tuple)); if (d.input && !d.loaded) { data::Load(value, std::get<1>(t), std::get<0>(t), true, !d.noTranspose); + n_rows = std::get<1>(t).n_rows; + n_cols = std::get<1>(t).n_cols; d.loaded = true; } diff --git a/src/mlpack/bindings/cli/get_printable_param_impl.hpp b/src/mlpack/bindings/cli/get_printable_param_impl.hpp index 9e2584f6b5..8a3cb211cb 100644 --- a/src/mlpack/bindings/cli/get_printable_param_impl.hpp +++ b/src/mlpack/bindings/cli/get_printable_param_impl.hpp @@ -83,13 +83,14 @@ std::string GetPrintableParam( const TupleType* tuple = boost::any_cast(&data.value); std::ostringstream oss; - oss << "'" << std::get<1>(*tuple) << "'"; + oss << "'" << std::get<0>(std::get<1>(*tuple)) << "'"; - if (std::get<1>(*tuple) != "") + if (std::get<0>(std::get<1>(*tuple)) != "") { // Make sure the matrix is loaded so that we can print its size. - T& mat = GetParam(const_cast(data)); - std::string matDescription = GetMatrixSize(mat); + GetParam(const_cast(data)); + std::string matDescription = std::to_string(std::get<1>(std::get<1>(*tuple))) + "x"; + matDescription += std::to_string(std::get<2>(std::get<1>(*tuple))) + " matrix"; oss << " (" << matDescription << ")"; } diff --git a/src/mlpack/bindings/cli/get_raw_param.hpp b/src/mlpack/bindings/cli/get_raw_param.hpp index 35d544f08b..46c3956a1f 100644 --- a/src/mlpack/bindings/cli/get_raw_param.hpp +++ b/src/mlpack/bindings/cli/get_raw_param.hpp @@ -48,7 +48,7 @@ T& GetRawParam( arma::mat>>::value>::type* = 0) { // Don't load the matrix. - typedef std::tuple TupleType; + typedef std::tuple> TupleType; T& value = std::get<0>(*boost::any_cast(&d.value)); return value; } diff --git a/src/mlpack/bindings/cli/in_place_copy.hpp b/src/mlpack/bindings/cli/in_place_copy.hpp index ca0d7667f5..e2094e53d4 100644 --- a/src/mlpack/bindings/cli/in_place_copy.hpp +++ b/src/mlpack/bindings/cli/in_place_copy.hpp @@ -41,7 +41,7 @@ void InPlaceCopyInternal( /** * Modify the filename for any type that needs to be loaded from disk to match - * the filename of the input parameter. + * the filename of the input parameter. For matrix/datasetinfo parameter. * * @param d ParamData object we want to make into an in-place copy. * @param input ParamData object whose filename we should copy. @@ -53,12 +53,34 @@ void InPlaceCopyInternal( const typename std::enable_if< arma::is_arma_type::value || std::is_same>::value || - data::HasSerialize::value>::type* = 0) + std::tuple>::value>::type* = 0) { // Make the output filename the same as the input filename. typedef std::tuple::type> TupleType; TupleType& tuple = *boost::any_cast(&d.value); + std::string& value = std::get<0>(std::get<1>(tuple)); + + const TupleType& inputTuple = *boost::any_cast(&input.value); + value = std::get<0>(std::get<1>(inputTuple)); +} + +/** + * Modify the filename for any type that needs to be loaded from disk to match + * the filename of the input parameter. For Serializable object. + * + * @param d ParamData object we want to make into an in-place copy. + * @param input ParamData object whose filename we should copy. + */ +template +void InPlaceCopyInternal( + util::ParamData& d, + util::ParamData& input, + const typename std::enable_if< + data::HasSerialize::value>::type* = 0) +{ + // Make the output filename the same as the input filename. + typedef std::tuple::type> TupleType; + TupleType& tuple = *boost::any_cast(&d.value); std::string& value = std::get<1>(tuple); const TupleType& inputTuple = *boost::any_cast(&input.value); diff --git a/src/mlpack/bindings/cli/output_param_impl.hpp b/src/mlpack/bindings/cli/output_param_impl.hpp index c4dcfddbf4..ab2f1e8822 100644 --- a/src/mlpack/bindings/cli/output_param_impl.hpp +++ b/src/mlpack/bindings/cli/output_param_impl.hpp @@ -53,10 +53,10 @@ void OutputParamImpl( util::ParamData& data, const typename boost::enable_if>::type* /* junk */) { - typedef std::tuple TupleType; + typedef std::tuple> TupleType; const T& output = std::get<0>(*boost::any_cast(&data.value)); const std::string& filename = - std::get<1>(*boost::any_cast(&data.value)); + std::get<0>(std::get<1>(*boost::any_cast(&data.value))); if (output.n_elem > 0 && filename != "") { @@ -95,10 +95,10 @@ void OutputParamImpl( std::tuple>>::type* /* junk */) { // Output the matrix with the mappings. - typedef std::tuple TupleType; + typedef std::tuple> TupleType; const T& tuple = std::get<0>(*boost::any_cast(&data.value)); const std::string& filename = - std::get<1>(*boost::any_cast(&data.value)); + std::get<0>(std::get<1>(*boost::any_cast(&data.value))); const arma::mat& matrix = std::get<1>(tuple); // The mapping isn't taken into account. We should write a data::Save() diff --git a/src/mlpack/bindings/cli/parameter_type.hpp b/src/mlpack/bindings/cli/parameter_type.hpp index ddc289ae32..036240b375 100644 --- a/src/mlpack/bindings/cli/parameter_type.hpp +++ b/src/mlpack/bindings/cli/parameter_type.hpp @@ -53,7 +53,7 @@ struct ParameterType template struct ParameterType> { - typedef std::string type; + typedef std::tuple type; }; /** @@ -65,7 +65,7 @@ struct ParameterType> template struct ParameterType> { - typedef std::string type; + typedef std::tuple type; }; /** @@ -76,7 +76,7 @@ struct ParameterType> template struct ParameterType> { - typedef std::string type; + typedef std::tuple type; }; /** @@ -86,7 +86,7 @@ template struct ParameterType, arma::Mat>> { - typedef std::string type; + typedef std::tuple type; }; } // namespace cli diff --git a/src/mlpack/bindings/cli/set_param.hpp b/src/mlpack/bindings/cli/set_param.hpp index 8295b51242..f800fe0553 100644 --- a/src/mlpack/bindings/cli/set_param.hpp +++ b/src/mlpack/bindings/cli/set_param.hpp @@ -51,8 +51,8 @@ void SetParam( } /** - * Set a matrix parameter, a matrix/dataset info parameter, or a serializable - * object. These set the filename referring to the parameter. + * Set a matrix parameter, a matrix/dataset info parameter. + * These set the filename referring to the parameter. */ template void SetParam( @@ -65,7 +65,7 @@ void SetParam( // We're setting the string filename. typedef std::tuple::type> TupleType; TupleType& tuple = *boost::any_cast(&d.value); - std::get<1>(tuple) = boost::any_cast(value); + std::get<0>(std::get<1>(tuple)) = boost::any_cast(value); } /** From e1713a4dbc5d233a0b16df173f39e8cbcfec1f66 Mon Sep 17 00:00:00 2001 From: NippunSharma Date: Wed, 5 May 2021 23:21:37 +0530 Subject: [PATCH 06/11] fixing tests 3 --- src/mlpack/tests/cli_binding_test.cpp | 65 ++++++++++++++++++--------- 1 file changed, 45 insertions(+), 20 deletions(-) diff --git a/src/mlpack/tests/cli_binding_test.cpp b/src/mlpack/tests/cli_binding_test.cpp index 391a0bfe1a..76cf6a652d 100644 --- a/src/mlpack/tests/cli_binding_test.cpp +++ b/src/mlpack/tests/cli_binding_test.cpp @@ -82,7 +82,9 @@ TEST_CASE("GetParamLoadedMatTest", "[CLIOptionTest]") // Create value. string filename = "hello.csv"; arma::mat m(5, 5, arma::fill::ones); - tuple tuple = make_tuple(m, filename); + typedef std::tuple TupleType; + TupleType testTuple{filename, 0, 0}; + tuple tuple = make_tuple(m, testTuple); d.value = boost::any(tuple); // Mark it as already loaded. d.input = true; @@ -106,7 +108,9 @@ TEST_CASE("GetParamUnloadedMatTest", "[CLIOptionTest]") arma::mat test(5, 5, arma::fill::ones); data::Save("test.csv", test); arma::mat m; - tuple tuple = make_tuple(m, filename); + typedef tuple TupleType; + TupleType testTuple{filename, 0, 0}; + tuple tuple = make_tuple(m, testTuple); d.value = boost::any(tuple); // Make sure it is not loaded yet. d.input = true; @@ -132,7 +136,9 @@ TEST_CASE("GetParamUmatTest", "[CLIOptionTest]") // Create value. string filename = "hello.csv"; arma::Mat m(5, 5, arma::fill::ones); - tuple, string> tuple = make_tuple(m, filename); + typedef tuple TupleType; + TupleType testTuple{filename, 0, 0}; + tuple, TupleType> tuple = make_tuple(m, testTuple); d.value = boost::any(tuple); // Mark it as already loaded. d.input = true; @@ -157,7 +163,9 @@ TEST_CASE("GetParamUnloadedUmatTest", "[CLIOptionTest]") arma::Mat test(5, 5, arma::fill::ones); data::Save("test.csv", test); arma::Mat m; - tuple, string> tuple = make_tuple(m, filename); + typedef tuple TupleType; + TupleType testTuple{filename, 0, 0}; + tuple, TupleType> tuple = make_tuple(m, testTuple); d.value = boost::any(tuple); // Make sure it is not loaded yet. d.input = true; @@ -199,8 +207,10 @@ TEST_CASE("GetParamDatasetInfoMatTest", "[CLIOptionTest]") data::DatasetInfo dd; arma::mat m; + typedef tuple TupleType; + TupleType testTuple{filename, 0, 0}; tuple tuple1 = make_tuple(dd, m); - tuple tuple2 = make_tuple(tuple1, filename); + tuple tuple2 = make_tuple(tuple1, testTuple); d.value = boost::any(tuple2); // Make sure it is not loaded yet. @@ -274,7 +284,9 @@ TEST_CASE("RawParamMatTest", "[CLIOptionTest]") // Create value. string filename = "hello.csv"; arma::mat m(5, 5, arma::fill::ones); - tuple tuple = make_tuple(m, filename); + typedef tuple TupleType; + TupleType testTuple{filename, 0, 0}; + tuple tuple = make_tuple(m, testTuple); d.value = boost::any(tuple); d.input = true; d.loaded = false; @@ -322,9 +334,10 @@ TEST_CASE("GetRawParamDatasetInfoTest", "[CLIOptionTest]") // Create tuples. data::DatasetInfo dd(3); arma::mat m(3, 3, arma::fill::randu); - + typedef tuple TupleType; + TupleType testTuple{filename, 0, 0}; tuple tuple1 = make_tuple(dd, m); - tuple tuple2 = make_tuple(tuple1, filename); + tuple tuple2 = make_tuple(tuple1, testTuple); d.value = boost::any(tuple2); // Make sure it is not loaded yet. @@ -350,7 +363,9 @@ TEST_CASE("OutputParamMatTest", "[CLIOptionTest]") // Create value. string filename = "test.csv"; arma::mat m(3, 3, arma::fill::randu); - tuple t = make_tuple(m, filename); + typedef tuple TupleType; + TupleType testTuple{filename, 0, 0}; + tuple t = make_tuple(m, testTuple); d.value = boost::any(t); d.input = false; @@ -376,7 +391,9 @@ TEST_CASE("OutputParamUmatTest", "[CLIOptionTest]") // Create value. string filename = "test.csv"; arma::Mat m(3, 3, arma::fill::randu); - tuple, string> t = make_tuple(m, filename); + typedef tuple TupleType; + TupleType testTuple{filename, 0, 0}; + tuple, TupleType> t = make_tuple(m, testTuple); d.value = boost::any(t); d.input = false; @@ -467,7 +484,9 @@ TEST_CASE("SetParamMatrixTest", "[CLIOptionTest]") // Create initial value. string filename = "hello.csv"; arma::mat m(5, 5, arma::fill::randu); - d.value = boost::any(make_tuple(m, filename)); + typedef tuple TupleType; + TupleType testTuple{filename, 0, 0}; + d.value = boost::any(make_tuple(m, testTuple)); // Get a new string. string newFilename = "new.csv"; @@ -477,9 +496,9 @@ TEST_CASE("SetParamMatrixTest", "[CLIOptionTest]") (void*) NULL); // Make sure the change went through. - tuple& t = - *boost::any_cast>(&d.value); - REQUIRE(get<1>(t) == "new.csv"); + tuple& t = + *boost::any_cast>(&d.value); + REQUIRE(get<0>(get<1>(t)) == "new.csv"); } // Test that calling SetParam on a model sets the string correctly. @@ -517,8 +536,10 @@ TEST_CASE("SetParamDatasetInfoMatTest", "[CLIOptionTest]") string filename = "test.csv"; arma::mat m(3, 3, arma::fill::randu); DatasetInfo di(3); + typedef tuple TupleType; + TupleType testTuple{filename, 0, 0}; tuple t1 = make_tuple(di, m); - tuple, string> t2 = make_tuple(t1, filename); + tuple, TupleType> t2 = make_tuple(t1, testTuple); d.value = boost::any(t2); d.noTranspose = false; @@ -530,10 +551,10 @@ TEST_CASE("SetParamDatasetInfoMatTest", "[CLIOptionTest]") (const void*) &a2, (void*) NULL); // Check that the name is right. - tuple, string>& t3 = - *boost::any_cast, string>>(&d.value); + tuple, TupleType>& t3 = + *boost::any_cast, TupleType>>(&d.value); - REQUIRE(get<1>(t3) == "new_filename.csv"); + REQUIRE(get<0>(get<1>(t3)) == "new_filename.csv"); } // Test that GetAllocatedMemory() will properly return NULL for a non-model @@ -556,7 +577,9 @@ TEST_CASE("GetAllocatedMemoryNonModelTest", "[CLIOptionTest]") // Also test with a matrix type. arma::mat test(10, 10, arma::fill::ones); string filename = "test.csv"; - tuple t = make_tuple(test, filename); + typedef tuple TupleType; + TupleType testTuple{filename, 0, 0}; + tuple t = make_tuple(test, testTuple); d.value = boost::any(t); result = (void*) 1; @@ -602,7 +625,9 @@ TEST_CASE("DeleteAllocatedMemoryNonModelTest", "[CLIOptionTest]") arma::mat test(10, 10, arma::fill::ones); string filename = "test.csv"; - tuple t = make_tuple(test, filename); + typedef tuple TupleType; + TupleType testTuple{filename, 0, 0}; + tuple t = make_tuple(test, testTuple); d.value = boost::any(t); DeleteAllocatedMemory((util::ParamData&) d, From 9930308e007d6ff90c7d8106277bf4e39bf07f18 Mon Sep 17 00:00:00 2001 From: Nippun Sharma <53967069+NippunSharma@users.noreply.github.com> Date: Sun, 9 May 2021 21:05:12 +0530 Subject: [PATCH 07/11] Update src/mlpack/bindings/cli/get_printable_param_impl.hpp Co-authored-by: Ryan Curtin --- src/mlpack/bindings/cli/get_printable_param_impl.hpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/mlpack/bindings/cli/get_printable_param_impl.hpp b/src/mlpack/bindings/cli/get_printable_param_impl.hpp index 8a3cb211cb..9898c49ee6 100644 --- a/src/mlpack/bindings/cli/get_printable_param_impl.hpp +++ b/src/mlpack/bindings/cli/get_printable_param_impl.hpp @@ -89,8 +89,9 @@ std::string GetPrintableParam( { // Make sure the matrix is loaded so that we can print its size. GetParam(const_cast(data)); - std::string matDescription = std::to_string(std::get<1>(std::get<1>(*tuple))) + "x"; - matDescription += std::to_string(std::get<2>(std::get<1>(*tuple))) + " matrix"; + std::string matDescription = + std::to_string(std::get<2>(std::get<1>(*tuple))) + "x" + + std::to_string(std::get<1>(std::get<1>(*tuple))) + " matrix"; oss << " (" << matDescription << ")"; } From 0a22827b41c1ed784dc817368293d1009415fa5d Mon Sep 17 00:00:00 2001 From: Nippun Sharma <53967069+NippunSharma@users.noreply.github.com> Date: Sun, 9 May 2021 21:05:20 +0530 Subject: [PATCH 08/11] Update src/mlpack/bindings/cli/in_place_copy.hpp Co-authored-by: Ryan Curtin --- src/mlpack/bindings/cli/in_place_copy.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mlpack/bindings/cli/in_place_copy.hpp b/src/mlpack/bindings/cli/in_place_copy.hpp index e2094e53d4..4112c8a5a5 100644 --- a/src/mlpack/bindings/cli/in_place_copy.hpp +++ b/src/mlpack/bindings/cli/in_place_copy.hpp @@ -41,7 +41,7 @@ void InPlaceCopyInternal( /** * Modify the filename for any type that needs to be loaded from disk to match - * the filename of the input parameter. For matrix/datasetinfo parameter. + * the filename of the input parameter, for a matrix/DatasetInfo parameter. * * @param d ParamData object we want to make into an in-place copy. * @param input ParamData object whose filename we should copy. From 92f568f3b785562c0b809c3138aa1d7e25b6fa95 Mon Sep 17 00:00:00 2001 From: Nippun Sharma <53967069+NippunSharma@users.noreply.github.com> Date: Sun, 9 May 2021 21:05:28 +0530 Subject: [PATCH 09/11] Update src/mlpack/bindings/cli/in_place_copy.hpp Co-authored-by: Ryan Curtin --- src/mlpack/bindings/cli/in_place_copy.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/mlpack/bindings/cli/in_place_copy.hpp b/src/mlpack/bindings/cli/in_place_copy.hpp index 4112c8a5a5..c8de4c81c8 100644 --- a/src/mlpack/bindings/cli/in_place_copy.hpp +++ b/src/mlpack/bindings/cli/in_place_copy.hpp @@ -53,7 +53,8 @@ void InPlaceCopyInternal( const typename std::enable_if< arma::is_arma_type::value || std::is_same>::value>::type* = 0) + std::tuple>::value + >::type* = 0) { // Make the output filename the same as the input filename. typedef std::tuple::type> TupleType; From ebc61b761533d13d9c48552f083df7712c5e585c Mon Sep 17 00:00:00 2001 From: Nippun Sharma <53967069+NippunSharma@users.noreply.github.com> Date: Sun, 9 May 2021 21:05:34 +0530 Subject: [PATCH 10/11] Update src/mlpack/bindings/cli/in_place_copy.hpp Co-authored-by: Ryan Curtin --- src/mlpack/bindings/cli/in_place_copy.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mlpack/bindings/cli/in_place_copy.hpp b/src/mlpack/bindings/cli/in_place_copy.hpp index c8de4c81c8..d3ed1c9521 100644 --- a/src/mlpack/bindings/cli/in_place_copy.hpp +++ b/src/mlpack/bindings/cli/in_place_copy.hpp @@ -67,7 +67,7 @@ void InPlaceCopyInternal( /** * Modify the filename for any type that needs to be loaded from disk to match - * the filename of the input parameter. For Serializable object. + * the filename of the input parameter. For serializable objects. * * @param d ParamData object we want to make into an in-place copy. * @param input ParamData object whose filename we should copy. From 7b7119fd8b6079c12cca1eba429a702b6bc2fb39 Mon Sep 17 00:00:00 2001 From: Nippun Sharma <53967069+NippunSharma@users.noreply.github.com> Date: Sun, 9 May 2021 23:27:49 +0530 Subject: [PATCH 11/11] updated UnmappedParamTest --- src/mlpack/tests/io_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mlpack/tests/io_test.cpp b/src/mlpack/tests/io_test.cpp index 26319a8d79..725ea25222 100644 --- a/src/mlpack/tests/io_test.cpp +++ b/src/mlpack/tests/io_test.cpp @@ -974,7 +974,7 @@ TEST_CASE_METHOD(IOTestDestroyer, "UnmappedParamTest", // Now check that we can get unmapped parameters. REQUIRE(IO::GetPrintableParam("matrix") == - "'test_data_3_1000.csv' (3x1000 matrix)"); + "'test_data_3_1000.csv' (1000x3 matrix)"); // This will have size 0x0 since it's an output parameter, and it hasn't been // set since ParseCommandLine() was called. REQUIRE(IO::GetPrintableParam("matrix2") ==