Skip to content

Commit

Permalink
update documentation and move the macro
Browse files Browse the repository at this point in the history
Co-authored-by: Marcel Koch <marcel.koch@kit.edu>
  • Loading branch information
yhmtsai and MarcelKoch committed May 17, 2024
1 parent 399b6b3 commit 2410d2d
Show file tree
Hide file tree
Showing 15 changed files with 131 additions and 102 deletions.
61 changes: 61 additions & 0 deletions core/config/parse_macro.hpp
Original file line number Diff line number Diff line change
@@ -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 <ginkgo/core/config/config.hpp>
#include <ginkgo/core/config/registry.hpp>
#include <ginkgo/core/config/type_descriptor.hpp>


#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<gko::LinOpFactory> \
parse<gko::config::LinOpFactoryType::_type>( \
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<gko::LinOpFactory, _configurator>( \
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<gko::LinOpFactory> \
parse<gko::config::LinOpFactoryType::_type>( \
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<gko::LinOpFactory, _configurator>( \
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_
73 changes: 14 additions & 59 deletions core/config/solver_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<gko::LinOpFactory> \
parse<LinOpFactoryType::_type>(const pnode& config, \
const registry& context, \
const type_descriptor& td) \
{ \
auto updated = update_type(config, td); \
return dispatch<gko::LinOpFactory, gko::solver::_type>( \
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<gko::LinOpFactory> parse<LinOpFactoryType::Direct>(
const pnode& config, const registry& context, const type_descriptor& td)
{
auto updated = update_type(config, td);
return dispatch<gko::LinOpFactory, gko::experimental::solver::Direct>(
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<gko::LinOpFactory> parse<LinOpFactoryType::LowerTrs>(
const pnode& config, const registry& context, const type_descriptor& td)
{
auto updated = update_type(config, td);
return dispatch<gko::LinOpFactory, gko::solver::LowerTrs>(
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<gko::LinOpFactory> parse<LinOpFactoryType::UpperTrs>(
const pnode& config, const registry& context, const type_descriptor& td)
{
auto updated = update_type(config, td);
return dispatch<gko::LinOpFactory, gko::solver::UpperTrs>(
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
Expand Down
34 changes: 17 additions & 17 deletions core/test/config/solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ struct SolverConfigTest {
detail::registry_accessor::get_data<gko::LinOpFactory>(
reg, "linop_factory"));
} else {
config_map["criteria"] = pnode{std::map<std::string, pnode>{
{"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"}},
Expand Down Expand Up @@ -106,7 +106,7 @@ struct SolverConfigTest {
struct Cg : SolverConfigTest<gko::solver::Cg<float>, gko::solver::Cg<double>> {
static pnode::map_type setup_base()
{
return pnode::map_type{{"type", pnode{"solver::Cg"}}};
return {{"type", pnode{"solver::Cg"}}};
}
};

Expand All @@ -115,7 +115,7 @@ struct Cgs
: SolverConfigTest<gko::solver::Cgs<float>, gko::solver::Cgs<double>> {
static pnode::map_type setup_base()
{
return pnode::map_type{{"type", pnode{"solver::Cgs"}}};
return {{"type", pnode{"solver::Cgs"}}};
}
};

Expand All @@ -124,7 +124,7 @@ struct Fcg
: SolverConfigTest<gko::solver::Fcg<float>, gko::solver::Fcg<double>> {
static pnode::map_type setup_base()
{
return pnode::map_type{{"type", pnode{"solver::Fcg"}}};
return {{"type", pnode{"solver::Fcg"}}};
}
};

Expand All @@ -133,7 +133,7 @@ struct Bicg
: SolverConfigTest<gko::solver::Bicg<float>, gko::solver::Bicg<double>> {
static pnode::map_type setup_base()
{
return pnode::map_type{{"type", pnode{"solver::Bicg"}}};
return {{"type", pnode{"solver::Bicg"}}};
}
};

Expand All @@ -142,15 +142,15 @@ struct Bicgstab : SolverConfigTest<gko::solver::Bicgstab<float>,
gko::solver::Bicgstab<double>> {
static pnode::map_type setup_base()
{
return pnode::map_type{{"type", pnode{"solver::Bicgstab"}}};
return {{"type", pnode{"solver::Bicgstab"}}};
}
};


struct Ir : SolverConfigTest<gko::solver::Ir<float>, gko::solver::Ir<double>> {
static pnode::map_type setup_base()
{
return pnode::map_type{{"type", pnode{"solver::Ir"}}};
return {{"type", pnode{"solver::Ir"}}};
}

template <bool from_reg, typename ParamType>
Expand All @@ -174,8 +174,8 @@ struct Ir : SolverConfigTest<gko::solver::Ir<float>, gko::solver::Ir<double>> {
detail::registry_accessor::get_data<gko::LinOpFactory>(
reg, "linop_factory"));
} else {
config_map["criteria"] = pnode{std::map<std::string, pnode>{
{"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"}}}};
Expand Down Expand Up @@ -214,7 +214,7 @@ struct Idr
: SolverConfigTest<gko::solver::Idr<float>, gko::solver::Idr<double>> {
static pnode::map_type setup_base()
{
return pnode::map_type{{"type", pnode{"solver::Idr"}}};
return {{"type", pnode{"solver::Idr"}}};
}

template <bool from_reg, typename ParamType>
Expand Down Expand Up @@ -252,7 +252,7 @@ struct Gcr
: SolverConfigTest<gko::solver::Gcr<float>, gko::solver::Gcr<double>> {
static pnode::map_type setup_base()
{
return pnode::map_type{{"type", pnode{"solver::Gcr"}}};
return {{"type", pnode{"solver::Gcr"}}};
}

template <bool from_reg, typename ParamType>
Expand Down Expand Up @@ -281,7 +281,7 @@ struct Gmres
: SolverConfigTest<gko::solver::Gmres<float>, gko::solver::Gmres<double>> {
static pnode::map_type setup_base()
{
return pnode::map_type{{"type", pnode{"solver::Gmres"}}};
return {{"type", pnode{"solver::Gmres"}}};
}

template <bool from_reg, typename ParamType>
Expand Down Expand Up @@ -313,7 +313,7 @@ struct CbGmres : SolverConfigTest<gko::solver::CbGmres<float>,
gko::solver::CbGmres<double>> {
static pnode::map_type setup_base()
{
return pnode::map_type{{"type", pnode{"solver::CbGmres"}}};
return {{"type", pnode{"solver::CbGmres"}}};
}

template <bool from_reg, typename ParamType>
Expand Down Expand Up @@ -347,7 +347,7 @@ struct Direct
gko::experimental::solver::Direct<double, int>> {
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)
Expand Down Expand Up @@ -430,15 +430,15 @@ struct TrsHelper : SolverConfigTest<Trs<float, gko::int64>, Trs<double, int>> {
struct LowerTrs : TrsHelper<gko::solver::LowerTrs> {
static pnode::map_type setup_base()
{
return pnode::map_type{{"type", pnode{"solver::LowerTrs"}}};
return {{"type", pnode{"solver::LowerTrs"}}};
}
};


struct UpperTrs : TrsHelper<gko::solver::UpperTrs> {
static pnode::map_type setup_base()
{
return pnode::map_type{{"type", pnode{"solver::UpperTrs"}}};
return {{"type", pnode{"solver::UpperTrs"}}};
}
};

Expand Down
5 changes: 3 additions & 2 deletions include/ginkgo/core/solver/bicg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
5 changes: 3 additions & 2 deletions include/ginkgo/core/solver/bicgstab.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
5 changes: 3 additions & 2 deletions include/ginkgo/core/solver/cb_gmres.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,13 @@ class CbGmres : public EnableLinOp<CbGmres<ValueType>>,
/**
* 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
*/
Expand Down
5 changes: 3 additions & 2 deletions include/ginkgo/core/solver/cg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,13 @@ class Cg : public EnableLinOp<Cg<ValueType>>,
/**
* 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
*/
Expand Down
5 changes: 3 additions & 2 deletions include/ginkgo/core/solver/cgs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
5 changes: 3 additions & 2 deletions include/ginkgo/core/solver/direct.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,13 @@ class Direct : public EnableLinOp<Direct<ValueType, IndexType>>,
/**
* 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
*/
Expand Down
5 changes: 3 additions & 2 deletions include/ginkgo/core/solver/fcg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Loading

0 comments on commit 2410d2d

Please sign in to comment.