mlpack 3.4.2
julia_option.hpp
Go to the documentation of this file.
1
12#ifndef MLPACK_BINDINGS_JULIA_JULIA_OPTION_HPP
13#define MLPACK_BINDINGS_JULIA_JULIA_OPTION_HPP
14
16#include "get_param.hpp"
18#include "print_param_defn.hpp"
19#include "print_input_param.hpp"
22#include "print_doc.hpp"
24#include "default_param.hpp"
25
26namespace mlpack {
27namespace bindings {
28namespace julia {
29
30// Defined in mlpack_main.hpp.
31extern std::string programName;
32
36template<typename T>
38{
39 public:
45 JuliaOption(const T defaultValue,
46 const std::string& identifier,
47 const std::string& description,
48 const std::string& alias,
49 const std::string& cppName,
50 const bool required = false,
51 const bool input = true,
52 const bool noTranspose = false,
53 const std::string& /* testName */ = "")
54 {
55 // Create the ParamData object to give to IO.
56 util::ParamData data;
57
58 data.desc = description;
59 data.name = identifier;
60 data.tname = TYPENAME(T);
61 data.alias = alias[0];
62 data.wasPassed = false;
63 data.noTranspose = noTranspose;
64 data.required = required;
65 data.input = input;
66 data.loaded = false;
67
68 // Only "verbose" will be persistent.
69 if (identifier == "verbose")
70 data.persistent = true;
71 else
72 data.persistent = false;
73 data.cppType = cppName;
74
75 // Every parameter we'll get from Julia will have the correct type.
76 data.value = boost::any(defaultValue);
77
78 // Restore the parameters for this program.
79 if (identifier != "verbose")
81
82 // Set the function pointers that we'll need. All of these function
83 // pointers will be used by both the program that generates the pyx, and
84 // also the binding itself. (The binding itself will only use GetParam,
85 // GetPrintableParam, and GetRawParam.)
86 IO::GetSingleton().functionMap[data.tname]["GetParam"] = &GetParam<T>;
87 IO::GetSingleton().functionMap[data.tname]["GetPrintableParam"] =
88 &GetPrintableParam<T>;
89
90 // These are used by the jl generator.
91 IO::GetSingleton().functionMap[data.tname]["PrintParamDefn"] =
92 &PrintParamDefn<T>;
93 IO::GetSingleton().functionMap[data.tname]["PrintInputParam"] =
94 &PrintInputParam<T>;
95 IO::GetSingleton().functionMap[data.tname]["PrintOutputProcessing"] =
96 &PrintOutputProcessing<T>;
97 IO::GetSingleton().functionMap[data.tname]["PrintInputProcessing"] =
98 &PrintInputProcessing<T>;
99 IO::GetSingleton().functionMap[data.tname]["PrintDoc"] = &PrintDoc<T>;
100 IO::GetSingleton().functionMap[data.tname]["PrintModelTypeImport"] =
101 &PrintModelTypeImport<T>;
102
103 // This is needed for the Markdown binding output.
104 IO::GetSingleton().functionMap[data.tname]["DefaultParam"] =
105 &DefaultParam<T>;
106
107 // Add the ParamData object, then store. This is necessary because we may
108 // import more than one .so that uses IO, so we have to keep the options
109 // separate. programName is a global variable from mlpack_main.hpp.
110 IO::Add(std::move(data));
111 if (identifier != "verbose")
114 }
115};
116
117} // namespace julia
118} // namespace bindings
119} // namespace mlpack
120
121#endif
FunctionMapType functionMap
Definition: io.hpp:299
static IO & GetSingleton()
Retrieve the singleton.
static void ClearSettings()
Clear all of the settings, removing all parameters and function mappings.
static void RestoreSettings(const std::string &name, const bool fatal=true)
Restore all of the parameters and function mappings of the given name, if they exist.
static void StoreSettings(const std::string &name)
Take all parameters and function mappings and store them, under the given name.
static void Add(util::ParamData &&d)
Adds a parameter to the hierarchy; use the PARAM_*() macros instead of this (i.e.
JuliaOption(const T defaultValue, const std::string &identifier, const std::string &description, const std::string &alias, const std::string &cppName, const bool required=false, const bool input=true, const bool noTranspose=false, const std::string &="")
Construct a JuliaOption object.
julia
Definition: CMakeLists.txt:6
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
#define TYPENAME(x)
The TYPENAME macro is used internally to convert a type into a string.
Definition: param_data.hpp:22
This structure holds all of the information about a single parameter, including its value (which is s...
Definition: param_data.hpp:53
bool noTranspose
True if this is a matrix that should not be transposed.
Definition: param_data.hpp:69
char alias
Alias for this parameter.
Definition: param_data.hpp:63
std::string desc
Description of this parameter, if any.
Definition: param_data.hpp:58
bool wasPassed
True if the option was passed to the program.
Definition: param_data.hpp:66
boost::any value
The actual value that is held.
Definition: param_data.hpp:82
std::string tname
Type information of this parameter.
Definition: param_data.hpp:61
bool required
True if this option is required.
Definition: param_data.hpp:71
bool input
True if this option is an input option (otherwise, it is output).
Definition: param_data.hpp:73
bool loaded
If this is an input parameter that needs extra loading, this indicates whether or not it has been loa...
Definition: param_data.hpp:76
std::string name
Name of this parameter.
Definition: param_data.hpp:56
std::string cppType
The true name of the type, as it would be written in C++.
Definition: param_data.hpp:84
bool persistent
If this should be preserved across different settings (i.e.
Definition: param_data.hpp:79