Skip to content

Commit

Permalink
update documentation and remove stop:: and index_type
Browse files Browse the repository at this point in the history
Co-authored-by: Marcel Koch <[email protected]>
Co-authored-by: Tobias Ribizel <[email protected]>
  • Loading branch information
3 people committed May 23, 2024
1 parent 1bf7def commit 7735cc5
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 26 deletions.
21 changes: 8 additions & 13 deletions core/config/config_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,14 @@ parse_or_get_factory<const LinOpFactory>(const pnode& config,
const registry& context,
const type_descriptor& td)
{
deferred_factory_parameter<const LinOpFactory> ptr;
if (config.get_tag() == pnode::tag_t::string) {
ptr = detail::registry_accessor::get_data<LinOpFactory>(
return detail::registry_accessor::get_data<LinOpFactory>(
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;
}


Expand All @@ -45,7 +41,6 @@ parse_or_get_factory<const stop::CriterionFactory>(const pnode& config,
const registry& context,
const type_descriptor& td)
{
deferred_factory_parameter<const stop::CriterionFactory> ptr;
if (config.get_tag() == pnode::tag_t::string) {
return detail::registry_accessor::get_data<stop::CriterionFactory>(
context, config.get_string());
Expand All @@ -55,15 +50,15 @@ parse_or_get_factory<const stop::CriterionFactory>(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
Expand Down
7 changes: 6 additions & 1 deletion core/config/type_descriptor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#include <ginkgo/core/config/type_descriptor.hpp>


#include <ginkgo/core/base/exception_helpers.hpp>


#include "core/config/type_descriptor_helper.hpp"


Expand All @@ -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};
}
Expand Down
3 changes: 1 addition & 2 deletions core/test/config/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ class Config : public ::testing::Test {
: exec(gko::ReferenceExecutor::create()),
mtx(gko::initialize<Mtx>(
{{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<const gko::Executor> exec;
Expand Down
15 changes: 7 additions & 8 deletions include/ginkgo/core/config/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_<key>(value)`, then the configuration
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down
8 changes: 6 additions & 2 deletions include/ginkgo/core/config/registry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {});

Expand All @@ -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<std::string, detail::allowed_ptr>& stored_map,
Expand Down

0 comments on commit 7735cc5

Please sign in to comment.