Skip to content

Commit

Permalink
check preconditioner config key
Browse files Browse the repository at this point in the history
  • Loading branch information
yhmtsai committed Feb 19, 2025
1 parent e96496d commit ec6eda5
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 9 deletions.
12 changes: 10 additions & 2 deletions core/preconditioner/gauss_seidel.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
//
// SPDX-License-Identifier: BSD-3-Clause

#include <ginkgo/core/preconditioner/gauss_seidel.hpp>
#include "ginkgo/core/preconditioner/gauss_seidel.hpp"

#include <set>
#include <string>

#include <ginkgo/core/preconditioner/sor.hpp>

#include "core/config/config_helper.hpp"
Expand All @@ -18,6 +22,10 @@ GaussSeidel<ValueType, IndexType>::parse(
const config::pnode& config, const config::registry& context,
const config::type_descriptor& td_for_child)
{
std::set<std::string> allowed_keys{"skip_sorting", "symmetric", "l_solver",
"u_solver"};
gko::config::check_allowed_keys(config, allowed_keys);

auto params = GaussSeidel::build();

if (auto& obj = config.get("skip_sorting")) {
Expand Down
8 changes: 7 additions & 1 deletion core/preconditioner/ic.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
//
// SPDX-License-Identifier: BSD-3-Clause

#include "ginkgo/core/preconditioner/ic.hpp"

#include <set>
#include <string>

#include <ginkgo/core/base/types.hpp>
#include <ginkgo/core/config/config.hpp>
#include <ginkgo/core/config/registry.hpp>
Expand All @@ -27,6 +30,9 @@ typename Ic::parameters_type ic_parse(
const config::pnode& config, const config::registry& context,
const config::type_descriptor& td_for_child)
{
std::set<std::string> allowed_keys{"l_solver", "factorization"};
gko::config::check_allowed_keys(config, allowed_keys);

auto params = Ic::build();

if (auto& obj = config.get("l_solver")) {
Expand Down
8 changes: 7 additions & 1 deletion core/preconditioner/ilu.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
//
// SPDX-License-Identifier: BSD-3-Clause

#include "ginkgo/core/preconditioner/ilu.hpp"

#include <set>
#include <string>

#include <ginkgo/core/base/types.hpp>
#include <ginkgo/core/config/config.hpp>
#include <ginkgo/core/config/registry.hpp>
Expand All @@ -29,6 +32,9 @@ typename Ilu::parameters_type ilu_parse(
const config::pnode& config, const config::registry& context,
const config::type_descriptor& td_for_child)
{
std::set<std::string> allowed_keys{"l_solver", "u_solver", "factorization"};
gko::config::check_allowed_keys(config, allowed_keys);

auto params = Ilu::build();

if (auto& obj = config.get("l_solver")) {
Expand Down
9 changes: 8 additions & 1 deletion core/preconditioner/isai.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
//
// SPDX-License-Identifier: BSD-3-Clause

#include "ginkgo/core/preconditioner/isai.hpp"

#include <functional>
#include <memory>
#include <set>
#include <string>
#include <type_traits>

#include <ginkgo/core/base/exception_helpers.hpp>
Expand Down Expand Up @@ -98,6 +100,11 @@ Isai<IsaiType, ValueType, IndexType>::parse(
const config::pnode& config, const config::registry& context,
const config::type_descriptor& td_for_child)
{
std::set<std::string> allowed_keys{"skip_sorting", "sparsity_power",
"excess_limit", "excess_solver_factory",
"excess_solver_reduction"};
gko::config::check_allowed_keys(config, allowed_keys);

auto params = preconditioner::Isai<IsaiType, ValueType, IndexType>::build();

if (auto& obj = config.get("skip_sorting")) {
Expand Down
9 changes: 8 additions & 1 deletion core/preconditioner/jacobi.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
//
// SPDX-License-Identifier: BSD-3-Clause

#include "ginkgo/core/preconditioner/jacobi.hpp"

#include <memory>
#include <set>
#include <string>

#include <ginkgo/core/base/exception_helpers.hpp>
#include <ginkgo/core/base/executor.hpp>
Expand Down Expand Up @@ -57,6 +59,11 @@ Jacobi<ValueType, IndexType>::parse(const config::pnode& config,
const config::registry& context,
const config::type_descriptor& td_for_child)
{
std::set<std::string> allowed_keys{
"max_block_size", "max_block_stride", "skip_sorting",
"block_pointers", "storage_optimization", "accuracy"};
gko::config::check_allowed_keys(config, allowed_keys);

auto params = preconditioner::Jacobi<ValueType, IndexType>::build();

if (auto& obj = config.get("max_block_size")) {
Expand Down
13 changes: 11 additions & 2 deletions core/preconditioner/sor.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
//
// SPDX-License-Identifier: BSD-3-Clause

#include "ginkgo/core/preconditioner/sor.hpp"

#include <set>
#include <string>

#include <ginkgo/core/base/array.hpp>
#include <ginkgo/core/base/executor.hpp>
#include <ginkgo/core/base/precision_dispatch.hpp>
#include <ginkgo/core/matrix/csr.hpp>
#include <ginkgo/core/matrix/diagonal.hpp>
#include <ginkgo/core/preconditioner/sor.hpp>
#include <ginkgo/core/solver/triangular.hpp>

#include "core/base/array_access.hpp"
Expand Down Expand Up @@ -39,6 +43,11 @@ Sor<ValueType, IndexType>::parse(const config::pnode& config,
const config::registry& context,
const config::type_descriptor& td_for_child)
{
std::set<std::string> allowed_keys{"skip_sorting", "symmetric",
"relaxation_factor", "l_solver",
"u_solver"};
gko::config::check_allowed_keys(config, allowed_keys);

auto params = Sor::build();

if (auto& obj = config.get("skip_sorting")) {
Expand Down
14 changes: 13 additions & 1 deletion core/test/config/preconditioner.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
//
// SPDX-License-Identifier: BSD-3-Clause

Expand Down Expand Up @@ -514,6 +514,18 @@ TYPED_TEST(Preconditioner, CreateDefault)
}


TYPED_TEST(Preconditioner, ThrowWhenKeyIsNotAllowed)
{
using Config = typename TestFixture::Config;
auto pnode_map = Config::setup_base();
pnode_map["invalid_key"] = pnode{""};
auto config = pnode(pnode_map);

ASSERT_THROW(parse(config, this->reg, this->td).on(this->exec),
gko::InvalidStateError);
}


TYPED_TEST(Preconditioner, ExplicitTemplate)
{
using Config = typename TestFixture::Config;
Expand Down

0 comments on commit ec6eda5

Please sign in to comment.