Skip to content

Commit ec6eda5

Browse files
committed
check preconditioner config key
1 parent e96496d commit ec6eda5

File tree

7 files changed

+64
-9
lines changed

7 files changed

+64
-9
lines changed

core/preconditioner/gauss_seidel.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
1+
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
22
//
33
// SPDX-License-Identifier: BSD-3-Clause
44

5-
#include <ginkgo/core/preconditioner/gauss_seidel.hpp>
5+
#include "ginkgo/core/preconditioner/gauss_seidel.hpp"
6+
7+
#include <set>
8+
#include <string>
9+
610
#include <ginkgo/core/preconditioner/sor.hpp>
711

812
#include "core/config/config_helper.hpp"
@@ -18,6 +22,10 @@ GaussSeidel<ValueType, IndexType>::parse(
1822
const config::pnode& config, const config::registry& context,
1923
const config::type_descriptor& td_for_child)
2024
{
25+
std::set<std::string> allowed_keys{"skip_sorting", "symmetric", "l_solver",
26+
"u_solver"};
27+
gko::config::check_allowed_keys(config, allowed_keys);
28+
2129
auto params = GaussSeidel::build();
2230

2331
if (auto& obj = config.get("skip_sorting")) {

core/preconditioner/ic.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
1+
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
22
//
33
// SPDX-License-Identifier: BSD-3-Clause
44

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

7+
#include <set>
8+
#include <string>
9+
710
#include <ginkgo/core/base/types.hpp>
811
#include <ginkgo/core/config/config.hpp>
912
#include <ginkgo/core/config/registry.hpp>
@@ -27,6 +30,9 @@ typename Ic::parameters_type ic_parse(
2730
const config::pnode& config, const config::registry& context,
2831
const config::type_descriptor& td_for_child)
2932
{
33+
std::set<std::string> allowed_keys{"l_solver", "factorization"};
34+
gko::config::check_allowed_keys(config, allowed_keys);
35+
3036
auto params = Ic::build();
3137

3238
if (auto& obj = config.get("l_solver")) {

core/preconditioner/ilu.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
1+
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
22
//
33
// SPDX-License-Identifier: BSD-3-Clause
44

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

7+
#include <set>
8+
#include <string>
9+
710
#include <ginkgo/core/base/types.hpp>
811
#include <ginkgo/core/config/config.hpp>
912
#include <ginkgo/core/config/registry.hpp>
@@ -29,6 +32,9 @@ typename Ilu::parameters_type ilu_parse(
2932
const config::pnode& config, const config::registry& context,
3033
const config::type_descriptor& td_for_child)
3134
{
35+
std::set<std::string> allowed_keys{"l_solver", "u_solver", "factorization"};
36+
gko::config::check_allowed_keys(config, allowed_keys);
37+
3238
auto params = Ilu::build();
3339

3440
if (auto& obj = config.get("l_solver")) {

core/preconditioner/isai.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
1+
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
22
//
33
// SPDX-License-Identifier: BSD-3-Clause
44

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

77
#include <functional>
88
#include <memory>
9+
#include <set>
10+
#include <string>
911
#include <type_traits>
1012

1113
#include <ginkgo/core/base/exception_helpers.hpp>
@@ -98,6 +100,11 @@ Isai<IsaiType, ValueType, IndexType>::parse(
98100
const config::pnode& config, const config::registry& context,
99101
const config::type_descriptor& td_for_child)
100102
{
103+
std::set<std::string> allowed_keys{"skip_sorting", "sparsity_power",
104+
"excess_limit", "excess_solver_factory",
105+
"excess_solver_reduction"};
106+
gko::config::check_allowed_keys(config, allowed_keys);
107+
101108
auto params = preconditioner::Isai<IsaiType, ValueType, IndexType>::build();
102109

103110
if (auto& obj = config.get("skip_sorting")) {

core/preconditioner/jacobi.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
1+
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
22
//
33
// SPDX-License-Identifier: BSD-3-Clause
44

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

77
#include <memory>
8+
#include <set>
9+
#include <string>
810

911
#include <ginkgo/core/base/exception_helpers.hpp>
1012
#include <ginkgo/core/base/executor.hpp>
@@ -57,6 +59,11 @@ Jacobi<ValueType, IndexType>::parse(const config::pnode& config,
5759
const config::registry& context,
5860
const config::type_descriptor& td_for_child)
5961
{
62+
std::set<std::string> allowed_keys{
63+
"max_block_size", "max_block_stride", "skip_sorting",
64+
"block_pointers", "storage_optimization", "accuracy"};
65+
gko::config::check_allowed_keys(config, allowed_keys);
66+
6067
auto params = preconditioner::Jacobi<ValueType, IndexType>::build();
6168

6269
if (auto& obj = config.get("max_block_size")) {

core/preconditioner/sor.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
1+
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
22
//
33
// SPDX-License-Identifier: BSD-3-Clause
44

5+
#include "ginkgo/core/preconditioner/sor.hpp"
6+
7+
#include <set>
8+
#include <string>
9+
510
#include <ginkgo/core/base/array.hpp>
611
#include <ginkgo/core/base/executor.hpp>
712
#include <ginkgo/core/base/precision_dispatch.hpp>
813
#include <ginkgo/core/matrix/csr.hpp>
914
#include <ginkgo/core/matrix/diagonal.hpp>
10-
#include <ginkgo/core/preconditioner/sor.hpp>
1115
#include <ginkgo/core/solver/triangular.hpp>
1216

1317
#include "core/base/array_access.hpp"
@@ -39,6 +43,11 @@ Sor<ValueType, IndexType>::parse(const config::pnode& config,
3943
const config::registry& context,
4044
const config::type_descriptor& td_for_child)
4145
{
46+
std::set<std::string> allowed_keys{"skip_sorting", "symmetric",
47+
"relaxation_factor", "l_solver",
48+
"u_solver"};
49+
gko::config::check_allowed_keys(config, allowed_keys);
50+
4251
auto params = Sor::build();
4352

4453
if (auto& obj = config.get("skip_sorting")) {

core/test/config/preconditioner.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
1+
// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
22
//
33
// SPDX-License-Identifier: BSD-3-Clause
44

@@ -514,6 +514,18 @@ TYPED_TEST(Preconditioner, CreateDefault)
514514
}
515515

516516

517+
TYPED_TEST(Preconditioner, ThrowWhenKeyIsNotAllowed)
518+
{
519+
using Config = typename TestFixture::Config;
520+
auto pnode_map = Config::setup_base();
521+
pnode_map["invalid_key"] = pnode{""};
522+
auto config = pnode(pnode_map);
523+
524+
ASSERT_THROW(parse(config, this->reg, this->td).on(this->exec),
525+
gko::InvalidStateError);
526+
}
527+
528+
517529
TYPED_TEST(Preconditioner, ExplicitTemplate)
518530
{
519531
using Config = typename TestFixture::Config;

0 commit comments

Comments
 (0)