13 #ifndef MLPACK_CORE_OPTIMIZERS_FUNCTION_TRAITS_HPP 14 #define MLPACK_CORE_OPTIMIZERS_FUNCTION_TRAITS_HPP 20 namespace optimization {
45 template<
typename FunctionType>
49 template<
typename FunctionType>
51 double(FunctionType::*)(
const arma::mat&)
const;
54 template<
typename FunctionType>
58 template<
typename FunctionType>
59 using GradientForm = void(FunctionType::*)(
const arma::mat&, arma::mat&);
62 template<
typename FunctionType>
64 void(FunctionType::*)(
const arma::mat&, arma::mat&)
const;
67 template<
typename FunctionType>
71 template<
typename FunctionType>
73 double(FunctionType::*)(
const arma::mat&, arma::mat&);
76 template<
typename FunctionType>
78 double(FunctionType::*)(
const arma::mat&, arma::mat&)
const;
81 template<
typename FunctionType>
83 double(*)(
const arma::mat&, arma::mat&);
86 template <
typename FunctionType>
90 template <
typename FunctionType>
94 template<
typename FunctionType>
98 template<
typename FunctionType>
102 template<
typename FunctionType>
106 template<
typename FunctionType>
110 template<
typename FunctionType>
112 const arma::mat&,
const size_t,
const size_t);
115 template<
typename FunctionType>
117 const arma::mat&,
const size_t,
const size_t)
const;
120 template<
typename FunctionType>
122 const arma::mat&,
const size_t,
const size_t);
125 template<
typename FunctionType>
127 const arma::mat&,
const size_t, arma::mat&,
const size_t);
130 template<
typename FunctionType>
132 const arma::mat&,
const size_t, arma::mat&,
const size_t)
const;
135 template<
typename FunctionType>
137 const arma::mat&,
const size_t, arma::mat&,
const size_t);
140 template<
typename FunctionType>
142 const arma::mat&,
const size_t, arma::mat&,
const size_t);
145 template<
typename FunctionType>
147 const arma::mat&,
const size_t, arma::mat&,
const size_t)
const;
150 template<
typename FunctionType>
152 const arma::mat&,
const size_t, arma::mat&,
const size_t);
155 template<
typename FunctionType>
159 template<
typename FunctionType>
163 template<
typename FunctionType>
167 template <
typename FunctionType>
169 const size_t,
const arma::mat&);
172 template<
typename FunctionType>
174 const size_t,
const arma::mat&)
const;
177 template<
typename FunctionType>
181 template <
typename FunctionType>
183 const size_t,
const arma::mat&, arma::mat&);
186 template<
typename FunctionType>
188 const size_t,
const arma::mat&, arma::mat&)
const;
191 template<
typename Class,
typename... Ts>
193 const size_t,
const arma::mat&, arma::mat&);
196 template<
typename FunctionType>
198 const arma::mat&,
const size_t, arma::sp_mat&,
const size_t);
201 template<
typename FunctionType>
203 const arma::mat&,
const size_t, arma::sp_mat&,
const size_t)
const;
206 template<
typename FunctionType>
208 const arma::mat&,
const size_t, arma::sp_mat&,
const size_t);
211 template<
typename FunctionType>
215 template<
typename FunctionType>
219 template<
typename FunctionType>
223 template<
typename FunctionType>
225 const arma::mat&,
const size_t, arma::sp_mat&);
228 template<
typename FunctionType>
230 const arma::mat&,
const size_t, arma::sp_mat&)
const;
233 template<
typename FunctionType>
235 const arma::mat&,
const size_t, arma::sp_mat&);
238 template<
typename FunctionType,
typename... Ts>
242 template<
typename FunctionType,
typename... Ts>
246 template<
typename FunctionType,
typename... Ts>
271 template<
typename ClassType,
272 template<
typename,
template<
typename...>
class,
size_t>
class CheckerA,
273 template<typename...> class SignatureA,
274 template<typename...> class ConstSignatureA,
275 template<typename...> class StaticSignatureA,
276 template<typename, template<typename...> class, size_t> class CheckerB,
277 template<typename...> class SignatureB,
278 template<typename...> class ConstSignatureB,
279 template<typename...> class StaticSignatureB>
283 const static bool HasAnyFormA =
284 CheckerA<ClassType, SignatureA, 0>::value ||
285 CheckerA<ClassType, ConstSignatureA, 0>::value ||
286 CheckerA<ClassType, StaticSignatureA, 0>::value;
288 const static bool HasAnyFormB =
289 CheckerB<ClassType, SignatureB, 0>::value ||
290 CheckerB<ClassType, ConstSignatureB, 0>::value ||
291 CheckerB<ClassType, StaticSignatureB, 0>::value;
294 const static bool HasEitherNonConstForm =
295 CheckerA<ClassType, SignatureA, 0>::value ||
296 CheckerB<ClassType, SignatureB, 0>::value;
298 const static bool value = HasEitherNonConstForm && HasAnyFormA && HasAnyFormB;
311 template<
typename ClassType,
312 template<
typename,
template<
typename...>
class,
size_t>
class CheckerA,
313 template<typename...> class ConstSignatureA,
314 template<typename...> class StaticSignatureA,
315 template<typename, template<typename...> class, size_t> class CheckerB,
316 template<typename...> class ConstSignatureB,
317 template<typename...> class StaticSignatureB>
321 const static bool HasAnyFormA =
322 CheckerA<ClassType, ConstSignatureA, 0>::value ||
323 CheckerA<ClassType, StaticSignatureA, 0>::value;
325 const static bool HasAnyFormB =
326 CheckerB<ClassType, ConstSignatureB, 0>::value ||
327 CheckerB<ClassType, StaticSignatureB, 0>::value;
330 const static bool HasEitherConstForm =
331 CheckerA<ClassType, ConstSignatureA, 0>::value ||
332 CheckerB<ClassType, ConstSignatureB, 0>::value;
334 const static bool value = HasEitherConstForm && HasAnyFormA && HasAnyFormB;
double(*)(const arma::mat &) EvaluateStaticForm
This is the form of a static Evaluate() method.
double(*)(const arma::mat &, arma::mat &) EvaluateWithGradientStaticForm
This is the form of a static EvaluateWithGradient() method.
void(FunctionType::*)(const arma::mat &, const size_t, arma::sp_mat &, const size_t) SparseGradientForm
This is the form of a non-const sparse Gradient() method.
void(*)() ShuffleStaticForm
This is the form of a static Shuffle() method.
void(*)(const arma::mat &, arma::mat &) GradientStaticForm
This is the form of a static Gradient() method.
double(FunctionType::*)(const arma::mat &) const EvaluateConstForm
This is the form of a const Evaluate() method.
size_t(*)() NumFeaturesStaticForm
This is the form of a static NumFeatures() method.
size_t(FunctionType::*)() const NumConstraintsConstForm
This is the form of a const NumConstraints() method.
void(FunctionType::*)(const arma::mat &, arma::mat &) const GradientConstForm
This is the form of a const Gradient() method.
void(*)(const arma::mat &, const size_t, arma::sp_mat &, const size_t) SparseGradientStaticForm
This is the form of a static sparse Gradient() method.
double(FunctionType::*)(const arma::mat &, arma::mat &) const EvaluateWithGradientConstForm
This is the form of a const EvaluateWithGradient() method.
void(FunctionType::*)(const size_t, const arma::mat &, arma::mat &) GradientConstraintForm
This is the form of a non-const GradientConstraint() method.
double(FunctionType::*)(Ts...) const OtherConstForm
This is a utility struct that will match any const form.
void(FunctionType::*)(const arma::mat &, const size_t, arma::sp_mat &) PartialGradientForm
This is the form of a non-const PartialGradient() method.
The core includes that mlpack expects; standard C++ includes and Armadillo.
void(FunctionType::*)(const arma::mat &, const size_t, arma::sp_mat &, const size_t) const SparseGradientConstForm
This is the form of a const sparse Gradient() method.
double(FunctionType::*)(const arma::mat &) EvaluateForm
This is the form of a non-const Evaluate() method.
size_t(FunctionType::*)() const NumFunctionsConstForm
This is the form of a const NumFunctions() method.
double(FunctionType::*)(const size_t, const arma::mat &) EvaluateConstraintForm
This is the form of a non-const EvaluateConstraint() method.
void(*)(const arma::mat &, const size_t, arma::sp_mat &) PartialGradientStaticForm
This is the form of a static PartialGradient() method.
double(FunctionType::*)(const arma::mat &, const size_t, const size_t) const DecomposableEvaluateConstForm
This is the form of a decomposable const Evaluate() method.
void(FunctionType::*)(const arma::mat &, arma::mat &) GradientForm
This is the form of a non-const Gradient() method.
size_t(FunctionType::*)() NumFeaturesForm
This is the form of a non-const NumFeatures() method.
double(*)(const arma::mat &, const size_t, arma::mat &, const size_t) DecomposableEvaluateWithGradientStaticForm
This is the form of a decomposable static EvaluateWithGradient() method.
double(FunctionType::*)(const arma::mat &, const size_t, arma::mat &, const size_t) const DecomposableEvaluateWithGradientConstForm
This is the form of a decomposable const EvaluateWithGradient() method.
HAS_EXACT_METHOD_FORM(Evaluate, HasEvaluate)
Detect an Evaluate() method.
size_t(*)() NumFunctionsStaticForm
This is the form of a static NumFunctions() method.
void(FunctionType::*)() const ShuffleConstForm
This is the form of a const Shuffle() method.
double(*)(const size_t, const arma::mat &) EvaluateConstraintStaticForm
This is the form of a static EvaluateConstraint() method.
void(FunctionType::*)(const arma::mat &, const size_t, arma::mat &, const size_t) DecomposableGradientForm
This is the form of a decomposable non-const Gradient() method.
This is a utility type used to provide unusable overloads from each of the mixin classes.
void(FunctionType::*)(const arma::mat &, const size_t, arma::sp_mat &) const PartialGradientConstForm
This is the form of a const PartialGradient() method.
double(*)(Ts...) OtherStaticForm
This is a utility struct that will match any static form.
size_t(FunctionType::*)() NumConstraintsForm
This is the form of a non-const NumConstraints() method.
void(FunctionType::*)(const arma::mat &, const size_t, arma::mat &, const size_t) const DecomposableGradientConstForm
This the form of a decomposable const Gradient() method.
void(FunctionType::*)() ShuffleForm
This is the form of a non-const Shuffle() method.
size_t(FunctionType::*)() NumFunctionsForm
This is the form of a non-const NumFunctions() method.
void(*)(const size_t, const arma::mat &, arma::mat &) GradientConstraintStaticForm
This is the form of a static GradientConstraint() method.
double(FunctionType::*)(const arma::mat &, arma::mat &) EvaluateWithGradientForm
This is the form of a non-const EvaluateWithGradient() method.
double(FunctionType::*)(const arma::mat &, const size_t, arma::mat &, const size_t) DecomposableEvaluateWithGradientForm
This is the form of a decomposable non-const EvaluateWithGradient() method.
Utility struct: sometimes we want to know if we have two functions available, and that at least one o...
Utility struct: sometimes we want to know if we have two functions available, and that at least one o...
size_t(*)() NumConstraintsStaticForm
This is the form of a static NumConstraints() method.
double(*)(const arma::mat &, const size_t, const size_t) DecomposableEvaluateStaticForm
This is the form of a decomposable static Evaluate() method.
void(FunctionType::*)(const size_t, const arma::mat &, arma::mat &) const GradientConstraintConstForm
This is the form of a const GradientConstraint() method.
double(FunctionType::*)(const arma::mat &, const size_t, const size_t) DecomposableEvaluateForm
This is the form of a decomposable Evaluate() method.
double(FunctionType::*)(Ts...) OtherForm
This is a utility struct that will match any non-const form.
size_t(FunctionType::*)() const NumFeaturesConstForm
This is the form of a const NumFeatures() method.
double(FunctionType::*)(const size_t, const arma::mat &) const EvaluateConstraintConstForm
This is the form of a const EvaluateConstraint() method.
void(*)(const arma::mat &, const size_t, arma::mat &, const size_t) DecomposableGradientStaticForm
This is the form of a decomposable static Gradient() method.