Skip to content

Commit

Permalink
rename and disallow setting indextype
Browse files Browse the repository at this point in the history
  • Loading branch information
yhmtsai committed May 27, 2024
1 parent d69160c commit 331b357
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 56 deletions.
59 changes: 28 additions & 31 deletions core/test/config/factorization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
using namespace gko::config;


using Sparsity = gko::matrix::SparsityCsr<float, gko::int64>;
using Sparsity = gko::matrix::SparsityCsr<float, int>;


template <typename StrategyType>
Expand All @@ -46,21 +46,20 @@ inline void check_strategy(std::shared_ptr<StrategyType>& res,
}


template <typename ExplicitType, typename DefaultType>
template <typename ChangedType, typename DefaultType>
struct FactorizationConfigTest {
using explicit_type = ExplicitType;
using changed_type = ChangedType;
using default_type = DefaultType;
using factorization_config_test = FactorizationConfigTest;

static void change_template(pnode::map_type& config_map)
{
config_map["value_type"] = pnode{"float32"};
config_map["index_type"] = pnode{"int64"};
}
};


struct Ic : FactorizationConfigTest<gko::factorization::Ic<float, gko::int64>,
struct Ic : FactorizationConfigTest<gko::factorization::Ic<float, int>,
gko::factorization::Ic<double, int>> {
static pnode::map_type setup_base()
{
Expand All @@ -74,7 +73,7 @@ struct Ic : FactorizationConfigTest<gko::factorization::Ic<float, gko::int64>,
config_map["l_strategy"] = pnode{"sparselib"};
param.with_l_strategy(
std::make_shared<
typename gko::matrix::Csr<float, gko::int64>::sparselib>());
typename gko::matrix::Csr<float, int>::sparselib>());
config_map["skip_sorting"] = pnode{true};
param.with_skip_sorting(true);
config_map["both_factors"] = pnode{false};
Expand All @@ -94,7 +93,7 @@ struct Ic : FactorizationConfigTest<gko::factorization::Ic<float, gko::int64>,
};


struct Ilu : FactorizationConfigTest<gko::factorization::Ilu<float, gko::int64>,
struct Ilu : FactorizationConfigTest<gko::factorization::Ilu<float, int>,
gko::factorization::Ilu<double, int>> {
static pnode::map_type setup_base()
{
Expand All @@ -108,11 +107,11 @@ struct Ilu : FactorizationConfigTest<gko::factorization::Ilu<float, gko::int64>,
config_map["l_strategy"] = pnode{"sparselib"};
param.with_l_strategy(
std::make_shared<
typename gko::matrix::Csr<float, gko::int64>::sparselib>());
typename gko::matrix::Csr<float, int>::sparselib>());
config_map["u_strategy"] = pnode{"sparselib"};
param.with_u_strategy(
std::make_shared<
typename gko::matrix::Csr<float, gko::int64>::sparselib>());
typename gko::matrix::Csr<float, int>::sparselib>());
config_map["skip_sorting"] = pnode{true};
param.with_skip_sorting(true);
}
Expand All @@ -130,10 +129,9 @@ struct Ilu : FactorizationConfigTest<gko::factorization::Ilu<float, gko::int64>,
};


