diff --git a/core/config/config.cpp b/core/config/config.cpp index 8c97c0038ed..160f88ce65c 100644 --- a/core/config/config.cpp +++ b/core/config/config.cpp @@ -29,7 +29,7 @@ deferred_factory_parameter parse(const pnode& config, obj.get_string()); return func(config, context, td); } - GKO_INVALID_STATE("Should contain type property"); + GKO_MISS_CONFIG_ENTRY("type"); } diff --git a/core/config/config_helper.hpp b/core/config/config_helper.hpp index 4add55e2385..9de08a94ccd 100644 --- a/core/config/config_helper.hpp +++ b/core/config/config_helper.hpp @@ -10,7 +10,6 @@ #include -#include #include #include #include @@ -27,6 +26,15 @@ namespace gko { namespace config { +#define GKO_INVALID_CONFIG_VALUE(_entry, _value) \ + GKO_INVALID_STATE(_value + std::string(" is invalid for the entry ") + \ + _entry) + + +#define GKO_MISS_CONFIG_ENTRY(_entry) \ + GKO_INVALID_STATE(std::string("miss the entry ") + _entry) + + /** * LinOpFactoryType enum is to avoid forward declaration, linopfactory header, * two template versions of parse @@ -257,7 +265,7 @@ get_value(const pnode& config) } else if (val == "provided") { return solver::initial_guess_mode::provided; } - GKO_INVALID_STATE("Wrong value for initial_guess_mode"); + GKO_INVALID_CONFIG_VALUE("default_initial_guess", val); } @@ -275,31 +283,6 @@ get_value(const pnode& config) } -// template -// struct is_array_t : std::false_type {}; - -// template -// struct is_array_t> : std::true_type {}; - -// template -// inline typename std::enable_if::value, ArrayType>::type -// get_value(const pnode& config, std::shared_ptr exec) -// { -// using T = typename ArrayType::value_type; -// std::vector res; -// // for loop in config -// if (config.get_tag() == pnode::tag_t::array) { -// for (const auto& it : config.get_array()) { -// res.push_back(get_value(it)); -// } -// } else { -// // only one config can be passed without array -// res.push_back(get_value(config)); -// } -// return ArrayType(exec, res.begin(), res.end()); -// } - - template inline std::shared_ptr get_strategy( const pnode& config) diff --git a/core/config/preconditioner_config.cpp b/core/config/preconditioner_config.cpp index 40cae59f096..a59b903f791 100644 --- a/core/config/preconditioner_config.cpp +++ b/core/config/preconditioner_config.cpp @@ -136,7 +136,7 @@ deferred_factory_parameter parse( make_type_selector(updated.get_value_typestr(), value_type_list()), make_type_selector(updated.get_index_typestr(), index_type_list())); } else { - GKO_INVALID_STATE("does not have valid LSolverType"); + GKO_INVALID_CONFIG_VALUE("l_solver_type", str); } } @@ -221,7 +221,7 @@ deferred_factory_parameter parse( make_type_selector(updated.get_index_typestr(), index_type_list())); } else { - GKO_INVALID_STATE("does not have valid LSolverType"); + GKO_INVALID_CONFIG_VALUE("l_solver_type", str); } }; bool reverse_apply = false; @@ -280,10 +280,10 @@ deferred_factory_parameter parse( make_type_selector(updated.get_index_typestr(), index_type_list())); } else { - GKO_INVALID_STATE("does not have valid IsaiType"); + GKO_INVALID_CONFIG_VALUE("isai_type", str); } } else { - GKO_INVALID_STATE("does not contain IsaiType"); + GKO_MISS_CONFIG_ENTRY("isai_type"); } } diff --git a/core/config/stop_config.cpp b/core/config/stop_config.cpp index 63148cbfcd9..9980b7a8743 100644 --- a/core/config/stop_config.cpp +++ b/core/config/stop_config.cpp @@ -55,7 +55,7 @@ inline stop::mode get_mode(const std::string& str) } else if (str == "rhs_norm") { return stop::mode::rhs_norm; } - GKO_INVALID_STATE("Not valid " + str); + GKO_INVALID_CONFIG_VALUE("baseline", str); } diff --git a/core/factorization/cholesky.cpp b/core/factorization/cholesky.cpp index f0035e9a1f5..63bbde4f2fd 100644 --- a/core/factorization/cholesky.cpp +++ b/core/factorization/cholesky.cpp @@ -45,8 +45,6 @@ Cholesky::parse( const config::pnode& config, const config::registry& context, const config::type_descriptor& td_for_child) { - using sparsity_pattern_type = - Cholesky::sparsity_pattern_type; auto params = Cholesky::build(); if (auto& obj = config.get("symbolic_factorization")) { params.with_symbolic_factorization( diff --git a/core/factorization/ic.cpp b/core/factorization/ic.cpp index cb32bd529fe..763a6364d09 100644 --- a/core/factorization/ic.cpp +++ b/core/factorization/ic.cpp @@ -45,8 +45,6 @@ Ic::parse(const config::pnode& config, const config::registry& context, const config::type_descriptor& td_for_child) { - using matrix_type = - typename factorization::Ic::matrix_type; auto params = factorization::Ic::build(); if (auto& obj = config.get("l_strategy")) { params.with_l_strategy(config::get_strategy(obj)); diff --git a/core/factorization/ilu.cpp b/core/factorization/ilu.cpp index eb60026e746..5ae4ccb9654 100644 --- a/core/factorization/ilu.cpp +++ b/core/factorization/ilu.cpp @@ -45,8 +45,6 @@ Ilu::parse(const config::pnode& config, const config::registry& context, const config::type_descriptor& td_for_child) { - using matrix_type = - typename factorization::Ilu::matrix_type; auto params = factorization::Ilu::build(); if (auto& obj = config.get("l_strategy")) { params.with_l_strategy(config::get_strategy(obj)); diff --git a/core/factorization/lu.cpp b/core/factorization/lu.cpp index 933979e15cd..e0da4ceb429 100644 --- a/core/factorization/lu.cpp +++ b/core/factorization/lu.cpp @@ -49,8 +49,6 @@ Lu::parse(const config::pnode& config, const config::registry& context, const config::type_descriptor& td_for_child) { - using sparsity_pattern_type = typename experimental::factorization::Lu< - ValueType, IndexType>::sparsity_pattern_type; auto params = experimental::factorization::Lu::build(); @@ -67,7 +65,7 @@ Lu::parse(const config::pnode& config, } else if (str == "symmetric") { params.with_symbolic_algorithm(symbolic_type::symmetric); } else { - GKO_INVALID_STATE("Wrong value for symbolic_type"); + GKO_INVALID_CONFIG_VALUE("symbolic_type", str); } } if (auto& obj = config.get("skip_sorting")) { diff --git a/core/factorization/par_ic.cpp b/core/factorization/par_ic.cpp index 9a7b7c693c4..3bd415257f7 100644 --- a/core/factorization/par_ic.cpp +++ b/core/factorization/par_ic.cpp @@ -54,8 +54,6 @@ ParIc::parse(const config::pnode& config, const config::registry& context, const config::type_descriptor& td_for_child) { - using matrix_type = - typename factorization::ParIc::matrix_type; auto params = factorization::ParIc::build(); if (auto& obj = config.get("iterations")) { diff --git a/core/factorization/par_ict.cpp b/core/factorization/par_ict.cpp index 4b362a82747..8a7f8297f7e 100644 --- a/core/factorization/par_ict.cpp +++ b/core/factorization/par_ict.cpp @@ -153,8 +153,6 @@ ParIct::parse(const config::pnode& config, const config::registry& context, const config::type_descriptor& td_for_child) { - using matrix_type = - typename factorization::ParIct::matrix_type; auto params = factorization::ParIct::build(); if (auto& obj = config.get("iterations")) { diff --git a/core/factorization/par_ilu.cpp b/core/factorization/par_ilu.cpp index 0070d6ec9f0..963b085d76f 100644 --- a/core/factorization/par_ilu.cpp +++ b/core/factorization/par_ilu.cpp @@ -51,8 +51,6 @@ ParIlu::parse(const config::pnode& config, const config::registry& context, const config::type_descriptor& td_for_child) { - using matrix_type = - typename factorization::ParIlu::matrix_type; auto params = factorization::ParIlu::build(); if (auto& obj = config.get("iterations")) { diff --git a/core/factorization/par_ilut.cpp b/core/factorization/par_ilut.cpp index 4fecdff66e4..da45642490b 100644 --- a/core/factorization/par_ilut.cpp +++ b/core/factorization/par_ilut.cpp @@ -169,8 +169,6 @@ ParIlut::parse( const config::pnode& config, const config::registry& context, const config::type_descriptor& td_for_child) { - using matrix_type = - typename factorization::ParIlut::matrix_type; auto params = factorization::ParIlut::build(); if (auto& obj = config.get("iterations")) { diff --git a/core/preconditioner/ic.cpp b/core/preconditioner/ic.cpp index 44dff46c94d..366e891f22c 100644 --- a/core/preconditioner/ic.cpp +++ b/core/preconditioner/ic.cpp @@ -35,8 +35,9 @@ Ic::parse(const config::pnode& config, td_for_child)); } if (auto& obj = config.get("factorization")) { - params.with_factorization(gko::config::get_factory( - obj, context, td_for_child)); + params.with_factorization( + gko::config::build_or_get_factory( + obj, context, td_for_child)); } return params; diff --git a/core/preconditioner/ilu.cpp b/core/preconditioner/ilu.cpp index ff92132db75..8248739dc51 100644 --- a/core/preconditioner/ilu.cpp +++ b/core/preconditioner/ilu.cpp @@ -43,8 +43,9 @@ Ilu::parse( td_for_child)); } if (auto& obj = config.get("factorization")) { - params.with_factorization(gko::config::get_factory( - obj, context, td_for_child)); + params.with_factorization( + gko::config::build_or_get_factory( + obj, context, td_for_child)); } return params; diff --git a/core/preconditioner/isai.cpp b/core/preconditioner/isai.cpp index d1f8a4ee113..e6cd16b872d 100644 --- a/core/preconditioner/isai.cpp +++ b/core/preconditioner/isai.cpp @@ -114,8 +114,8 @@ Isai::parse( } if (auto& obj = config.get("excess_solver_factory")) { params.with_excess_solver_factory( - gko::config::get_factory(obj, context, - td_for_child)); + gko::config::build_or_get_factory( + obj, context, td_for_child)); } if (auto& obj = config.get("excess_solver_reduction")) { params.with_excess_solver_reduction( diff --git a/core/preconditioner/jacobi.cpp b/core/preconditioner/jacobi.cpp index 631d4fd5e87..861c7afb5af 100644 --- a/core/preconditioner/jacobi.cpp +++ b/core/preconditioner/jacobi.cpp @@ -71,16 +71,10 @@ Jacobi::parse(const config::pnode& config, if (auto& obj = config.get("skip_sorting")) { params.with_skip_sorting(gko::config::get_value(obj)); } - // SET_VALUE_ARRAY(factory, gko::array, block_pointers, - // config); // storage_optimization_type is not public. It uses precision_reduction - // as input. Also, it allows value and array input - // Each precision_reduction is created by two values. - // [x, y] -> one precision_reduction (value mode) - // [[x, y], ...] -> array mode + // as input. It allows value and array input, but we only support the value + // input [x, y] -> one precision_reduction (value mode) if (auto& obj = config.get("storage_optimization")) { - // only support value mode - // TODO: more than one precision_reduction -> array mode. params.with_storage_optimization( gko::config::get_value(obj)); } diff --git a/core/solver/cb_gmres.cpp b/core/solver/cb_gmres.cpp index 6e2608e5c47..57dc380dcfd 100644 --- a/core/solver/cb_gmres.cpp +++ b/core/solver/cb_gmres.cpp @@ -185,7 +185,7 @@ typename CbGmres::parameters_type CbGmres::parse( } else if (str == "ireduce2") { return storage_precision::ireduce2; } - GKO_INVALID_STATE("Wrong value for storage_precision"); + GKO_INVALID_CONFIG_VALUE("storage_precision", str); }; factory.with_storage_precision(get_storage_precision(obj.get_string())); } diff --git a/core/solver/lower_trs.cpp b/core/solver/lower_trs.cpp index 932602c3f27..26acd34c747 100644 --- a/core/solver/lower_trs.cpp +++ b/core/solver/lower_trs.cpp @@ -56,7 +56,7 @@ LowerTrs::parse( } else if (str == "syncfree") { factory.with_algorithm(trisolve_algorithm::syncfree); } else { - GKO_INVALID_STATE("Wrong value for algorithm"); + GKO_INVALID_CONFIG_VALUE("algorithm", str); } } return factory; diff --git a/core/solver/upper_trs.cpp b/core/solver/upper_trs.cpp index 089513c5d97..756cda69b52 100644 --- a/core/solver/upper_trs.cpp +++ b/core/solver/upper_trs.cpp @@ -56,7 +56,7 @@ UpperTrs::parse( } else if (str == "syncfree") { factory.with_algorithm(trisolve_algorithm::syncfree); } else { - GKO_INVALID_STATE("Wrong value for algorithm"); + GKO_INVALID_CONFIG_VALUE("algorithm", str); } } return factory; diff --git a/core/test/config/preconditioner.cpp b/core/test/config/preconditioner.cpp index e7f66c74168..5302e23249a 100644 --- a/core/test/config/preconditioner.cpp +++ b/core/test/config/preconditioner.cpp @@ -212,7 +212,8 @@ struct Isai config_map["excess_limit"] = pnode{32}; param.with_excess_limit(32u); config_map["excess_solver_reduction"] = pnode{1e-4}; - param.with_excess_solver_reduction(1e-4); + param.with_excess_solver_reduction( + gko::remove_complex{1e-4}); if (from_reg) { config_map["excess_solver_factory"] = pnode{"solver"}; param.with_excess_solver_factory( @@ -268,8 +269,8 @@ struct Jacobi static void set(pnode::map_type& config_map, ParamType& param, registry reg, std::shared_ptr exec) { - config_map["max_block_size"] = pnode{32}; - param.with_max_block_size(32u); + config_map["max_block_size"] = pnode{16}; + param.with_max_block_size(16u); config_map["max_block_stride"] = pnode{32u}; param.with_max_block_stride(32u); config_map["skip_sorting"] = pnode{true}; @@ -280,7 +281,8 @@ struct Jacobi pnode{std::vector{pnode{0}, pnode{1}}}; param.with_storage_optimization(gko::precision_reduction(0, 1)); config_map["accuracy"] = pnode{1e-2}; - param.with_accuracy(1e-2); + param.with_accuracy( + gko::remove_complex{1e-2}); } template @@ -304,23 +306,6 @@ struct Jacobi }; -// struct JacobiByArray : Jacobi { -// template -// static void set(pnode::map_type& config_map, ParamType& param, registry -// reg, -// std::shared_ptr exec) -// { -// Jacobi::template set(config_map, param, reg, exec); -// using pvec = std::vector; -// config_map["storage_optimization"] = -// pnode{pvec{pvec{{0}, {1}}, pvec{{0}, {0}}, pvec{{1}, {1}}}}; -// using pr = gko::precision_reduction; -// gko::array storage(exec, {pr(0, 1), pr(0, 0), pr(1, 1)}); -// param.with_storage_optimization(storage); -// } -// }; - - template class Preconditioner : public ::testing::Test { protected: diff --git a/include/ginkgo/core/factorization/cholesky.hpp b/include/ginkgo/core/factorization/cholesky.hpp index 8dbb9e06710..34cfb6aa8ed 100644 --- a/include/ginkgo/core/factorization/cholesky.hpp +++ b/include/ginkgo/core/factorization/cholesky.hpp @@ -95,12 +95,13 @@ class Cholesky /** * 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/factorization/ic.hpp b/include/ginkgo/core/factorization/ic.hpp index f346aa7e736..170297ffa0b 100644 --- a/include/ginkgo/core/factorization/ic.hpp +++ b/include/ginkgo/core/factorization/ic.hpp @@ -107,12 +107,13 @@ class Ic : public Composition { /** * 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/factorization/ilu.hpp b/include/ginkgo/core/factorization/ilu.hpp index c39abb2b74e..785faadd65a 100644 --- a/include/ginkgo/core/factorization/ilu.hpp +++ b/include/ginkgo/core/factorization/ilu.hpp @@ -102,12 +102,13 @@ class Ilu : public Composition { /** * 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/factorization/lu.hpp b/include/ginkgo/core/factorization/lu.hpp index e02e62a5f93..9a4f2029970 100644 --- a/include/ginkgo/core/factorization/lu.hpp +++ b/include/ginkgo/core/factorization/lu.hpp @@ -125,12 +125,13 @@ class Lu /** * 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/factorization/par_ic.hpp b/include/ginkgo/core/factorization/par_ic.hpp index 24291356c5a..1b49ce83edc 100644 --- a/include/ginkgo/core/factorization/par_ic.hpp +++ b/include/ginkgo/core/factorization/par_ic.hpp @@ -140,12 +140,13 @@ class ParIc : public Composition { /** * 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/factorization/par_ict.hpp b/include/ginkgo/core/factorization/par_ict.hpp index 4d9714b8dd6..9d0b194a69a 100644 --- a/include/ginkgo/core/factorization/par_ict.hpp +++ b/include/ginkgo/core/factorization/par_ict.hpp @@ -189,12 +189,13 @@ class ParIct : public Composition { /** * 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/factorization/par_ilu.hpp b/include/ginkgo/core/factorization/par_ilu.hpp index 352721bf5c4..1497b8c3574 100644 --- a/include/ginkgo/core/factorization/par_ilu.hpp +++ b/include/ginkgo/core/factorization/par_ilu.hpp @@ -138,12 +138,13 @@ class ParIlu : public Composition { /** * 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/factorization/par_ilut.hpp b/include/ginkgo/core/factorization/par_ilut.hpp index 457e8b7ad0f..24136b089a8 100644 --- a/include/ginkgo/core/factorization/par_ilut.hpp +++ b/include/ginkgo/core/factorization/par_ilut.hpp @@ -195,12 +195,13 @@ class ParIlut : public Composition { /** * 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/preconditioner/ic.hpp b/include/ginkgo/core/preconditioner/ic.hpp index d1aff58dcab..e505d04731e 100644 --- a/include/ginkgo/core/preconditioner/ic.hpp +++ b/include/ginkgo/core/preconditioner/ic.hpp @@ -165,12 +165,13 @@ class Ic : public EnableLinOp>, public Transposable { /** * 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/preconditioner/ilu.hpp b/include/ginkgo/core/preconditioner/ilu.hpp index 10f0b9bdee6..3174b31cf0e 100644 --- a/include/ginkgo/core/preconditioner/ilu.hpp +++ b/include/ginkgo/core/preconditioner/ilu.hpp @@ -208,12 +208,13 @@ class Ilu : 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/preconditioner/isai.hpp b/include/ginkgo/core/preconditioner/isai.hpp index 2e77aa7a578..8d3fb044d49 100644 --- a/include/ginkgo/core/preconditioner/isai.hpp +++ b/include/ginkgo/core/preconditioner/isai.hpp @@ -198,12 +198,13 @@ class Isai : 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/preconditioner/jacobi.hpp b/include/ginkgo/core/preconditioner/jacobi.hpp index 48b3c369f7a..f6ee3de5de1 100644 --- a/include/ginkgo/core/preconditioner/jacobi.hpp +++ b/include/ginkgo/core/preconditioner/jacobi.hpp @@ -504,12 +504,13 @@ class Jacobi : 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 */