Ginkgo Generated from branch based on main. Ginkgo version 1.11.0
A numerical linear algebra library targeting many-core architectures
Loading...
Searching...
No Matches
identity.hpp
1// SPDX-FileCopyrightText: 2017 - 2025 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
12namespace gko {
13namespace matrix {
14
15
34template <typename ValueType = default_precision>
35class Identity : public EnableLinOp<Identity<ValueType>>, public Transposable {
36 friend class EnablePolymorphicObject<Identity, LinOp>;
37 GKO_ASSERT_SUPPORTED_VALUE_TYPE;
38
39public:
40 using EnableLinOp<Identity>::convert_to;
41 using EnableLinOp<Identity>::move_to;
42
43 using value_type = ValueType;
44 using transposed_type = Identity<ValueType>;
45
46 std::unique_ptr<LinOp> transpose() const override;
47
48 std::unique_ptr<LinOp> conj_transpose() const override;
49
55 GKO_DEPRECATED("use the version taking a size_type instead of dim<2>")
56 static std::unique_ptr<Identity> create(
57 std::shared_ptr<const Executor> exec, dim<2> size);
58
64 static std::unique_ptr<Identity> create(
65 std::shared_ptr<const Executor> exec, size_type size = 0);
66
67protected:
68 explicit Identity(std::shared_ptr<const Executor> exec, size_type size = 0);
69
70 void apply_impl(const LinOp* b, LinOp* x) const override;
71
72 void apply_impl(const LinOp* alpha, const LinOp* b, const LinOp* beta,
73 LinOp* x) const override;
74};
75
76
89template <typename ValueType = default_precision>
90class IdentityFactory
91 : public EnablePolymorphicObject<IdentityFactory<ValueType>, LinOpFactory> {
92 friend class EnablePolymorphicObject<IdentityFactory, LinOpFactory>;
93
94public:
95 using value_type = ValueType;
96
104 static std::unique_ptr<IdentityFactory> create(
105 std::shared_ptr<const Executor> exec)
106 {
107 return std::unique_ptr<IdentityFactory>(
108 new IdentityFactory(std::move(exec)));
109 }
110
111protected:
112 std::unique_ptr<LinOp> generate_impl(
113 std::shared_ptr<const LinOp> base) const override;
114
115 IdentityFactory(std::shared_ptr<const Executor> exec)
117 {}
118};
119
120
121} // namespace matrix
122} // namespace gko
123
124
125#endif // GKO_PUBLIC_CORE_MATRIX_IDENTITY_HPP_
The EnableLinOp mixin can be used to provide sensible default implementations of the majority of the ...
Definition lin_op.hpp:879
This mixin inherits from (a subclass of) PolymorphicObject and provides a base implementation of a ne...
Definition polymorphic_object.hpp:668
The first step in using the Ginkgo library consists of creating an executor.
Definition executor.hpp:615
A LinOpFactory represents a higher order mapping which transforms one linear operator into another.
Definition lin_op.hpp:385
Definition lin_op.hpp:117
Linear operators which support transposition should implement the Transposable interface.
Definition lin_op.hpp:433
This factory is a utility which can be used to generate Identity operators.
Definition identity.hpp:91
static std::unique_ptr< IdentityFactory > create(std::shared_ptr< const Executor > exec)
Creates a new Identity factory.
Definition identity.hpp:104
static std::unique_ptr< Identity > create(std::shared_ptr< const Executor > exec, dim< 2 > size)
std::unique_ptr< LinOp > conj_transpose() const override
Returns a LinOp representing the conjugate transpose of the Transposable object.
std::unique_ptr< LinOp > transpose() const override
Returns a LinOp representing the transpose of the Transposable object.
The matrix namespace.
Definition dense_cache.hpp:24
The Ginkgo namespace.
Definition abstract_factory.hpp:20
double default_precision
Precision used if no precision is explicitly specified.
Definition types.hpp:172
std::size_t size_type
Integral type used for allocation quantities.
Definition types.hpp:90
STL namespace.
A type representing the dimensions of a multidimensional object.
Definition dim.hpp:26