diff --git a/core/config/parse_macro.hpp b/core/config/parse_macro.hpp new file mode 100644 index 00000000000..bb54916835e --- /dev/null +++ b/core/config/parse_macro.hpp @@ -0,0 +1,61 @@ +// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors +// +// SPDX-License-Identifier: BSD-3-Clause + +#ifndef GKO_CORE_CONFIG_PARSE_MACRO_HPP_ +#define GKO_CORE_CONFIG_PARSE_MACRO_HPP_ + + +#include +#include +#include + + +#include "core/config/config_helper.hpp" +#include "core/config/dispatch.hpp" +#include "core/config/type_descriptor_helper.hpp" + + +// for value_type only +#define PARSE_VALUE_TYPE(_type, _configurator) \ + template <> \ + deferred_factory_parameter \ + parse( \ + const gko::config::pnode& config, \ + const gko::config::registry& context, \ + const gko::config::type_descriptor& td) \ + { \ + auto updated = gko::config::update_type(config, td); \ + return gko::config::dispatch( \ + config, context, updated, \ + gko::config::make_type_selector(updated.get_value_typestr(), \ + gko::config::value_type_list())); \ + } \ + static_assert(true, \ + "This assert is used to counter the false positive extra " \ + "semi-colon warnings") + + +// for value_type and index_type +#define PARSE_VALUE_AND_INDEX_TYPE(_type, _configurator) \ + template <> \ + deferred_factory_parameter \ + parse( \ + const gko::config::pnode& config, \ + const gko::config::registry& context, \ + const gko::config::type_descriptor& td) \ + { \ + auto updated = gko::config::update_type(config, td); \ + return gko::config::dispatch( \ + config, context, updated, \ + gko::config::make_type_selector(updated.get_value_typestr(), \ + gko::config::value_type_list()), \ + gko::config::make_type_selector(updated.get_index_typestr(), \ + gko::config::index_type_list())); \ + } \ + static_assert(true, \ + "This assert is used to counter the false positive extra " \ + "semi-colon warnings") + + +#endif // GKO_CORE_CONFIG_PARSE_MACRO_HPP_ diff --git a/core/config/solver_config.cpp b/core/config/solver_config.cpp index 43b00965a48..21ddf015e4e 100644 --- a/core/config/solver_config.cpp +++ b/core/config/solver_config.cpp @@ -21,72 +21,27 @@ #include "core/config/config_helper.hpp" #include "core/config/dispatch.hpp" +#include "core/config/parse_macro.hpp" #include "core/config/solver_config.hpp" namespace gko { namespace config { -// for valuetype only -#define PARSE(_type) \ - template <> \ - deferred_factory_parameter \ - parse(const pnode& config, \ - const registry& context, \ - const type_descriptor& td) \ - { \ - auto updated = update_type(config, td); \ - return dispatch( \ - config, context, updated, \ - make_type_selector(updated.get_value_typestr(), \ - value_type_list())); \ - } -PARSE(Cg) -PARSE(Bicg) -PARSE(Bicgstab) -PARSE(Cgs) -PARSE(Fcg) -PARSE(Ir) -PARSE(Idr) -PARSE(Gcr) -PARSE(Gmres) -PARSE(CbGmres) - - -template <> -deferred_factory_parameter parse( - const pnode& config, const registry& context, const type_descriptor& td) -{ - auto updated = update_type(config, td); - return dispatch( - config, context, updated, - make_type_selector(updated.get_value_typestr(), value_type_list()), - make_type_selector(updated.get_index_typestr(), index_type_list())); -} - - -template <> -deferred_factory_parameter parse( - const pnode& config, const registry& context, const type_descriptor& td) -{ - auto updated = update_type(config, td); - return dispatch( - config, context, updated, - make_type_selector(updated.get_value_typestr(), value_type_list()), - make_type_selector(updated.get_index_typestr(), index_type_list())); -} - -template <> -deferred_factory_parameter parse( - const pnode& config, const registry& context, const type_descriptor& td) -{ - auto updated = update_type(config, td); - return dispatch( - config, context, updated, - make_type_selector(updated.get_value_typestr(), value_type_list()), - make_type_selector(updated.get_index_typestr(), index_type_list())); -} +PARSE_VALUE_TYPE(Cg, gko::solver::Cg); +PARSE_VALUE_TYPE(Bicg, gko::solver::Bicg); +PARSE_VALUE_TYPE(Bicgstab, gko::solver::Bicgstab); +PARSE_VALUE_TYPE(Cgs, gko::solver::Cgs); +PARSE_VALUE_TYPE(Fcg, gko::solver::Fcg); +PARSE_VALUE_TYPE(Ir, gko::solver::Ir); +PARSE_VALUE_TYPE(Idr, gko::solver::Idr); +PARSE_VALUE_TYPE(Gcr, gko::solver::Gcr); +PARSE_VALUE_TYPE(Gmres, gko::solver::Gmres); +PARSE_VALUE_TYPE(CbGmres, gko::solver::CbGmres); +PARSE_VALUE_AND_INDEX_TYPE(Direct, gko::experimental::solver::Direct); +PARSE_VALUE_AND_INDEX_TYPE(LowerTrs, gko::solver::LowerTrs); +PARSE_VALUE_AND_INDEX_TYPE(UpperTrs, gko::solver::UpperTrs); } // namespace config diff --git a/core/test/config/solver.cpp b/core/test/config/solver.cpp index 621a2a6ed4a..c2faa58891d 100644 --- a/core/test/config/solver.cpp +++ b/core/test/config/solver.cpp @@ -68,8 +68,8 @@ struct SolverConfigTest { detail::registry_accessor::get_data( reg, "linop_factory")); } else { - config_map["criteria"] = pnode{std::map{ - {"type", pnode{"stop::Iteration"}}}}; + config_map["criteria"] = + pnode{{{"type", pnode{"stop::Iteration"}}}}; param.with_criteria(DummyStop::build().on(exec)); config_map["preconditioner"] = pnode{{{"type", pnode{"solver::Cg"}}, @@ -106,7 +106,7 @@ struct SolverConfigTest { struct Cg : SolverConfigTest, gko::solver::Cg> { static pnode::map_type setup_base() { - return pnode::map_type{{"type", pnode{"solver::Cg"}}}; + return {{"type", pnode{"solver::Cg"}}}; } }; @@ -115,7 +115,7 @@ struct Cgs : SolverConfigTest, gko::solver::Cgs> { static pnode::map_type setup_base() { - return pnode::map_type{{"type", pnode{"solver::Cgs"}}}; + return {{"type", pnode{"solver::Cgs"}}}; } }; @@ -124,7 +124,7 @@ struct Fcg : SolverConfigTest, gko::solver::Fcg> { static pnode::map_type setup_base() { - return pnode::map_type{{"type", pnode{"solver::Fcg"}}}; + return {{"type", pnode{"solver::Fcg"}}}; } }; @@ -133,7 +133,7 @@ struct Bicg : SolverConfigTest, gko::solver::Bicg> { static pnode::map_type setup_base() { - return pnode::map_type{{"type", pnode{"solver::Bicg"}}}; + return {{"type", pnode{"solver::Bicg"}}}; } }; @@ -142,7 +142,7 @@ struct Bicgstab : SolverConfigTest, gko::solver::Bicgstab> { static pnode::map_type setup_base() { - return pnode::map_type{{"type", pnode{"solver::Bicgstab"}}}; + return {{"type", pnode{"solver::Bicgstab"}}}; } }; @@ -150,7 +150,7 @@ struct Bicgstab : SolverConfigTest, struct Ir : SolverConfigTest, gko::solver::Ir> { static pnode::map_type setup_base() { - return pnode::map_type{{"type", pnode{"solver::Ir"}}}; + return {{"type", pnode{"solver::Ir"}}}; } template @@ -174,8 +174,8 @@ struct Ir : SolverConfigTest, gko::solver::Ir> { detail::registry_accessor::get_data( reg, "linop_factory")); } else { - config_map["criteria"] = pnode{std::map{ - {"type", pnode{"stop::Iteration"}}}}; + config_map["criteria"] = + pnode{{{"type", pnode{"stop::Iteration"}}}}; param.with_criteria(DummyStop::build().on(exec)); config_map["solver"] = pnode{{{"type", pnode{"solver::Cg"}}, {"value_type", pnode{"float64"}}}}; @@ -214,7 +214,7 @@ struct Idr : SolverConfigTest, gko::solver::Idr> { static pnode::map_type setup_base() { - return pnode::map_type{{"type", pnode{"solver::Idr"}}}; + return {{"type", pnode{"solver::Idr"}}}; } template @@ -252,7 +252,7 @@ struct Gcr : SolverConfigTest, gko::solver::Gcr> { static pnode::map_type setup_base() { - return pnode::map_type{{"type", pnode{"solver::Gcr"}}}; + return {{"type", pnode{"solver::Gcr"}}}; } template @@ -281,7 +281,7 @@ struct Gmres : SolverConfigTest, gko::solver::Gmres> { static pnode::map_type setup_base() { - return pnode::map_type{{"type", pnode{"solver::Gmres"}}}; + return {{"type", pnode{"solver::Gmres"}}}; } template @@ -313,7 +313,7 @@ struct CbGmres : SolverConfigTest, gko::solver::CbGmres> { static pnode::map_type setup_base() { - return pnode::map_type{{"type", pnode{"solver::CbGmres"}}}; + return {{"type", pnode{"solver::CbGmres"}}}; } template @@ -347,7 +347,7 @@ struct Direct gko::experimental::solver::Direct> { static pnode::map_type setup_base() { - return pnode::map_type{{"type", pnode{"solver::Direct"}}}; + return {{"type", pnode{"solver::Direct"}}}; } static void change_template(pnode::map_type& config_map) @@ -430,7 +430,7 @@ struct TrsHelper : SolverConfigTest, Trs> { struct LowerTrs : TrsHelper { static pnode::map_type setup_base() { - return pnode::map_type{{"type", pnode{"solver::LowerTrs"}}}; + return {{"type", pnode{"solver::LowerTrs"}}}; } }; @@ -438,7 +438,7 @@ struct LowerTrs : TrsHelper { struct UpperTrs : TrsHelper { static pnode::map_type setup_base() { - return pnode::map_type{{"type", pnode{"solver::UpperTrs"}}}; + return {{"type", pnode{"solver::UpperTrs"}}}; } }; diff --git a/include/ginkgo/core/solver/bicg.hpp b/include/ginkgo/core/solver/bicg.hpp index 30608e1bda5..f8285e80533 100644 --- a/include/ginkgo/core/solver/bicg.hpp +++ b/include/ginkgo/core/solver/bicg.hpp @@ -85,12 +85,13 @@ class Bicg /** * Create the parameters from the property_tree. * Because this is directly tied to the specific type. The value/index type - * settings are ignored and type_descriptor is for children objects. + * settings within config are ignored and type_descriptor is only used + * for children objects. * * @param config the property tree for setting * @param context the registry * @param td_for_child the type descriptor for children objects. The - * default will directly from the specific type. + * default uses the value type of this class. * * @return parameters */ diff --git a/include/ginkgo/core/solver/bicgstab.hpp b/include/ginkgo/core/solver/bicgstab.hpp index 56db86ddfe5..93477c6a29d 100644 --- a/include/ginkgo/core/solver/bicgstab.hpp +++ b/include/ginkgo/core/solver/bicgstab.hpp @@ -83,12 +83,13 @@ class Bicgstab /** * Create the parameters from the property_tree. * Because this is directly tied to the specific type. The value/index type - * settings are ignored and type_descriptor is for children objects. + * settings within config are ignored and type_descriptor is only used + * for children objects. * * @param config the property tree for setting * @param context the registry * @param td_for_child the type descriptor for children objects. The - * default will directly from the specific type. + * default uses the value type of this class. * * @return parameters */ diff --git a/include/ginkgo/core/solver/cb_gmres.hpp b/include/ginkgo/core/solver/cb_gmres.hpp index 3bc986d2bef..933085acd44 100644 --- a/include/ginkgo/core/solver/cb_gmres.hpp +++ b/include/ginkgo/core/solver/cb_gmres.hpp @@ -150,12 +150,13 @@ class CbGmres : public EnableLinOp>, /** * Create the parameters from the property_tree. * Because this is directly tied to the specific type. The value/index type - * settings are ignored and type_descriptor is for children objects. + * settings within config are ignored and type_descriptor is only used + * for children objects. * * @param config the property tree for setting * @param context the registry * @param td_for_child the type descriptor for children objects. The - * default will directly from the specific type. + * default uses the value type of this class. * * @return parameters */ diff --git a/include/ginkgo/core/solver/cg.hpp b/include/ginkgo/core/solver/cg.hpp index 9302f2297b3..981adc0675c 100644 --- a/include/ginkgo/core/solver/cg.hpp +++ b/include/ginkgo/core/solver/cg.hpp @@ -79,12 +79,13 @@ class Cg : public EnableLinOp>, /** * Create the parameters from the property_tree. * Because this is directly tied to the specific type. The value/index type - * settings are ignored and type_descriptor is for children objects. + * settings within config are ignored and type_descriptor is only used + * for children objects. * * @param config the property tree for setting * @param context the registry * @param td_for_child the type descriptor for children objects. The - * default will directly from the specific type. + * default uses the value type of this class. * * @return parameters */ diff --git a/include/ginkgo/core/solver/cgs.hpp b/include/ginkgo/core/solver/cgs.hpp index bc7314d5f12..5ddf2539784 100644 --- a/include/ginkgo/core/solver/cgs.hpp +++ b/include/ginkgo/core/solver/cgs.hpp @@ -76,12 +76,13 @@ class Cgs /** * Create the parameters from the property_tree. * Because this is directly tied to the specific type. The value/index type - * settings are ignored and type_descriptor is for children objects. + * settings within config are ignored and type_descriptor is only used + * for children objects. * * @param config the property tree for setting * @param context the registry * @param td_for_child the type descriptor for children objects. The - * default will directly from the specific type. + * default uses the value type of this class. * * @return parameters */ diff --git a/include/ginkgo/core/solver/direct.hpp b/include/ginkgo/core/solver/direct.hpp index 06a4019bf43..781903f5337 100644 --- a/include/ginkgo/core/solver/direct.hpp +++ b/include/ginkgo/core/solver/direct.hpp @@ -70,12 +70,13 @@ class Direct : public EnableLinOp>, /** * Create the parameters from the property_tree. * Because this is directly tied to the specific type. The value/index type - * settings are ignored and type_descriptor is for children objects. + * settings within config are ignored and type_descriptor is only used + * for children objects. * * @param config the property tree for setting * @param context the registry * @param td_for_child the type descriptor for children objects. The - * default will directly from the specific type. + * default uses the value/index type of this class. * * @return parameters */ diff --git a/include/ginkgo/core/solver/fcg.hpp b/include/ginkgo/core/solver/fcg.hpp index 17ce63a670a..9056cb6b623 100644 --- a/include/ginkgo/core/solver/fcg.hpp +++ b/include/ginkgo/core/solver/fcg.hpp @@ -84,12 +84,13 @@ class Fcg /** * Create the parameters from the property_tree. * Because this is directly tied to the specific type. The value/index type - * settings are ignored and type_descriptor is for children objects. + * settings within config are ignored and type_descriptor is only used + * for children objects. * * @param config the property tree for setting * @param context the registry * @param td_for_child the type descriptor for children objects. The - * default will directly from the specific type. + * default uses the value type of this class. * * @return parameters */ diff --git a/include/ginkgo/core/solver/gcr.hpp b/include/ginkgo/core/solver/gcr.hpp index af11a4901d5..393886ec827 100644 --- a/include/ginkgo/core/solver/gcr.hpp +++ b/include/ginkgo/core/solver/gcr.hpp @@ -96,12 +96,13 @@ class Gcr /** * Create the parameters from the property_tree. * Because this is directly tied to the specific type. The value/index type - * settings are ignored and type_descriptor is for children objects. + * settings within config are ignored and type_descriptor is only used + * for children objects. * * @param config the property tree for setting * @param context the registry * @param td_for_child the type descriptor for children objects. The - * default will directly from the specific type. + * default uses the value type of this class. * * @return parameters */ diff --git a/include/ginkgo/core/solver/gmres.hpp b/include/ginkgo/core/solver/gmres.hpp index 68f4086e2d0..8146fb52db4 100644 --- a/include/ginkgo/core/solver/gmres.hpp +++ b/include/ginkgo/core/solver/gmres.hpp @@ -101,12 +101,13 @@ class Gmres /** * Create the parameters from the property_tree. * Because this is directly tied to the specific type. The value/index type - * settings are ignored and type_descriptor is for children objects. + * settings within config are ignored and type_descriptor is only used + * for children objects. * * @param config the property tree for setting * @param context the registry * @param td_for_child the type descriptor for children objects. The - * default will directly from the specific type. + * default uses the value type of this class. * * @return parameters */ diff --git a/include/ginkgo/core/solver/idr.hpp b/include/ginkgo/core/solver/idr.hpp index 7ee0063a5e7..58ec1ba7e67 100644 --- a/include/ginkgo/core/solver/idr.hpp +++ b/include/ginkgo/core/solver/idr.hpp @@ -199,12 +199,13 @@ class Idr /** * Create the parameters from the property_tree. * Because this is directly tied to the specific type. The value/index type - * settings are ignored and type_descriptor is for children objects. + * settings within config are ignored and type_descriptor is only used + * for children objects. * * @param config the property tree for setting * @param context the registry * @param td_for_child the type descriptor for children objects. The - * default will directly from the specific type. + * default uses the value type of this class. * * @return parameters */ diff --git a/include/ginkgo/core/solver/ir.hpp b/include/ginkgo/core/solver/ir.hpp index 961fb5b4475..6db7e8fa455 100644 --- a/include/ginkgo/core/solver/ir.hpp +++ b/include/ginkgo/core/solver/ir.hpp @@ -187,12 +187,13 @@ class Ir : public EnableLinOp>, /** * Create the parameters from the property_tree. * Because this is directly tied to the specific type. The value/index type - * settings are ignored and type_descriptor is for children objects. + * settings within config are ignored and type_descriptor is only used + * for children objects. * * @param config the property tree for setting * @param context the registry * @param td_for_child the type descriptor for children objects. The - * default will directly from the specific type. + * default uses the value type of this class. * * @return parameters */ diff --git a/include/ginkgo/core/solver/triangular.hpp b/include/ginkgo/core/solver/triangular.hpp index a620f8501b5..24ed9ee03a6 100644 --- a/include/ginkgo/core/solver/triangular.hpp +++ b/include/ginkgo/core/solver/triangular.hpp @@ -111,12 +111,13 @@ class LowerTrs : public EnableLinOp>, /** * Create the parameters from the property_tree. * Because this is directly tied to the specific type. The value/index type - * settings are ignored and type_descriptor is for children objects. + * settings within config are ignored and type_descriptor is only used + * for children objects. * * @param config the property tree for setting * @param context the registry * @param td_for_child the type descriptor for children objects. The - * default will directly from the specific type. + * default uses the value/index type of this class. * * @return parameters */ @@ -278,12 +279,13 @@ class UpperTrs : public EnableLinOp>, /** * Create the parameters from the property_tree. * Because this is directly tied to the specific type. The value/index type - * settings are ignored and type_descriptor is for children objects. + * settings within config are ignored and type_descriptor is only used + * for children objects. * * @param config the property tree for setting * @param context the registry * @param td_for_child the type descriptor for children objects. The - * default will directly from the specific type. + * default uses the value/index type of this class. * * @return parameters */