Ginkgo Generated from branch based on master. Ginkgo version 1.8.0
A numerical linear algebra library targeting many-core architectures
Loading...
Searching...
No Matches
combined.hpp
1// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
5#ifndef GKO_PUBLIC_CORE_STOP_COMBINED_HPP_
6#define GKO_PUBLIC_CORE_STOP_COMBINED_HPP_
7
8
9#include <vector>
10
11
12#include <ginkgo/core/stop/criterion.hpp>
13
14
15namespace gko {
16namespace stop {
17
18
27class Combined : public EnablePolymorphicObject<Combined, Criterion> {
29
30public:
31 class Factory;
32
34 : public ::gko::enable_parameters_type<parameters_type, Factory> {
44 std::vector<std::shared_ptr<const CriterionFactory>>
45 GKO_DEFERRED_FACTORY_VECTOR_PARAMETER(criteria);
46 };
47
48 class Factory
49 : public ::gko::stop::EnableDefaultCriterionFactory<Factory, Combined,
50 parameters_type> {
51 friend class ::gko::EnablePolymorphicObject<
53 friend class ::gko::enable_parameters_type<parameters_type, Factory>;
54
55 using Base =
57 parameters_type>;
58
59 public:
60 explicit Factory(std::shared_ptr<const ::gko::Executor> exec);
61 explicit Factory(std::shared_ptr<const ::gko::Executor> exec,
62 const parameters_type& parameters);
63
64 Factory(const Factory& other) = default;
65 Factory(Factory&& other) = default;
66
67 Factory& operator=(const Factory& other);
68 };
69
70 static parameters_type build() { return {}; }
71
72 const parameters_type& get_parameters() const { return parameters_; }
73
74protected:
75 bool check_impl(uint8 stoppingId, bool setFinalized,
76 array<stopping_status>* stop_status, bool* one_changed,
77 const Updater&) override;
78
79 explicit Combined(std::shared_ptr<const gko::Executor> exec);
80
81 explicit Combined(const Factory* factory, const CriterionArgs& args);
82
83private:
84 friend ::gko::stop::EnableDefaultCriterionFactory<Factory, Combined,
85 parameters_type>;
86
87 parameters_type parameters_;
88
89 std::vector<std::unique_ptr<Criterion>> criteria_{};
90};
91
92
109template <typename FactoryContainer>
110std::shared_ptr<const CriterionFactory> combine(FactoryContainer&& factories)
111{
112 switch (factories.size()) {
113 case 0:
114 GKO_NOT_SUPPORTED(nullptr);
115 case 1:
116 if (factories[0] == nullptr) {
117 GKO_NOT_SUPPORTED(nullptr);
118 }
119 return factories[0];
120 default:
121 if (factories[0] == nullptr) {
122 // first factory must be valid to capture executor
123 GKO_NOT_SUPPORTED(nullptr);
124 } else {
125 auto exec = factories[0]->get_executor();
126 return Combined::build()
127 .with_criteria(std::forward<FactoryContainer>(factories))
128 .on(exec);
129 }
130 }
131}
132
133
134} // namespace stop
135} // namespace gko
136
137
138#endif // GKO_PUBLIC_CORE_STOP_COMBINED_HPP_
The AbstractFactory is a generic interface template that enables easy implementation of the abstract ...
Definition abstract_factory.hpp:47
This mixin provides a default implementation of a concrete factory.
Definition abstract_factory.hpp:126
This mixin inherits from (a subclass of) PolymorphicObject and provides a base implementation of a ne...
Definition polymorphic_object.hpp:663
The enable_parameters_type mixin is used to create a base implementation of the factory parameters st...
Definition abstract_factory.hpp:211
Definition combined.hpp:50
The Combined class is used to combine multiple criterions together through an OR operation.
Definition combined.hpp:27
The Criterion class is a base class for all stopping criteria.
Definition criterion.hpp:36
std::shared_ptr< const CriterionFactory > combine(FactoryContainer &&factories)
Combines multiple criterion factories into a single combined criterion factory.
Definition combined.hpp:110
The Ginkgo namespace.
Definition abstract_factory.hpp:20
std::uint8_t uint8
8-bit unsigned integral type.
Definition types.hpp:115
@ array
The matrix should be written as dense matrix in column-major order.
Definition combined.hpp:34
std::vector< std::shared_ptr< const CriterionFactory > > criteria
Criterion factories to combine.
Definition combined.hpp:45