Ginkgo  Generated from pipelines/2662685947 branch based on develop. Ginkgo version 2.0.0
A numerical linear algebra library targeting many-core architectures
combined.hpp
1 // SPDX-FileCopyrightText: 2017 - 2026 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 
14 namespace gko {
15 namespace stop {
16 
17 
26 class Combined : public Criterion {
27 public:
28  class Factory;
29 
31  : public ::gko::enable_parameters_type<parameters_type, Factory> {
41  std::vector<std::shared_ptr<const CriterionFactory>>
42  GKO_DEFERRED_FACTORY_VECTOR_PARAMETER(criteria);
43  };
44 
45  class Factory
46  : public ::gko::stop::EnableDefaultCriterionFactory<Factory, Combined,
47  parameters_type> {
48  friend class ::gko::enable_parameters_type<parameters_type, Factory>;
49 
50  using Base =
52  parameters_type>;
53 
54  public:
55  explicit Factory(std::shared_ptr<const ::gko::Executor> exec);
56  explicit Factory(std::shared_ptr<const ::gko::Executor> exec,
57  const parameters_type& parameters);
58 
59  Factory(const Factory& other) = default;
60  Factory(Factory&& other) = default;
61 
62  Factory& operator=(const Factory& other);
63  };
64 
65  static parameters_type build() { return {}; }
66 
67  const parameters_type& get_parameters() const { return parameters_; }
68 
69 protected:
70  bool check_impl(uint8 stoppingId, bool setFinalized,
71  array<stopping_status>* stop_status, bool* one_changed,
72  const Updater&) override;
73 
74  explicit Combined(std::shared_ptr<const gko::Executor> exec);
75 
76  explicit Combined(const Factory* factory, const CriterionArgs& args);
77 
78 private:
79  friend ::gko::stop::EnableDefaultCriterionFactory<Factory, Combined,
80  parameters_type>;
81 
82  parameters_type parameters_;
83 
84  std::vector<std::unique_ptr<Criterion>> criteria_{};
85 };
86 
87 
104 template <typename FactoryContainer>
105 std::shared_ptr<const CriterionFactory> combine(FactoryContainer&& factories)
106 {
107  switch (factories.size()) {
108  case 0:
109  GKO_NOT_SUPPORTED(nullptr);
110  case 1:
111  if (factories[0] == nullptr) {
112  GKO_NOT_SUPPORTED(nullptr);
113  }
114  return factories[0];
115  default:
116  if (factories[0] == nullptr) {
117  // first factory must be valid to capture executor
118  GKO_NOT_SUPPORTED(nullptr);
119  } else {
120  auto exec = factories[0]->get_executor();
121  return Combined::build()
122  .with_criteria(std::forward<FactoryContainer>(factories))
123  .on(exec);
124  }
125  }
126 }
127 
128 
129 } // namespace stop
130 } // namespace gko
131 
132 
133 #endif // GKO_PUBLIC_CORE_STOP_COMBINED_HPP_
gko::uint8
std::uint8_t uint8
8-bit unsigned integral type.
Definition: types.hpp:119
gko::stop::Combined::parameters_type::criteria
std::vector< std::shared_ptr< const CriterionFactory > > criteria
Criterion factories to combine.
Definition: combined.hpp:42
gko::EnableDefaultFactory
This mixin provides a default implementation of a concrete factory.
Definition: abstract_factory.hpp:122
gko
The Ginkgo namespace.
Definition: abstract_factory.hpp:20
gko::stop::Combined
The Combined class is used to combine multiple criterions together through an OR operation.
Definition: combined.hpp:26
gko::stop::combine
std::shared_ptr< const CriterionFactory > combine(FactoryContainer &&factories)
Combines multiple criterion factories into a single combined criterion factory.
Definition: combined.hpp:105
gko::stop::Combined::parameters_type
Definition: combined.hpp:30
gko::stop::Criterion
The Criterion class is a base class for all stopping criteria.
Definition: criterion.hpp:36
gko::enable_parameters_type
The enable_parameters_type mixin is used to create a base implementation of the factory parameters st...
Definition: abstract_factory.hpp:203
gko::stop::Combined::Factory
Definition: combined.hpp:45