diff --git a/core/config/config_helper.cpp b/core/config/config_helper.cpp index 2c70fa6f79e..5f26d927cad 100644 --- a/core/config/config_helper.cpp +++ b/core/config/config_helper.cpp @@ -24,18 +24,14 @@ parse_or_get_factory(const pnode& config, const registry& context, const type_descriptor& td) { - deferred_factory_parameter ptr; if (config.get_tag() == pnode::tag_t::string) { - ptr = detail::registry_accessor::get_data( + return detail::registry_accessor::get_data( context, config.get_string()); } else if (config.get_tag() == pnode::tag_t::map) { - ptr = parse(config, context, td); + return parse(config, context, td); } else { GKO_INVALID_STATE("The data of config is not valid."); } - GKO_THROW_IF_INVALID(!ptr.is_empty(), "parse returned nullptr"); - - return ptr; } @@ -45,7 +41,6 @@ parse_or_get_factory(const pnode& config, const registry& context, const type_descriptor& td) { - deferred_factory_parameter ptr; if (config.get_tag() == pnode::tag_t::string) { return detail::registry_accessor::get_data( context, config.get_string()); @@ -55,15 +50,15 @@ parse_or_get_factory(const pnode& config, gko::stop::CriterionFactory>( const pnode&, const registry&, type_descriptor)>> criterion_map{ - {{"stop::Time", configure_time}, - {"stop::Iteration", configure_iter}, - {"stop::ResidualNorm", configure_residual}, - {"stop::ImplicitResidualNorm", configure_implicit_residual}}}; + {{"Time", configure_time}, + {"Iteration", configure_iter}, + {"ResidualNorm", configure_residual}, + {"ImplicitResidualNorm", configure_implicit_residual}}}; return criterion_map.at(config.get("type").get_string())(config, context, td); + } else { + GKO_INVALID_STATE("The data of config is not valid."); } - GKO_THROW_IF_INVALID(!ptr.is_empty(), "parse returned nullptr"); - return ptr; } } // namespace config diff --git a/core/config/type_descriptor.cpp b/core/config/type_descriptor.cpp index de44d19700c..c2885407cad 100644 --- a/core/config/type_descriptor.cpp +++ b/core/config/type_descriptor.cpp @@ -5,6 +5,9 @@ #include +#include + + #include "core/config/type_descriptor_helper.hpp" @@ -21,7 +24,9 @@ type_descriptor update_type(const pnode& config, const type_descriptor& td) value_typestr = obj.get_string(); } if (auto& obj = config.get("index_type")) { - index_typestr = obj.get_string(); + GKO_INVALID_STATE( + "Setting index_type in the config is not allowed. Please set the " + "proper index_type through type_descriptor of parse"); } return type_descriptor{value_typestr, index_typestr}; } diff --git a/core/test/config/config.cpp b/core/test/config/config.cpp index 59e06dfb589..163f6936de2 100644 --- a/core/test/config/config.cpp +++ b/core/test/config/config.cpp @@ -35,8 +35,7 @@ class Config : public ::testing::Test { : exec(gko::ReferenceExecutor::create()), mtx(gko::initialize( {{2, -1.0, 0.0}, {-1.0, 2, -1.0}, {0.0, -1.0, 2}}, exec)), - stop_config( - {{"type", pnode{"stop::Iteration"}}, {"max_iters", pnode{1}}}) + stop_config({{"type", pnode{"Iteration"}}, {"max_iters", pnode{1}}}) {} std::shared_ptr exec; diff --git a/include/ginkgo/core/config/config.hpp b/include/ginkgo/core/config/config.hpp index 01a1a339cc1..5d77c6f71c7 100644 --- a/include/ginkgo/core/config/config.hpp +++ b/include/ginkgo/core/config/config.hpp @@ -38,11 +38,11 @@ class pnode; * that is not defined will fallback to the type_descriptor argument * 2. The new `"type"` key determines which Ginkgo object to create. The value * for this key is the desired class name with namespaces (except for - * `gko::`, `experimental::`). Any template parameters a class might have are - * left out. Only classes with a factory are supported. For example, the - * configuration `"type": "solver::Cg"` specifies that a Cg solver will be - * created. Note: template parameters can either be given in the - * configuration as separate key-value pairs, or in the type_descriptor. + * `gko::`, `experimental::`, `stop::`). Any template parameters a class + * might have are left out. Only classes with a factory are supported. For + * example, the configuration `"type": "solver::Cg"` specifies that a Cg + * solver will be created. Note: template parameters can either be given in + * the configuration as separate key-value pairs, or in the type_descriptor. * 3. Factory and class template parameters can be defined with key-value pairs * that are derived from the class they are referring to. When a factory has * a parameter with the function `with_(value)`, then the configuration @@ -101,8 +101,8 @@ class pnode; * "type": "solver::Gmres", * "krylov_dim": 20, * "criteria": [ - * {"type": "stop::Iteration", "max_iters": 10}, - * {"type": "stop::ResidualNorm", "reduction_factor": 1e-6} + * {"type": "Iteration", "max_iters": 10}, + * {"type": "ResidualNorm", "reduction_factor": 1e-6} * ] * ``` * then passing it to this function like this: @@ -126,7 +126,6 @@ class pnode; * Additionally, the config can be used to set these types through the fields: * ``` * value_type: "some_value_type" - * index_type: "some_index_type" * ``` * These types take precedence over the type descriptor and they are used for * every created object beginning from the config level they are defined on and diff --git a/include/ginkgo/core/config/registry.hpp b/include/ginkgo/core/config/registry.hpp index 1cb7e40cf80..2efa160ee65 100644 --- a/include/ginkgo/core/config/registry.hpp +++ b/include/ginkgo/core/config/registry.hpp @@ -175,7 +175,9 @@ class registry final { * * @param additional_map the additional map to dispatch the class base. * Users can extend the map to fit their own - * LinOpFactory. + * LinOpFactory. We suggest using "usr::" as the + * prefix in the key to simply avoid conflict with + * ginkgo's map. */ registry(const configuration_map& additional_map = {}); @@ -194,7 +196,9 @@ class registry final { * ``` * @param additional_map the additional map to dispatch the class base. * Users can extend the map to fit their own - * LinOpFactory. + * LinOpFactory. We suggest using "usr::" as the + * prefix in the key to simply avoid conflict with + * ginkgo's map. */ registry( const std::unordered_map& stored_map,