struct Cholesky
: FactorizationConfigTest<
gko::experimental::factorization::Cholesky<float, gko::int64>,
gko::experimental::factorization::Cholesky<double, int>> {
struct Cholesky : FactorizationConfigTest<
gko::experimental::factorization::Cholesky<float, int>,
gko::experimental::factorization::Cholesky<double, int>> {
static pnode::map_type setup_base()
{
return {{"type", pnode{"factorization::Cholesky"}}};
Expand Down Expand Up @@ -164,7 +162,7 @@ struct Cholesky


struct Lu : FactorizationConfigTest<
gko::experimental::factorization::Lu<float, gko::int64>,
gko::experimental::factorization::Lu<float, int>,
gko::experimental::factorization::Lu<double, int>> {
static pnode::map_type setup_base()
{
Expand Down Expand Up @@ -199,9 +197,8 @@ struct Lu : FactorizationConfigTest<
};


struct ParIc
: FactorizationConfigTest<gko::factorization::ParIc<float, gko::int64>,
gko::factorization::ParIc<double, int>> {
struct ParIc : FactorizationConfigTest<gko::factorization::ParIc<float, int>,
gko::factorization::ParIc<double, int>> {
static pnode::map_type setup_base()
{
return {{"type", pnode{"factorization::ParIc"}}};
Expand All @@ -218,7 +215,7 @@ struct ParIc
config_map["l_strategy"] = pnode{"sparselib"};
param.with_l_strategy(
std::make_shared<
typename gko::matrix::Csr<float, gko::int64>::sparselib>());
typename gko::matrix::Csr<float, int>::sparselib>());
config_map["both_factors"] = pnode{false};
param.with_both_factors(false);
}
Expand All @@ -238,7 +235,7 @@ struct ParIc


struct ParIlu
: FactorizationConfigTest<gko::factorization::ParIlu<float, gko::int64>,
: FactorizationConfigTest<gko::factorization::ParIlu<float, int>,
gko::factorization::ParIlu<double, int>> {
static pnode::map_type setup_base()
{
Expand All @@ -256,11 +253,11 @@ struct ParIlu
config_map["l_strategy"] = pnode{"sparselib"};
param.with_l_strategy(
std::make_shared<
typename gko::matrix::Csr<float, gko::int64>::sparselib>());
typename gko::matrix::Csr<float, int>::sparselib>());
config_map["u_strategy"] = pnode{"sparselib"};
param.with_u_strategy(
std::make_shared<
typename gko::matrix::Csr<float, gko::int64>::sparselib>());
typename gko::matrix::Csr<float, int>::sparselib>());
}

template <typename AnswerType>
Expand All @@ -278,7 +275,7 @@ struct ParIlu


struct ParIct
: FactorizationConfigTest<gko::factorization::ParIct<float, gko::int64>,
: FactorizationConfigTest<gko::factorization::ParIct<float, int>,
gko::factorization::ParIct<double, int>> {
static pnode::map_type setup_base()
{
Expand All @@ -296,7 +293,7 @@ struct ParIct
config_map["l_strategy"] = pnode{"sparselib"};
param.with_l_strategy(
std::make_shared<
typename gko::matrix::Csr<float, gko::int64>::sparselib>());
typename gko::matrix::Csr<float, int>::sparselib>());
config_map["approximate_select"] = pnode{false};
param.with_approximate_select(false);
config_map["deterministic_sample"] = pnode{true};
Expand All @@ -306,7 +303,7 @@ struct ParIct
config_map["lt_strategy"] = pnode{"sparselib"};
param.with_lt_strategy(
std::make_shared<
typename gko::matrix::Csr<float, gko::int64>::sparselib>());
typename gko::matrix::Csr<float, int>::sparselib>());
}

template <typename AnswerType>
Expand All @@ -328,7 +325,7 @@ struct ParIct


struct ParIlut
: FactorizationConfigTest<gko::factorization::ParIlut<float, gko::int64>,
: FactorizationConfigTest<gko::factorization::ParIlut<float, int>,
gko::factorization::ParIlut<double, int>> {
static pnode::map_type setup_base()
{
Expand All @@ -346,7 +343,7 @@ struct ParIlut
config_map["l_strategy"] = pnode{"sparselib"};
param.with_l_strategy(
std::make_shared<
typename gko::matrix::Csr<float, gko::int64>::sparselib>());
typename gko::matrix::Csr<float, int>::sparselib>());
config_map["approximate_select"] = pnode{false};
param.with_approximate_select(false);
config_map["deterministic_sample"] = pnode{true};
Expand All @@ -356,7 +353,7 @@ struct ParIlut
config_map["u_strategy"] = pnode{"sparselib"};
param.with_u_strategy(
std::make_shared<
typename gko::matrix::Csr<float, gko::int64>::sparselib>());
typename gko::matrix::Csr<float, int>::sparselib>());
}

template <typename AnswerType>
Expand Down Expand Up @@ -426,7 +423,7 @@ TYPED_TEST(Factorization, ExplicitTemplate)
auto config = pnode(config_map);

auto res = parse(config, this->reg, this->td).on(this->exec);
auto ans = Config::explicit_type::build().on(this->exec);
auto ans = Config::changed_type::build().on(this->exec);

Config::validate(res.get(), ans.get());
}
Expand All @@ -437,12 +434,12 @@ TYPED_TEST(Factorization, Set)
using Config = typename TestFixture::Config;
auto config_map = Config::setup_base();
Config::change_template(config_map);
auto param = Config::explicit_type::build();
Config::set(config_map, param, this->reg, this->exec);
auto params = Config::changed_type::build();
Config::set(config_map, params, this->reg, this->exec);
auto config = pnode(config_map);

auto res = parse(config, this->reg, this->td).on(this->exec);
auto ans = param.on(this->exec);
auto ans = params.on(this->exec);

Config::validate(res.get(), ans.get());
}
46 changes: 21 additions & 25 deletions core/test/config/preconditioner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ using namespace gko::config;
using DummyIr = gko::solver::Ir<float>;


