diff --git a/src/mlpack/bindings/R/generate_R.cpp.in b/src/mlpack/bindings/R/generate_R.cpp.in index 8b96f9e5ae..632fe554bb 100644 --- a/src/mlpack/bindings/R/generate_R.cpp.in +++ b/src/mlpack/bindings/R/generate_R.cpp.in @@ -35,5 +35,5 @@ int main(int /* argc */, char** /* argv */) // programName is defined in mlpack_main.hpp. IO::RestoreSettings(IO::ProgramName()); - PrintR(*IO::GetSingleton().doc, "${NAME}"); + PrintR(IO::GetSingleton().doc, "${NAME}"); } diff --git a/src/mlpack/bindings/R/print_R.cpp b/src/mlpack/bindings/R/print_R.cpp index 421a9e8b51..ff9e8dcc31 100644 --- a/src/mlpack/bindings/R/print_R.cpp +++ b/src/mlpack/bindings/R/print_R.cpp @@ -24,12 +24,15 @@ namespace r { /** * Print the code for a .R binding for an mlpack program to stdout. + * + * @param doc Documentation for the binding. + * @param functionName Name of the function (i.e. "pca"). */ -void PrintR(const util::ProgramDoc& programInfo, +void PrintR(const util::BindingDetails& doc, const string& functionName) { // Restore parameters. - IO::RestoreSettings(programInfo.programName); + IO::RestoreSettings(doc.programName); map& parameters = IO::Parameters(); typedef map::iterator ParamIter; @@ -65,13 +68,13 @@ void PrintR(const util::ProgramDoc& programInfo, // Print the documentation. // Print programName as @title. cout << "#' @title "; - cout << util::HyphenateString(programInfo.programName, "#' ") << endl; + cout << util::HyphenateString(doc.programName, "#' ") << endl; cout << "#'" << endl; // Next print the short description as @description. cout << "#' @description" << endl; cout << "#' "; - cout << util::HyphenateString(programInfo.shortDocumentation, "#' ") << endl; + cout << util::HyphenateString(doc.shortDescription, "#' ") << endl; // Next, print information on the input options. cout << "#'" << endl; @@ -106,7 +109,7 @@ void PrintR(const util::ProgramDoc& programInfo, // Next print the long description as @details. cout << "#' @details" << endl; cout << "#' "; - cout << util::HyphenateString(programInfo.documentation(), "#' ") << endl; + cout << util::HyphenateString(doc.longDescription(), "#' ") << endl; cout << "#'" << endl; cout << "#' @author" << endl; cout << "#' mlpack developers" << endl; @@ -114,36 +117,39 @@ void PrintR(const util::ProgramDoc& programInfo, // Next print the example as @examples. cout << "#' @export" << endl; - if (programInfo.example().size() != 0) + if (doc.example.size() != 0) cout << "#' @examples" << endl; - - const std::string str = programInfo.example(); - size_t pos = 0; - while (pos < str.length()) + for (size_t j = 0; j < doc.example.size(); ++j) { - size_t splitpos = 0; - // Find where example starts. - splitpos = str.find("\n\\donttest{", pos) - 1; - // If no example left, then print all the comments that are left. - if (splitpos == std::string::npos || splitpos > str.length()) + const std::string str = doc.example[j](); + size_t pos = 0; + while (pos < str.length()) { - splitpos = str.length(); - cout << util::HyphenateString(str.substr(pos, (splitpos - pos)), "#' # "); - break; + size_t splitpos = 0; + // Find where example starts. + splitpos = str.find("\n\\donttest{", pos) - 1; + // If no example left, then print all the comments that are left. + if (splitpos == std::string::npos || splitpos > str.length()) + { + splitpos = str.length(); + cout << util::HyphenateString(str.substr(pos, (splitpos - pos)), + "#' # "); + break; + } + if (splitpos != 0 && pos == 0) + cout << "#' # "; + // Print comments in the "example", if there is available. + cout << util::HyphenateString(str.substr(pos, (splitpos - pos)), + "#' # ", true); + // Find where example ends. + pos = str.find("\n}", pos) + 3; + // Here length of example might be less 80, we must handle this carefully. + // Print example in the "example". + cout << util::HyphenateString(str.substr(splitpos, (pos - splitpos)), + "#' ", true); } - if (splitpos != 0 && pos == 0) - cout << "#' # "; - // Print comments in the "example", if there is available. - cout << util::HyphenateString(str.substr(pos, (splitpos - pos)), - "#' # ", true); - // Find where example ends. - pos = str.find("\n}", pos) + 3; - // Here length of example might be less 80, we must handle this carefully. - // Print example in the "example". - cout << util::HyphenateString(str.substr(splitpos, (pos - splitpos)), - "#' ", true); + cout << endl; } - cout << endl; // Print the definition. cout << functionName << " <- function("; diff --git a/src/mlpack/bindings/R/print_R.hpp b/src/mlpack/bindings/R/print_R.hpp index 3bdbb88240..76689420cd 100644 --- a/src/mlpack/bindings/R/print_R.hpp +++ b/src/mlpack/bindings/R/print_R.hpp @@ -20,8 +20,11 @@ namespace r { /** * Print the code for a .R binding for an mlpack program to stdout. + * + * @param doc Documentation for the binding. + * @param functionName Name of the function (i.e. "pca"). */ -void PrintR(const util::ProgramDoc& programInfo, +void PrintR(const util::BindingDetails& doc, const std::string& functionName); } // namespace r diff --git a/src/mlpack/bindings/R/tests/test_r_binding_main.cpp b/src/mlpack/bindings/R/tests/test_r_binding_main.cpp index ecaf9f3dd9..8bd78992b6 100644 --- a/src/mlpack/bindings/R/tests/test_r_binding_main.cpp +++ b/src/mlpack/bindings/R/tests/test_r_binding_main.cpp @@ -18,11 +18,18 @@ using namespace std; using namespace mlpack; using namespace mlpack::kernel; -PROGRAM_INFO("R binding test", - "A simple program to test R binding functionality.", +// Program Name. +BINDING_NAME("R binding test"); + +// Short description. +BINDING_SHORT_DESC( + "A simple program to test R binding functionality."); + +// Long description. +BINDING_LONG_DESC( "A simple program to test R binding functionality. You can build " "mlpack with the BUILD_TESTS option set to off, and this binding will " - "no longer be built.", ""); + "no longer be built."); PARAM_STRING_IN_REQ("string_in", "Input string, must be 'hello'.", "s"); PARAM_INT_IN_REQ("int_in", "Input int, must be 12.", "i"); diff --git a/src/mlpack/bindings/go/tests/test_go_binding_main.cpp b/src/mlpack/bindings/go/tests/test_go_binding_main.cpp index 69e78af4d0..3aeb255906 100644 --- a/src/mlpack/bindings/go/tests/test_go_binding_main.cpp +++ b/src/mlpack/bindings/go/tests/test_go_binding_main.cpp @@ -29,7 +29,7 @@ BINDING_SHORT_DESC( BINDING_LONG_DESC( "A simple program to test Go binding functionality. You can build " "mlpack with the BUILD_TESTS option set to off, and this binding will " - "no longer be built.", ""); + "no longer be built."); PARAM_STRING_IN_REQ("string_in", "Input string, must be 'hello'.", "s"); PARAM_INT_IN_REQ("int_in", "Input int, must be 12.", "i"); diff --git a/src/mlpack/bindings/julia/tests/test_julia_binding_main.cpp b/src/mlpack/bindings/julia/tests/test_julia_binding_main.cpp index d5ea842684..5ba385cf2b 100644 --- a/src/mlpack/bindings/julia/tests/test_julia_binding_main.cpp +++ b/src/mlpack/bindings/julia/tests/test_julia_binding_main.cpp @@ -29,7 +29,7 @@ BINDING_SHORT_DESC( BINDING_LONG_DESC( "A simple program to test Julia binding functionality. You can build " "mlpack with the BUILD_TESTS option set to off, and this binding will " - "no longer be built.", ""); + "no longer be built."); PARAM_STRING_IN_REQ("string_in", "Input string, must be 'hello'.", "s"); PARAM_INT_IN_REQ("int_in", "Input int, must be 12.", "i"); diff --git a/src/mlpack/bindings/python/tests/test_python_binding_main.cpp b/src/mlpack/bindings/python/tests/test_python_binding_main.cpp index c0f1ba61be..ec24202d8e 100644 --- a/src/mlpack/bindings/python/tests/test_python_binding_main.cpp +++ b/src/mlpack/bindings/python/tests/test_python_binding_main.cpp @@ -29,7 +29,7 @@ BINDING_SHORT_DESC( BINDING_LONG_DESC( "A simple program to test Python binding functionality. You can build " "mlpack with the BUILD_TESTS option set to off, and this binding will " - "no longer be built.", ""); + "no longer be built."); PARAM_STRING_IN_REQ("string_in", "Input string, must be 'hello'.", "s"); PARAM_INT_IN_REQ("int_in", "Input int, must be 12.", "i"); diff --git a/src/mlpack/core/util/mlpack_main.hpp b/src/mlpack/core/util/mlpack_main.hpp index 26fab564de..06f6f8b060 100644 --- a/src/mlpack/core/util/mlpack_main.hpp +++ b/src/mlpack/core/util/mlpack_main.hpp @@ -348,12 +348,6 @@ using Option = mlpack::bindings::r::ROption; static const std::string testName = ""; #include -#undef PROGRAM_INFO -#define PROGRAM_INFO(NAME, SHORT_DESC, DESC, EXAMPLE, ...) static \ - mlpack::util::ProgramDoc \ - io_programdoc_dummy_object = mlpack::util::ProgramDoc(NAME, SHORT_DESC, \ - []() { return DESC; }, []() { return EXAMPLE; }, { __VA_ARGS__ }) - PARAM_FLAG("verbose", "Display informational messages and the full list of " "parameters and timers at the end of execution.", "v"); diff --git a/src/mlpack/methods/local_coordinate_coding/local_coordinate_coding_main.cpp b/src/mlpack/methods/local_coordinate_coding/local_coordinate_coding_main.cpp index 24d2ae837a..b68d91f052 100644 --- a/src/mlpack/methods/local_coordinate_coding/local_coordinate_coding_main.cpp +++ b/src/mlpack/methods/local_coordinate_coding/local_coordinate_coding_main.cpp @@ -49,17 +49,17 @@ BINDING_LONG_DESC( "\n\n" "The coding is found with an algorithm which alternates between a " "dictionary step, which updates the dictionary D, and a coding step, which " - "updates the coding matrix Z."); - -// Example. -BINDING_EXAMPLE( + "updates the coding matrix Z." + "\n\n" "To run this program, the input matrix X must be specified (with -i), along" " with the number of atoms in the dictionary (-k). An initial dictionary " "may also be specified with the " + PRINT_PARAM_STRING("initial_dictionary") + " parameter. The l1-norm " "regularization parameter is specified with the " + - PRINT_PARAM_STRING("lambda") + " parameter.", - // Example. + PRINT_PARAM_STRING("lambda") + " parameter."); + +// Example. +BINDING_EXAMPLE( "For example, to run LCC on " "the dataset " + PRINT_DATASET("data") + " using 200 atoms and an " "l1-regularization parameter of 0.1, saving the dictionary " + diff --git a/src/mlpack/methods/perceptron/perceptron_main.cpp b/src/mlpack/methods/perceptron/perceptron_main.cpp index 15ae762bc8..1a842baef3 100644 --- a/src/mlpack/methods/perceptron/perceptron_main.cpp +++ b/src/mlpack/methods/perceptron/perceptron_main.cpp @@ -62,16 +62,16 @@ BINDING_LONG_DESC( "." "\n" "Use " + PRINT_PARAM_STRING("predictions") + " instead of " + - PRINT_PARAM_STRING("output") + '.', - // Example. + PRINT_PARAM_STRING("output") + '.'); + +// Example. +BINDING_EXAMPLE( "The training data given with the " + PRINT_PARAM_STRING("training") + " option may have class labels as its last dimension (so, if the training " "data is in CSV format, labels should be the last column). Alternately, " "the " + PRINT_PARAM_STRING("labels") + " parameter may be used to specify " - "a separate matrix of labels."); - -// Example. -BINDING_EXAMPLE( + "a separate matrix of labels." + "\n\n" "All these options make it easy to train a perceptron, and then re-use that" " perceptron for later classification. The invocation below trains a " "perceptron on " + PRINT_DATASET("training_data") + " with labels " +