Ginkgo  Generated from pipelines/1556235455 branch based on develop. Ginkgo version 1.9.0
A numerical linear algebra library targeting many-core architectures
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 
14 namespace gko {
15 namespace stop {
16 
17 
26 class Combined : public EnablePolymorphicObject<Combined, Criterion> {
28 
29 public:
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 
73 protected:
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 
82 private:
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 
108 template <typename FactoryContainer>
109 std::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_
gko::uint8
std::uint8_t uint8
8-bit unsigned integral type.
Definition: types.hpp:115
gko::stop::Combined::parameters_type::criteria
std::vector< std::shared_ptr< const CriterionFactory > > criteria
Criterion factories to combine.
Definition: combined.hpp:44
gko::AbstractFactory
The AbstractFactory is a generic interface template that enables easy implementation of the abstract ...
Definition: abstract_factory.hpp:45
gko::EnableDefaultFactory
This mixin provides a default implementation of a concrete factory.
Definition: abstract_factory.hpp:124
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:109
gko::stop::Combined::parameters_type
Definition: combined.hpp:32
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:211
gko::stop::Combined::Factory
Definition: combined.hpp:47
gko::EnablePolymorphicObject
This mixin inherits from (a subclass of) PolymorphicObject and provides a base implementation of a ne...
Definition: polymorphic_object.hpp:661