template <typename ExplicitType, typename DefaultType>
template <typename ChangedType, typename DefaultType>
struct PreconditionerConfigTest {
using explicit_type = ExplicitType;
using changed_type = ChangedType;
using default_type = DefaultType;
using preconditioner_config_test = PreconditionerConfigTest;
static pnode::map_type setup_base()
Expand All @@ -42,7 +42,7 @@ struct PreconditionerConfigTest {


struct Ic : PreconditionerConfigTest<
::gko::preconditioner::Ic<DummyIr, gko::int64>,
::gko::preconditioner::Ic<DummyIr, int>,
::gko::preconditioner::Ic<gko::solver::LowerTrs<>, int>> {
static pnode::map_type setup_base()
{
Expand All @@ -53,7 +53,6 @@ struct Ic : PreconditionerConfigTest<
{
config_map["value_type"] = pnode{"float32"};
config_map["l_solver_type"] = pnode{"solver::Ir"};
config_map["index_type"] = pnode{"int64"};
}

template <bool from_reg, typename ParamType>
Expand All @@ -63,7 +62,7 @@ struct Ic : PreconditionerConfigTest<
if (from_reg) {
config_map["l_solver"] = pnode{"l_solver"};
param.with_l_solver(detail::registry_accessor::get_data<
typename explicit_type::l_solver_type::Factory>(
typename changed_type::l_solver_type::Factory>(
reg, "l_solver"));
config_map["factorization"] = pnode{"factorization"};
param.with_factorization(
Expand All @@ -72,7 +71,7 @@ struct Ic : PreconditionerConfigTest<
} else {
config_map["l_solver"] = pnode{{{"type", pnode{"solver::Ir"}},
{"value_type", pnode{"float32"}}}};
param.with_l_solver(explicit_type::l_solver_type::build().on(exec));
param.with_l_solver(changed_type::l_solver_type::build().on(exec));
config_map["factorization"] =
pnode{{{"type", pnode{"solver::Ir"}},
{"value_type", pnode{"float32"}}}};
Expand Down Expand Up @@ -106,7 +105,7 @@ struct Ic : PreconditionerConfigTest<

struct Ilu
: PreconditionerConfigTest<
::gko::preconditioner::Ilu<DummyIr, DummyIr, true, gko::int64>,
::gko::preconditioner::Ilu<DummyIr, DummyIr, true, int>,
::gko::preconditioner::Ilu<gko::solver::LowerTrs<>,
gko::solver::UpperTrs<>, false, int>> {
static pnode::map_type setup_base()
Expand All @@ -118,7 +117,6 @@ struct Ilu
{
config_map["value_type"] = pnode{"float32"};
config_map["l_solver_type"] = pnode{"solver::Ir"};
config_map["index_type"] = pnode{"int64"};
config_map["reverse_apply"] = pnode{true};
}

Expand All @@ -129,11 +127,11 @@ struct Ilu
if (from_reg) {
config_map["l_solver"] = pnode{"l_solver"};
param.with_l_solver(detail::registry_accessor::get_data<
typename explicit_type::l_solver_type::Factory>(
typename changed_type::l_solver_type::Factory>(
reg, "l_solver"));
config_map["u_solver"] = pnode{"u_solver"};
param.with_u_solver(detail::registry_accessor::get_data<
typename explicit_type::u_solver_type::Factory>(
typename changed_type::u_solver_type::Factory>(
reg, "u_solver"));
config_map["factorization"] = pnode{"factorization"};
param.with_factorization(
Expand All @@ -142,10 +140,10 @@ struct Ilu
} else {
config_map["l_solver"] = pnode{{{"type", pnode{"solver::Ir"}},
{"value_type", pnode{"float32"}}}};
param.with_l_solver(explicit_type::l_solver_type::build().on(exec));
param.with_l_solver(changed_type::l_solver_type::build().on(exec));
config_map["u_solver"] = pnode{{{"type", pnode{"solver::Ir"}},
{"value_type", pnode{"float32"}}}};
param.with_u_solver(explicit_type::u_solver_type::build().on(exec));
param.with_u_solver(changed_type::u_solver_type::build().on(exec));
config_map["factorization"] =
pnode{{{"type", pnode{"solver::Ir"}},
{"value_type", pnode{"float32"}}}};
Expand Down Expand Up @@ -185,7 +183,7 @@ struct Ilu
struct Isai
: PreconditionerConfigTest<
::gko::preconditioner::Isai<gko::preconditioner::isai_type::upper,
float, gko::int64>,
float, int>,
::gko::preconditioner::Isai<gko::preconditioner::isai_type::lower,
double, int>> {
static pnode::map_type setup_base()
Expand All @@ -198,7 +196,6 @@ struct Isai
{
config_map["isai_type"] = pnode{"upper"};
config_map["value_type"] = pnode{"float32"};
config_map["index_type"] = pnode{"int64"};
}

template <bool from_reg, typename ParamType>
Expand All @@ -213,7 +210,7 @@ struct Isai
param.with_excess_limit(32u);
config_map["excess_solver_reduction"] = pnode{1e-4};
param.with_excess_solver_reduction(
gko::remove_complex<typename explicit_type::value_type>{1e-4});
gko::remove_complex<typename changed_type::value_type>{1e-4});
if (from_reg) {
config_map["excess_solver_factory"] = pnode{"solver"};
param.with_excess_solver_factory(
Expand Down Expand Up @@ -252,7 +249,7 @@ struct Isai


struct Jacobi
: PreconditionerConfigTest<::gko::preconditioner::Jacobi<float, gko::int64>,
: PreconditionerConfigTest<::gko::preconditioner::Jacobi<float, int>,
::gko::preconditioner::Jacobi<double, int>> {
static pnode::map_type setup_base()
{
Expand All @@ -262,7 +259,6 @@ struct Jacobi
static void change_template(pnode::map_type& config_map)
{
config_map["value_type"] = pnode{"float32"};
config_map["index_type"] = pnode{"int64"};
}

template <bool from_reg, typename ParamType>
Expand All @@ -280,7 +276,7 @@ struct Jacobi
param.with_storage_optimization(gko::precision_reduction(0, 1));
config_map["accuracy"] = pnode{1e-2};
param.with_accuracy(
gko::remove_complex<typename explicit_type::value_type>{1e-2});
gko::remove_complex<typename changed_type::value_type>{1e-2});
}

template <bool from_reg, typename AnswerType>
Expand Down Expand Up @@ -360,7 +356,7 @@ TYPED_TEST(Preconditioner, ExplicitTemplate)
auto config = pnode(config_map);

auto res = parse(config, this->reg, this->td).on(this->exec);
auto ans = Config::explicit_type::build().on(this->exec);
auto ans = Config::changed_type::build().on(this->exec);

Config::template validate<true>(res.get(), ans.get());
}
Expand All @@ -371,12 +367,12 @@ TYPED_TEST(Preconditioner, SetFromRegistry)
using Config = typename TestFixture::Config;
auto config_map = Config::setup_base();
Config::change_template(config_map);
auto param = Config::explicit_type::build();
Config::template set<true>(config_map, param, this->reg, this->exec);
auto params = Config::changed_type::build();
Config::template set<true>(config_map, params, this->reg, this->exec);
auto config = pnode(config_map);

auto res = parse(config, this->reg, this->td).on(this->exec);
auto ans = param.on(this->exec);
auto ans = params.on(this->exec);

Config::template validate<true>(res.get(), ans.get());
}
Expand All @@ -387,12 +383,12 @@ TYPED_TEST(Preconditioner, SetFromConfig)
using Config = typename TestFixture::Config;
auto config_map = Config::setup_base();
Config::change_template(config_map);
auto param = Config::explicit_type::build();
Config::template set<false>(config_map, param, this->reg, this->exec);
auto params = Config::changed_type::build();
Config::template set<false>(config_map, params, this->reg, this->exec);
auto config = pnode(config_map);

auto res = parse(config, this->reg, this->td).on(this->exec);
auto ans = param.on(this->exec);
auto ans = params.on(this->exec);

Config::template validate<false>(res.get(), ans.get());
}

0 comments on commit 331b357

Please sign in to comment.