Ginkgo  Generated from pipelines/1330831941 branch based on master. Ginkgo version 1.8.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 
12 #include <ginkgo/core/stop/criterion.hpp>
13 
14 
15 namespace gko {
16 namespace stop {
17 
18 
27 class Combined : public EnablePolymorphicObject<Combined, Criterion> {
29 
30 public:
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 
74 protected:
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 
83 private:
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 
109 template <typename FactoryContainer>
110 std::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_
gko::uint8
std::uint8_t uint8
8-bit unsigned integral type.
Definition: types.hpp:137
gko::stop::Combined::parameters_type::criteria
std::vector< std::shared_ptr< const CriterionFactory > > criteria
Criterion factories to combine.
Definition: combined.hpp:45
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:27
gko::stop::combine
std::shared_ptr< const CriterionFactory > combine(FactoryContainer &&factories)
Combines multiple criterion factories into a single combined criterion factory.
Definition: combined.hpp:110
gko::stop::Combined::parameters_type
Definition: combined.hpp:33
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:48
gko::EnablePolymorphicObject
This mixin inherits from (a subclass of) PolymorphicObject and provides a base implementation of a ne...
Definition: polymorphic_object.hpp:662