test_option.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_CORE_BINDINGS_TESTS_TEST_OPTION_HPP
14 #define MLPACK_CORE_BINDINGS_TESTS_TEST_OPTION_HPP
15 
16 #include <string>
17 
18 #include <mlpack/core/util/io.hpp>
19 #include "get_printable_param.hpp"
20 #include "get_param.hpp"
21 #include "get_allocated_memory.hpp"
23 #include "test_function_map.hpp"
24 
25 namespace mlpack {
26 namespace bindings {
27 namespace tests {
28 
29 // Defined in mlpack_main.hpp.
30 extern std::string programName;
31 
40 template<typename N>
42 {
43  public:
62  TestOption(const N defaultValue,
63  const std::string& identifier,
64  const std::string& description,
65  const std::string& alias,
66  const std::string& cppName,
67  const bool required = false,
68  const bool input = true,
69  const bool noTranspose = false,
70  const std::string& bindingName = "")
71  {
72  // Create the ParamData object to give to IO.
74 
75  data.desc = description;
76  data.name = identifier;
77  data.tname = TYPENAME(N);
78  data.alias = alias[0];
79  // If this is an output option, set it as passed.
80  data.wasPassed = !input;
81  data.noTranspose = noTranspose;
82  data.required = required;
83  data.input = input;
84  data.loaded = false;
85  data.cppType = cppName;
86  data.value = ANY(defaultValue);
87 
88  const std::string tname = data.tname;
89 
90  // Set the function pointers in the test function map singleton. We don't
91  // register them with IO::AddFunction(), because these will be restored as
92  // part of the test binding fixture; see
93  // `src/mlpack/tests/main_tests/main_test_fixture.hpp`.
94  TestFunctionMap::RegisterFunction(tname, "GetPrintableParam",
95  &GetPrintableParam<N>);
96  TestFunctionMap::RegisterFunction(tname, "GetParam", &GetParam<N>);
97  TestFunctionMap::RegisterFunction(tname, "GetAllocatedMemory",
98  &GetAllocatedMemory<N>);
99  TestFunctionMap::RegisterFunction(tname, "DeleteAllocatedMemory",
100  &DeleteAllocatedMemory<N>);
101 
102  IO::AddParameter(bindingName, std::move(data));
103  }
104 };
105 
106 } // namespace tests
107 } // namespace bindings
108 } // namespace mlpack
109 
110 #endif
ANY value
The actual value that is held.
Definition: param_data.hpp:78
Linear algebra utility functions, generally performed on matrices or vectors.
bool wasPassed
True if the option was passed to the program.
Definition: param_data.hpp:65
std::string desc
Description of this parameter, if any.
Definition: param_data.hpp:57
#define ANY
Definition: prereqs.hpp:82
bool input
True if this option is an input option (otherwise, it is output).
Definition: param_data.hpp:72
This structure holds all of the information about a single parameter, including its value (which is s...
Definition: param_data.hpp:51
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:75
constexpr auto data(Container const &container) noexcept -> decltype(container.data())
Definition: iterator.hpp:79
#define TYPENAME(x)
The TYPENAME macro is used internally to convert a type into a string.
Definition: param_data.hpp:21
static void RegisterFunction(const std::string &tname, const std::string &functionName, void(*func)(util::ParamData &, const void *, void *))
Register the function func for the given typename tname and the given function name functionName...
char alias
Alias for this parameter.
Definition: param_data.hpp:62
std::string tname
Type information of this parameter.
Definition: param_data.hpp:60
std::string name
Name of this parameter.
Definition: param_data.hpp:55
bool required
True if this option is required.
Definition: param_data.hpp:70
static void AddParameter(const std::string &bindingName, util::ParamData &&d)
Adds a parameter to the hierarchy; use the PARAM_*() macros instead of this (i.e. ...
TestOption(const N 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 &bindingName="")
Construct an Option object.
Definition: test_option.hpp:62
A static object whose constructor registers a parameter with the IO class.
Definition: test_option.hpp:41
std::string cppType
The true name of the type, as it would be written in C++.
Definition: param_data.hpp:80
auto move(Range &&rng, OutputIt &&it) -> enable_if_t< is_range< Range >::value, decay_t< OutputIt > >
Definition: algorithm.hpp:736
bool noTranspose
True if this is a matrix that should not be transposed.
Definition: param_data.hpp:68