Ginkgo Generated from branch based on main. Ginkgo version 1.9.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#include <ginkgo/core/stop/criterion.hpp>
12
13
14namespace gko {
15namespace stop {
16
17
26class Combined : public EnablePolymorphicObject<Combined, Criterion> {
27 friend class EnablePolymorphicObject<Combined, Criterion>;
28
29public:
30 class Factory;
31
33 : public ::gko::enable_parameters_type<parameters_type, Factory> {
43 std::vector<std::shared_ptr<const CriterionFactory>>
44 GKO_DEFERRED_FACTORY_VECTOR_PARAMETER(criteria);
45 };
46
47 class Factory
48 : public ::gko::stop::EnableDefaultCriterionFactory<Factory, Combined,
49 parameters_type> {
50 friend class ::gko::EnablePolymorphicObject<
52 friend class ::gko::enable_parameters_type<parameters_type, Factory>;
53
54 using Base =
56 parameters_type>;
57
58 public:
59 explicit Factory(std::shared_ptr<const ::gko::Executor> exec);
60 explicit Factory(std::shared_ptr<const ::gko::Executor> exec,
61 const parameters_type& parameters);
62
63 Factory(const Factory& other) = default;
64 Factory(Factory&& other) = default;
65
66 Factory& operator=(const Factory& other);
67 };
68
69 static parameters_type build() { return {}; }
70
71 const parameters_type& get_parameters() const { return parameters_; }
72
73protected:
74 bool check_impl(uint8 stoppingId, bool setFinalized,
75 array<stopping_status>* stop_status, bool* one_changed,
76 const Updater&) override;
77
78 explicit Combined(std::shared_ptr<const gko::Executor> exec);
79
80 explicit Combined(const Factory* factory, const CriterionArgs& args);
81
82private:
83 friend ::gko::stop::EnableDefaultCriterionFactory<Factory, Combined,
84 parameters_type>;
85
86 parameters_type parameters_;
87
88 std::vector<std::unique_ptr<Criterion>> criteria_{};
89};
90
91
108template <typename FactoryContainer>
109std::shared_ptr<const CriterionFactory> combine(FactoryContainer&& factories)
110{
111 switch (factories.size()) {
112 case 0:
113 GKO_NOT_SUPPORTED(nullptr);
114 case 1:
115 if (factories[0] == nullptr) {
116 GKO_NOT_SUPPORTED(nullptr);
117 }
118 return factories[0];
119 default:
120 if (factories[0] == nullptr) {
121 // first factory must be valid to capture executor
122 GKO_NOT_SUPPORTED(nullptr);
123 } else {
124 auto exec = factories[0]->get_executor();
125 return Combined::build()
126 .with_criteria(std::forward<FactoryContainer>(factories))
127 .on(exec);
128 }
129 }
130}
131
132
133} // namespace stop
134} // namespace gko
135
136
137#endif // GKO_PUBLIC_CORE_STOP_COMBINED_HPP_
This mixin inherits from (a subclass of) PolymorphicObject and provides a base implementation of a ne...
Definition polymorphic_object.hpp:662
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:49
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:109
The Stopping criterion namespace.
Definition logger.hpp:52
AbstractFactory< Criterion, CriterionArgs > CriterionFactory
Declares an Abstract Factory specialized for Criterions.
Definition criterion.hpp:226
EnableDefaultFactory< ConcreteFactory, ConcreteCriterion, ParametersType, PolymorphicBase > EnableDefaultCriterionFactory
This is an alias for the EnableDefaultFactory mixin, which correctly sets the template parameters to ...
Definition criterion.hpp:246
The Ginkgo namespace.
Definition abstract_factory.hpp:20
std::uint8_t uint8
8-bit unsigned integral type.
Definition types.hpp:118
@ array
The matrix should be written as dense matrix in column-major order.
Definition mtx_io.hpp:96
Definition combined.hpp:33
std::vector< std::shared_ptr< const CriterionFactory > > criteria
Criterion factories to combine.
Definition combined.hpp:44