From 9fc7013d8d710afa36be6072812497829a494a9b Mon Sep 17 00:00:00 2001 From: NanuSai Date: Sat, 3 Apr 2021 23:51:42 +0530 Subject: [PATCH 01/10] type trait for multiarbitraryfunction --- .../ensmallen_bits/function/static_checks.hpp | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/include/ensmallen_bits/function/static_checks.hpp b/include/ensmallen_bits/function/static_checks.hpp index 91a211034..a19c08003 100644 --- a/include/ensmallen_bits/function/static_checks.hpp +++ b/include/ensmallen_bits/function/static_checks.hpp @@ -387,6 +387,40 @@ inline void CheckArbitraryFunctionTypeAPI() #endif } +/** +* Perform checks for the ArbitraryFunctionType API. +* Multiobjective case. +*/ +template +typename std::enable_if::type +CheckMultiArbitraryFunctionTypeAPI() +{ + CheckArbitraryFunctionTypeAPI(); +} + +/** + * Perform checks for the ArbitraryFunctionType API. + * Multiobjective case. + */ +template +typename std::enable_if<(I > 1U), void>::type +CheckMultiArbitraryFunctionTypeAPI() +{ +#ifndef ENS_DISABLE_TYPE_CHECKS + static_assert(CheckEvaluate::value, + "One of the FunctionType does not have a correct definition of Evaluate(). " + "Please ensure that each of the FunctionTypes fully satisfies the requirements of " + "the ArbitraryFunctionType API; see the optimizer tutorial for " + "more details."); + CheckMultiArbitraryFunctionTypeAPI(); +#endif +} + /** * Perform checks for the ResolvableFunctionType API. */ From 006929157260c50af531a8bc80a0032513fbca42 Mon Sep 17 00:00:00 2001 From: NanuSai Date: Sun, 4 Apr 2021 14:18:21 +0530 Subject: [PATCH 02/10] temporary solution in: a) static_check (possibly wrong) b) check Arbitrary in for loop in EvaluateObjectives --- include/ensmallen_bits/function/static_checks.hpp | 8 ++++---- include/ensmallen_bits/nsga2/nsga2_impl.hpp | 4 ++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/include/ensmallen_bits/function/static_checks.hpp b/include/ensmallen_bits/function/static_checks.hpp index a19c08003..caf491577 100644 --- a/include/ensmallen_bits/function/static_checks.hpp +++ b/include/ensmallen_bits/function/static_checks.hpp @@ -404,10 +404,10 @@ CheckMultiArbitraryFunctionTypeAPI() * Perform checks for the ArbitraryFunctionType API. * Multiobjective case. */ -template + std::size_t I = sizeof...(RemainingFunctionTypes) + 1U, + typename MatType> typename std::enable_if<(I > 1U), void>::type CheckMultiArbitraryFunctionTypeAPI() { @@ -417,7 +417,7 @@ CheckMultiArbitraryFunctionTypeAPI() "Please ensure that each of the FunctionTypes fully satisfies the requirements of " "the ArbitraryFunctionType API; see the optimizer tutorial for " "more details."); - CheckMultiArbitraryFunctionTypeAPI(); + CheckMultiArbitraryFunctionTypeAPI(); #endif } diff --git a/include/ensmallen_bits/nsga2/nsga2_impl.hpp b/include/ensmallen_bits/nsga2/nsga2_impl.hpp index 9b083be3c..2972fe36f 100644 --- a/include/ensmallen_bits/nsga2/nsga2_impl.hpp +++ b/include/ensmallen_bits/nsga2/nsga2_impl.hpp @@ -227,6 +227,10 @@ NSGA2::EvaluateObjectives( { for (size_t i = 0; i < populationSize; i++) { + using FunctionType = typename std::tuple_element< + I, std::tuple>::type; + traits::CheckArbitraryFunctionTypeAPI< + FunctionType, MatType>(); calculatedObjectives[i](I) = std::get(objectives).Evaluate(population[i]); EvaluateObjectives(population, objectives, calculatedObjectives); From ccf0dff819bd846cd74ed99e20c67595ffc78102 Mon Sep 17 00:00:00 2001 From: NanuSai Date: Sun, 4 Apr 2021 15:50:06 +0530 Subject: [PATCH 03/10] ryans method --- .../ensmallen_bits/function/static_checks.hpp | 43 ++++++++----------- 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/include/ensmallen_bits/function/static_checks.hpp b/include/ensmallen_bits/function/static_checks.hpp index caf491577..72cfdf2aa 100644 --- a/include/ensmallen_bits/function/static_checks.hpp +++ b/include/ensmallen_bits/function/static_checks.hpp @@ -388,37 +388,32 @@ inline void CheckArbitraryFunctionTypeAPI() } /** -* Perform checks for the ArbitraryFunctionType API. -* Multiobjective case. -*/ -template -typename std::enable_if::type + * Perform checks for the ArbitraryFunctionType API. + * Multiobjective case. + */ +template +typename std::enable_if :: type CheckMultiArbitraryFunctionTypeAPI() { + constexpr size_t size = sizeof...(FunctionAndMatTypes); + using TupleType = typename std::tuple; + using FunctionType = typename std::tuple_element::type; + using MatType = typename std::tuple_element::type; + CheckArbitraryFunctionTypeAPI(); } -/** - * Perform checks for the ArbitraryFunctionType API. - * Multiobjective case. - */ -template -typename std::enable_if<(I > 1U), void>::type +template +typename std::enable_if::type CheckMultiArbitraryFunctionTypeAPI() { -#ifndef ENS_DISABLE_TYPE_CHECKS - static_assert(CheckEvaluate::value, - "One of the FunctionType does not have a correct definition of Evaluate(). " - "Please ensure that each of the FunctionTypes fully satisfies the requirements of " - "the ArbitraryFunctionType API; see the optimizer tutorial for " - "more details."); - CheckMultiArbitraryFunctionTypeAPI(); -#endif + constexpr size_t size = sizeof...(FunctionAndMatTypes); + using TupleType = typename std::tuple; + using FunctionType = typename std::tuple_element::type; + using MatType = typename std::tuple_element::type; + CheckArbitraryFunctionTypeAPI(); + + CheckMultiArbitraryFunctionTypeAPI(); } /** From 563457848e11d6553ced288ff47e3f15e8ecdf01 Mon Sep 17 00:00:00 2001 From: Nanubala Gnana Sai <45007169+jonpsy@users.noreply.github.com> Date: Sun, 4 Apr 2021 12:57:31 +0530 Subject: [PATCH 04/10] Added History.MD --- HISTORY.md | 3 ++ .../ensmallen_bits/function/static_checks.hpp | 43 +++++++++---------- include/ensmallen_bits/nsga2/nsga2_impl.hpp | 4 -- 3 files changed, 23 insertions(+), 27 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 9e022a56e..a596432ad 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -16,6 +16,9 @@ * Add clarifying comments in problems/ implementations ([#276](https://github.com/mlpack/ensmallen/pull/276)). + * CheckArbitraryFunctionTypeAPI extended for MOO support + ([#283](https://github.com/mlpack/ensmallen/pull/283)). + ### ensmallen 2.16.1: "Severely Dented Can Of Polyurethane" ###### 2021-03-02 * Fix test compilation issue when `ENS_USE_OPENMP` is set diff --git a/include/ensmallen_bits/function/static_checks.hpp b/include/ensmallen_bits/function/static_checks.hpp index 72cfdf2aa..1f34c09f3 100644 --- a/include/ensmallen_bits/function/static_checks.hpp +++ b/include/ensmallen_bits/function/static_checks.hpp @@ -375,45 +375,42 @@ inline void CheckSparseFunctionTypeAPI() /** * Perform checks for the ArbitraryFunctionType API. */ -template -inline void CheckArbitraryFunctionTypeAPI() -{ -#ifndef ENS_DISABLE_TYPE_CHECKS - static_assert(CheckEvaluate::value, - "The FunctionType does not have a correct definition of Evaluate(). " - "Please check that the FunctionType fully satisfies the requirements of " - "the ArbitraryFunctionType API; see the optimizer tutorial for " - "more details."); -#endif -} - -/** - * Perform checks for the ArbitraryFunctionType API. - * Multiobjective case. - */ -template +template typename std::enable_if :: type -CheckMultiArbitraryFunctionTypeAPI() +CheckArbitraryFunctionTypeAPI() { +#ifndef ENS_DISABLE_TYPE_CHECKS constexpr size_t size = sizeof...(FunctionAndMatTypes); using TupleType = typename std::tuple; using FunctionType = typename std::tuple_element::type; using MatType = typename std::tuple_element::type; - CheckArbitraryFunctionTypeAPI(); + static_assert(CheckEvaluate::value, + "The FunctionType does not have a correct definition of Evaluate(). " + "Please check that the FunctionType fully satisfies the requirements of " + "the ArbitraryFunctionType API; see the optimizer tutorial for " + "more details."); +#endif } -template +template typename std::enable_if::type -CheckMultiArbitraryFunctionTypeAPI() +CheckArbitraryFunctionTypeAPI() { +#ifndef ENS_DISABLE_TYPE_CHECKS constexpr size_t size = sizeof...(FunctionAndMatTypes); using TupleType = typename std::tuple; using FunctionType = typename std::tuple_element::type; using MatType = typename std::tuple_element::type; - CheckArbitraryFunctionTypeAPI(); - CheckMultiArbitraryFunctionTypeAPI(); + static_assert(CheckEvaluate::value, + "The FunctionType does not have a correct definition of Evaluate(). " + "Please check that the FunctionType fully satisfies the requirements of " + "the ArbitraryFunctionType API; see the optimizer tutorial for " + "more details."); + + CheckArbitraryFunctionTypeAPI(); +#endif } /** diff --git a/include/ensmallen_bits/nsga2/nsga2_impl.hpp b/include/ensmallen_bits/nsga2/nsga2_impl.hpp index 2972fe36f..9b083be3c 100644 --- a/include/ensmallen_bits/nsga2/nsga2_impl.hpp +++ b/include/ensmallen_bits/nsga2/nsga2_impl.hpp @@ -227,10 +227,6 @@ NSGA2::EvaluateObjectives( { for (size_t i = 0; i < populationSize; i++) { - using FunctionType = typename std::tuple_element< - I, std::tuple>::type; - traits::CheckArbitraryFunctionTypeAPI< - FunctionType, MatType>(); calculatedObjectives[i](I) = std::get(objectives).Evaluate(population[i]); EvaluateObjectives(population, objectives, calculatedObjectives); From 750043d20a7d74a0c89f1e71bf4e39bc93b4149e Mon Sep 17 00:00:00 2001 From: Nanubala Gnana Sai <45007169+jonpsy@users.noreply.github.com> Date: Sun, 4 Apr 2021 19:31:42 +0530 Subject: [PATCH 05/10] - reuse established API - doc change for MOO trait --- .../ensmallen_bits/function/static_checks.hpp | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/include/ensmallen_bits/function/static_checks.hpp b/include/ensmallen_bits/function/static_checks.hpp index 1f34c09f3..5d38a0c0e 100644 --- a/include/ensmallen_bits/function/static_checks.hpp +++ b/include/ensmallen_bits/function/static_checks.hpp @@ -375,16 +375,10 @@ inline void CheckSparseFunctionTypeAPI() /** * Perform checks for the ArbitraryFunctionType API. */ -template -typename std::enable_if :: type -CheckArbitraryFunctionTypeAPI() +template +void CheckArbitraryFunctionTypeAPI() { #ifndef ENS_DISABLE_TYPE_CHECKS - constexpr size_t size = sizeof...(FunctionAndMatTypes); - using TupleType = typename std::tuple; - using FunctionType = typename std::tuple_element::type; - using MatType = typename std::tuple_element::type; - static_assert(CheckEvaluate::value, "The FunctionType does not have a correct definition of Evaluate(). " "Please check that the FunctionType fully satisfies the requirements of " @@ -404,9 +398,9 @@ CheckArbitraryFunctionTypeAPI() using MatType = typename std::tuple_element::type; static_assert(CheckEvaluate::value, - "The FunctionType does not have a correct definition of Evaluate(). " - "Please check that the FunctionType fully satisfies the requirements of " - "the ArbitraryFunctionType API; see the optimizer tutorial for " + "One of the provided FunctionType does not have a correct definition of Evaluate(). " + "Please check that the corresponding FunctionType fully satisfies the requirements" + "of the ArbitraryFunctionType API; see the optimizer tutorial for " "more details."); CheckArbitraryFunctionTypeAPI(); From 6f4362b23ee3e7efee578f520c99a8a07ebe5a9c Mon Sep 17 00:00:00 2001 From: Nanubala Gnana Sai <45007169+jonpsy@users.noreply.github.com> Date: Sun, 4 Apr 2021 19:35:40 +0530 Subject: [PATCH 06/10] style fixing --- .../ensmallen_bits/function/static_checks.hpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/include/ensmallen_bits/function/static_checks.hpp b/include/ensmallen_bits/function/static_checks.hpp index 5d38a0c0e..f45baa50d 100644 --- a/include/ensmallen_bits/function/static_checks.hpp +++ b/include/ensmallen_bits/function/static_checks.hpp @@ -380,10 +380,10 @@ void CheckArbitraryFunctionTypeAPI() { #ifndef ENS_DISABLE_TYPE_CHECKS static_assert(CheckEvaluate::value, - "The FunctionType does not have a correct definition of Evaluate(). " - "Please check that the FunctionType fully satisfies the requirements of " - "the ArbitraryFunctionType API; see the optimizer tutorial for " - "more details."); + "The FunctionType does not have a correct definition of Evaluate(). " + "Please check that the FunctionType fully satisfies the requirements of " + "the ArbitraryFunctionType API; see the optimizer tutorial for " + "more details."); #endif } @@ -398,10 +398,10 @@ CheckArbitraryFunctionTypeAPI() using MatType = typename std::tuple_element::type; static_assert(CheckEvaluate::value, - "One of the provided FunctionType does not have a correct definition of Evaluate(). " - "Please check that the corresponding FunctionType fully satisfies the requirements" - "of the ArbitraryFunctionType API; see the optimizer tutorial for " - "more details."); + "One of the provided FunctionType does not have a correct definition of Evaluate(). " + "Please check that the corresponding FunctionType fully satisfies the requirements" + "of the ArbitraryFunctionType API; see the optimizer tutorial for " + "more details."); CheckArbitraryFunctionTypeAPI(); #endif From 7bffa5df48be1ae295e1ce9d9cc14e2a5bced82f Mon Sep 17 00:00:00 2001 From: Nanubala Gnana Sai <45007169+jonpsy@users.noreply.github.com> Date: Sun, 4 Apr 2021 19:38:04 +0530 Subject: [PATCH 07/10] restore inline --- include/ensmallen_bits/function/static_checks.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/ensmallen_bits/function/static_checks.hpp b/include/ensmallen_bits/function/static_checks.hpp index f45baa50d..43a9f02a5 100644 --- a/include/ensmallen_bits/function/static_checks.hpp +++ b/include/ensmallen_bits/function/static_checks.hpp @@ -376,7 +376,7 @@ inline void CheckSparseFunctionTypeAPI() * Perform checks for the ArbitraryFunctionType API. */ template -void CheckArbitraryFunctionTypeAPI() +inline void CheckArbitraryFunctionTypeAPI() { #ifndef ENS_DISABLE_TYPE_CHECKS static_assert(CheckEvaluate::value, From 8ecd483bd4b35bf6740d1d703efd1436642ede47 Mon Sep 17 00:00:00 2001 From: Nanubala Gnana Sai <45007169+jonpsy@users.noreply.github.com> Date: Wed, 7 Apr 2021 09:01:41 +0530 Subject: [PATCH 08/10] Update include/ensmallen_bits/function/static_checks.hpp Co-authored-by: Marcus Edel --- include/ensmallen_bits/function/static_checks.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/ensmallen_bits/function/static_checks.hpp b/include/ensmallen_bits/function/static_checks.hpp index 43a9f02a5..733081d7a 100644 --- a/include/ensmallen_bits/function/static_checks.hpp +++ b/include/ensmallen_bits/function/static_checks.hpp @@ -399,7 +399,7 @@ CheckArbitraryFunctionTypeAPI() static_assert(CheckEvaluate::value, "One of the provided FunctionType does not have a correct definition of Evaluate(). " - "Please check that the corresponding FunctionType fully satisfies the requirements" + "Please check that the corresponding FunctionType fully satisfies the requirements " "of the ArbitraryFunctionType API; see the optimizer tutorial for " "more details."); From 782b99476580e471915a29cb4890d6b8b9e73508 Mon Sep 17 00:00:00 2001 From: Nanubala Gnana Sai <45007169+jonpsy@users.noreply.github.com> Date: Wed, 7 Apr 2021 09:26:11 +0530 Subject: [PATCH 09/10] rm unsigned symnb --- include/ensmallen_bits/function/static_checks.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/ensmallen_bits/function/static_checks.hpp b/include/ensmallen_bits/function/static_checks.hpp index 733081d7a..8267aaddf 100644 --- a/include/ensmallen_bits/function/static_checks.hpp +++ b/include/ensmallen_bits/function/static_checks.hpp @@ -375,7 +375,7 @@ inline void CheckSparseFunctionTypeAPI() /** * Perform checks for the ArbitraryFunctionType API. */ -template +template inline void CheckArbitraryFunctionTypeAPI() { #ifndef ENS_DISABLE_TYPE_CHECKS @@ -387,8 +387,8 @@ inline void CheckArbitraryFunctionTypeAPI() #endif } -template -typename std::enable_if::type +template +typename std::enable_if::type CheckArbitraryFunctionTypeAPI() { #ifndef ENS_DISABLE_TYPE_CHECKS From ad8538602d7811236621df312aae74ba949cb580 Mon Sep 17 00:00:00 2001 From: NanuSai Date: Thu, 8 Apr 2021 01:17:36 +0530 Subject: [PATCH 10/10] fix compile time error --- include/ensmallen_bits/function/static_checks.hpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/include/ensmallen_bits/function/static_checks.hpp b/include/ensmallen_bits/function/static_checks.hpp index 8267aaddf..449090bd0 100644 --- a/include/ensmallen_bits/function/static_checks.hpp +++ b/include/ensmallen_bits/function/static_checks.hpp @@ -375,7 +375,7 @@ inline void CheckSparseFunctionTypeAPI() /** * Perform checks for the ArbitraryFunctionType API. */ -template +template inline void CheckArbitraryFunctionTypeAPI() { #ifndef ENS_DISABLE_TYPE_CHECKS @@ -387,14 +387,13 @@ inline void CheckArbitraryFunctionTypeAPI() #endif } -template -typename std::enable_if::type +template +typename std::enable_if<(sizeof...(RemainingTypes) > 1), void>::type CheckArbitraryFunctionTypeAPI() { #ifndef ENS_DISABLE_TYPE_CHECKS - constexpr size_t size = sizeof...(FunctionAndMatTypes); - using TupleType = typename std::tuple; - using FunctionType = typename std::tuple_element::type; + constexpr size_t size = sizeof...(RemainingTypes); + using TupleType = typename std::tuple; using MatType = typename std::tuple_element::type; static_assert(CheckEvaluate::value, @@ -403,7 +402,7 @@ CheckArbitraryFunctionTypeAPI() "of the ArbitraryFunctionType API; see the optimizer tutorial for " "more details."); - CheckArbitraryFunctionTypeAPI(); + CheckArbitraryFunctionTypeAPI(); #endif }