Ginkgo  Generated from pipelines/3136675824 branch based on develop. Ginkgo version 2.0.0
A numerical linear algebra library targeting many-core architectures
identity.hpp
1 // SPDX-FileCopyrightText: 2017 - 2026 The Ginkgo authors
2 //
3 // SPDX-License-Identifier: BSD-3-Clause
4 
5 #ifndef GKO_PUBLIC_CORE_MATRIX_IDENTITY_HPP_
6 #define GKO_PUBLIC_CORE_MATRIX_IDENTITY_HPP_
7 
8 
9 #include <ginkgo/core/base/lin_op.hpp>
10 
11 
12 namespace gko {
13 namespace matrix {
14 
15 
33 template <typename ValueType = default_precision>
34 class Identity : public LinOp,
35  public EnableCloneable<Identity<ValueType>>,
36  public Transposable {
37  friend class EnableCloneable<Identity>;
38  GKO_ASSERT_SUPPORTED_VALUE_TYPE;
39 
40 public:
43 
44  using value_type = ValueType;
46 
47  std::unique_ptr<LinOp> transpose() const override;
48 
49  std::unique_ptr<LinOp> conj_transpose() const override;
50 
57  GKO_DEPRECATED("use the version taking a size_type instead of dim<2>")
58  static std::unique_ptr<Identity> create(
59  std::shared_ptr<const Executor> exec, dim<2> size);
60 
67  static std::unique_ptr<Identity> create(
68  std::shared_ptr<const Executor> exec, size_type size = 0);
69 
70 protected:
71  explicit Identity(std::shared_ptr<const Executor> exec, size_type size = 0);
72 
73  void apply_impl(const AbstractMultiVector* b,
74  AbstractMultiVector* x) const override;
75 
76  void apply_impl(const AbstractMultiVector* alpha,
77  const AbstractMultiVector* b,
78  const AbstractMultiVector* beta,
79  AbstractMultiVector* x) const override;
80 };
81 
82 
95 template <typename ValueType = default_precision>
96 class IdentityFactory : public LinOpFactory {
97 public:
98  using value_type = ValueType;
99 
107  static std::unique_ptr<IdentityFactory> create(
108  std::shared_ptr<const Executor> exec)
109  {
110  return std::unique_ptr<IdentityFactory>(
111  new IdentityFactory(std::move(exec)));
112  }
113 
114 protected:
115  std::unique_ptr<LinOp> generate_impl(
116  std::shared_ptr<const LinOp> base) const override;
117 
118  IdentityFactory(std::shared_ptr<const Executor> exec) : LinOpFactory(exec)
119  {}
120 };
121 
122 
123 } // namespace matrix
124 } // namespace gko
125 
126 
127 #endif // GKO_PUBLIC_CORE_MATRIX_IDENTITY_HPP_
gko::LinOp
Definition: lin_op.hpp:163
gko::Transposable
Linear operators which support transposition should implement the Transposable interface.
Definition: lin_op.hpp:596
gko::matrix::IdentityFactory
This factory is a utility which can be used to generate Identity operators.
Definition: identity.hpp:96
gko::size_type
std::size_t size_type
Integral type used for allocation quantities.
Definition: types.hpp:102
gko::matrix::IdentityFactory::create
static std::unique_ptr< IdentityFactory > create(std::shared_ptr< const Executor > exec)
Creates a new Identity factory.
Definition: identity.hpp:107
gko
The Ginkgo namespace.
Definition: abstract_factory.hpp:19
gko::matrix::Identity::conj_transpose
std::unique_ptr< LinOp > conj_transpose() const override
Returns a LinOp representing the conjugate transpose of the Transposable object.
gko::dim< 2 >
gko::matrix::Identity::create
static std::unique_ptr< Identity > create(std::shared_ptr< const Executor > exec, dim< 2 > size)
Creates an Identity matrix of the specified size.
gko::matrix::Identity
This class is a utility which efficiently implements the identity matrix (a linear operator which map...
Definition: identity.hpp:34
gko::EnableCloneable
This mixin is used to enable a default Cloneable::clone() implementation and similar for objects that...
Definition: polymorphic_object.hpp:372
gko::matrix::Identity::transpose
std::unique_ptr< LinOp > transpose() const override
Returns a LinOp representing the transpose of the Transposable object.
gko::LinOpFactory
A LinOpFactory represents a higher order mapping which transforms one linear operator into another.
Definition: lin_op.hpp:447
gko::AbstractMultiVector
Abstract interface class for (multi-)vector types.
Definition: multivector.hpp:81