12 #ifndef MLPACK_CORE_UTIL_PARAM_CHECKS_IMPL_HPP 13 #define MLPACK_CORE_UTIL_PARAM_CHECKS_IMPL_HPP 22 const std::vector<std::string>& constraints,
24 const std::string& errorMessage,
27 if (BINDING_IGNORE_CHECK(constraints))
31 for (
size_t i = 0; i < constraints.size(); ++i)
42 if (constraints.size() == 2)
44 stream <<
"Can only pass one of " << PRINT_PARAM_STRING(constraints[0])
45 <<
" or " << PRINT_PARAM_STRING(constraints[1]);
49 stream <<
"Can only pass one of ";
50 for (
size_t i = 0 ; i < constraints.size() - 1; ++i)
51 stream << PRINT_PARAM_STRING(constraints[i]) <<
", ";
53 << PRINT_PARAM_STRING(constraints[constraints.size() - 1]);
57 if (!errorMessage.empty())
58 stream <<
"; " << errorMessage;
59 stream <<
"!" << std::endl;
61 else if (
set == 0 && !allowNone)
63 stream << (fatal ?
"Must " :
"Should ");
67 if (constraints.size() == 1)
69 stream <<
"specify " << PRINT_PARAM_STRING(constraints[0]);
71 else if (constraints.size() == 2)
73 stream <<
"specify one of " << PRINT_PARAM_STRING(constraints[0])
74 <<
" or " << PRINT_PARAM_STRING(constraints[1]);
78 stream <<
"specify one of ";
79 for (
size_t i = 0; i < constraints.size() - 1; ++i)
80 stream << PRINT_PARAM_STRING(constraints[i]) <<
", ";
82 << PRINT_PARAM_STRING(constraints[constraints.size() - 1]);
86 if (!errorMessage.empty())
87 stream <<
"; " << errorMessage;
88 stream <<
"!" << std::endl;
93 const std::vector<std::string>& constraints,
95 const std::string& errorMessage)
97 if (BINDING_IGNORE_CHECK(constraints))
101 for (
size_t i = 0; i < constraints.size(); ++i)
110 stream << (fatal ?
"Must " :
"Should ");
111 if (constraints.size() == 1)
114 stream <<
"pass " << PRINT_PARAM_STRING(constraints[0]);
116 else if (constraints.size() == 2)
118 stream <<
"pass either " << PRINT_PARAM_STRING(constraints[0])
119 <<
" or " << PRINT_PARAM_STRING(constraints[1]) <<
" or both";
123 stream <<
"pass one of ";
124 for (
size_t i = 0; i < constraints.size() - 1; ++i)
125 stream << PRINT_PARAM_STRING(constraints[i]) <<
", ";
127 << PRINT_PARAM_STRING(constraints[constraints.size() - 1]);
131 if (!errorMessage.empty())
132 stream <<
"; " << errorMessage <<
"!" << std::endl;
134 stream <<
"!" << std::endl;
139 const std::vector<std::string>& constraints,
141 const std::string& errorMessage)
143 if (BINDING_IGNORE_CHECK(constraints))
147 for (
size_t i = 0; i < constraints.size(); ++i)
153 if (
set != 0 &&
set < constraints.size())
156 stream << (fatal ?
"Must " :
"Should ");
157 if (constraints.size() == 2)
159 stream <<
"pass none or both of " << PRINT_PARAM_STRING(constraints[0])
160 <<
" and " << PRINT_PARAM_STRING(constraints[1]);
165 stream <<
"pass none or all of ";
166 for (
size_t i = 0; i < constraints.size() - 1; ++i)
167 stream << PRINT_PARAM_STRING(constraints[i]) <<
", ";
169 << PRINT_PARAM_STRING(constraints[constraints.size() - 1]);
173 if (!errorMessage.empty())
174 stream <<
"; " << errorMessage <<
"!" << std::endl;
176 stream <<
"!" << std::endl;
182 const std::vector<T>&
set,
184 const std::string& errorMessage)
186 if (BINDING_IGNORE_CHECK(name))
189 if (std::find(
set.begin(),
set.end(), IO::GetParam<T>(name)) ==
set.end())
193 stream <<
"Invalid value of " << PRINT_PARAM_STRING(name) <<
" specified (" 194 << PRINT_PARAM_VALUE(IO::GetParam<T>(name),
true) <<
"); ";
195 if (!errorMessage.empty())
196 stream << errorMessage <<
"; ";
197 stream <<
"must be one of ";
198 for (
size_t i = 0; i <
set.size() - 1; ++i)
199 stream << PRINT_PARAM_VALUE(
set[i],
true) <<
", ";
200 stream <<
"or " << PRINT_PARAM_VALUE(
set[
set.size() - 1],
true) <<
"!" 207 const std::function<
bool(T)>& conditional,
209 const std::string& errorMessage)
211 if (BINDING_IGNORE_CHECK(name))
215 bool condition = conditional(IO::GetParam<T>(name));
220 stream <<
"Invalid value of " << PRINT_PARAM_STRING(name) <<
" specified (" 221 << PRINT_PARAM_VALUE(IO::GetParam<T>(name),
false) <<
"); " 222 << errorMessage <<
"!" << std::endl;
227 const std::vector<std::pair<std::string, bool>>& constraints,
228 const std::string& paramName)
230 if (BINDING_IGNORE_CHECK(paramName))
234 bool condition =
true;
235 for (
size_t i = 0; i < constraints.size(); ++i)
237 if (
IO::HasParam(constraints[i].first) != constraints[i].second)
250 Log::Warn << PRINT_PARAM_STRING(paramName) <<
" ignored because ";
251 if (constraints.size() == 1)
253 Log::Warn << PRINT_PARAM_STRING(constraints[0].first)
254 << ((constraints[0].second) ?
" is " :
" is not ")
255 <<
"specified!" << std::endl;
257 else if (constraints.size() == 2)
259 if (constraints[0].second == constraints[1].second)
261 Log::Warn << ((constraints[0].second) ?
"both " :
"neither ")
262 << PRINT_PARAM_STRING(constraints[0].first)
263 << ((constraints[0].second) ?
"or " :
"nor ")
264 << PRINT_PARAM_STRING(constraints[1].first)
265 <<
" are specified!" << std::endl;
269 Log::Warn << PRINT_PARAM_STRING(constraints[0].first)
270 << ((constraints[0].second) ?
" is " :
" is not ")
272 << ((constraints[1].second) ?
" is " :
" is not ")
273 <<
"specified!" << std::endl;
279 for (
size_t i = 0; i < constraints.size(); ++i)
281 Log::Warn << PRINT_PARAM_STRING(constraints[i].first)
282 << ((constraints[i].second) ?
" is " :
" is not ")
283 << ((i == constraints.size() - 1) ?
"specified!" 292 const std::string& reason)
297 Log::Warn << PRINT_PARAM_STRING(paramName) <<
" ignored because " 298 << reason <<
"!" << std::endl;
static bool HasParam(const std::string &identifier)
See if the specified flag was found while parsing.
Definition: io.cpp:85
void RequireParamInSet(const std::string ¶mName, const std::vector< T > &set, const bool fatal, const std::string &errorMessage)
Require that a given parameter is in a set of allowable parameters.
Definition: param_checks_impl.hpp:181
void RequireAtLeastOnePassed(const std::vector< std::string > &constraints, const bool fatal=true, const std::string &customErrorMessage="")
Require that at least one of the given parameters in the constraints set was passed to the IO object;...
Definition: param_checks_impl.hpp:92
static MLPACK_EXPORT util::PrefixedOutStream Fatal
Prints fatal messages prefixed with [FATAL], then terminates the program.
Definition: log.hpp:90
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
void RequireOnlyOnePassed(const std::vector< std::string > &constraints, const bool fatal=true, const std::string &customErrorMessage="", const bool allowNone=false)
Require that only one of the given parameters in the constraints set was passed to the IO object; oth...
Definition: param_checks_impl.hpp:21
void RequireNoneOrAllPassed(const std::vector< std::string > &constraints, const bool fatal=true, const std::string &customErrorMessage="")
Require that either none or all of the given parameters in the constraints set were passed to the IO ...
Definition: param_checks_impl.hpp:138
static MLPACK_EXPORT util::PrefixedOutStream Warn
Prints warning messages prefixed with [WARN ].
Definition: log.hpp:87
void RequireParamValue(const std::string ¶mName, const std::function< bool(T)> &conditional, const bool fatal, const std::string &errorMessage)
Require that a given parameter satisfies the given conditional function.
Definition: param_checks_impl.hpp:206
void ReportIgnoredParam(const std::vector< std::pair< std::string, bool >> &constraints, const std::string ¶mName)
Report that a parameter is ignored, if each of the constraints given are satisfied.
Definition: param_checks_impl.hpp:226
Allows us to output to an ostream with a prefix at the beginning of each line, in the same way we wou...
Definition: prefixedoutstream.hpp:46