Ginkgo Generated from branch based on master. Ginkgo version 1.7.0
A numerical linear algebra library targeting many-core architectures
Loading...
Searching...
No Matches
identity.hpp
1/*******************************<GINKGO LICENSE>******************************
2Copyright (c) 2017-2023, the Ginkgo authors
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions
7are met:
8
91. Redistributions of source code must retain the above copyright
10notice, this list of conditions and the following disclaimer.
11
122. Redistributions in binary form must reproduce the above copyright
13notice, this list of conditions and the following disclaimer in the
14documentation and/or other materials provided with the distribution.
15
163. Neither the name of the copyright holder nor the names of its
17contributors may be used to endorse or promote products derived from
18this software without specific prior written permission.
19
20THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31******************************<GINKGO LICENSE>*******************************/
32
33#ifndef GKO_PUBLIC_CORE_MATRIX_IDENTITY_HPP_
34#define GKO_PUBLIC_CORE_MATRIX_IDENTITY_HPP_
35
36
37#include <ginkgo/core/base/lin_op.hpp>
38
39
40namespace gko {
41namespace matrix {
42
43
62template <typename ValueType = default_precision>
63class Identity : public EnableLinOp<Identity<ValueType>>,
64 public EnableCreateMethod<Identity<ValueType>>,
65 public Transposable {
67 friend class EnableCreateMethod<Identity>;
68
69public:
72
73 using value_type = ValueType;
75
76 std::unique_ptr<LinOp> transpose() const override;
77
78 std::unique_ptr<LinOp> conj_transpose() const override;
79
80
81protected:
87 explicit Identity(std::shared_ptr<const Executor> exec)
88 : EnableLinOp<Identity>(exec)
89 {}
90
96 Identity(std::shared_ptr<const Executor> exec, dim<2> size)
97 : EnableLinOp<Identity>(exec, size)
98 {
99 GKO_ASSERT_IS_SQUARE_MATRIX(this);
100 }
101
107 Identity(std::shared_ptr<const Executor> exec, size_type size)
108 : EnableLinOp<Identity>(exec, dim<2>{size})
109 {}
110
111 void apply_impl(const LinOp* b, LinOp* x) const override;
112
113 void apply_impl(const LinOp* alpha, const LinOp* b, const LinOp* beta,
114 LinOp* x) const override;
115};
116
117
130template <typename ValueType = default_precision>
132 : public EnablePolymorphicObject<IdentityFactory<ValueType>, LinOpFactory> {
134
135public:
136 using value_type = ValueType;
137
145 static std::unique_ptr<IdentityFactory> create(
146 std::shared_ptr<const Executor> exec)
147 {
148 return std::unique_ptr<IdentityFactory>(
149 new IdentityFactory(std::move(exec)));
150 }
151
152protected:
153 std::unique_ptr<LinOp> generate_impl(
154 std::shared_ptr<const LinOp> base) const override;
155
156 IdentityFactory(std::shared_ptr<const Executor> exec)
158 {}
159};
160
161
162} // namespace matrix
163} // namespace gko
164
165
166#endif // GKO_PUBLIC_CORE_MATRIX_IDENTITY_HPP_
This mixin implements a static create() method on ConcreteType that dynamically allocates the memory,...
Definition polymorphic_object.hpp:776
The EnableLinOp mixin can be used to provide sensible default implementations of the majority of the ...
Definition lin_op.hpp:908
void move_to(result_type *result) override
Definition polymorphic_object.hpp:760
void convert_to(result_type *result) const override
Definition polymorphic_object.hpp:758
This mixin inherits from (a subclass of) PolymorphicObject and provides a base implementation of a ne...
Definition polymorphic_object.hpp:691
A LinOpFactory represents a higher order mapping which transforms one linear operator into another.
Definition lin_op.hpp:414
Definition lin_op.hpp:146
Linear operators which support transposition should implement the Transposable interface.
Definition lin_op.hpp:462
This factory is a utility which can be used to generate Identity operators.
Definition identity.hpp:132
static std::unique_ptr< IdentityFactory > create(std::shared_ptr< const Executor > exec)
Creates a new Identity factory.
Definition identity.hpp:145
This class is a utility which efficiently implements the identity matrix (a linear operator which map...
Definition identity.hpp:65
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 Ginkgo namespace.
Definition abstract_factory.hpp:48
constexpr T one()
Returns the multiplicative identity for T.
Definition math.hpp:803
std::size_t size_type
Integral type used for allocation quantities.
Definition types.hpp:120
A type representing the dimensions of a multidimensional object.
Definition dim.hpp:55