Refactoring according to #2558.
This commit is contained 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}");
|
||||
}
|
||||
|
||||
@@ -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<string, util::ParamData>& parameters = IO::Parameters();
|
||||
typedef map<string, util::ParamData>::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(";
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -348,12 +348,6 @@ using Option = mlpack::bindings::r::ROption<T>;
|
||||
static const std::string testName = "";
|
||||
#include <mlpack/core/util/param.hpp>
|
||||
|
||||
#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");
|
||||
|
||||
|
||||
@@ -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 " +
|
||||
|
||||
@@ -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 " +
|
||||
|
||||
Reference in New Issue
Block a user