Ginkgo  Generated from tags/v1.0.0^0 branch based on master. Ginkgo version 1.0.0
A numerical linear algebra library targeting many-core architectures
identity.hpp
1 /*******************************<GINKGO LICENSE>******************************
2 Copyright (c) 2017-2019, the Ginkgo authors
3 All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
7 are met:
8 
9 1. Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
11 
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
15 
16 3. Neither the name of the copyright holder nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
19 
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
21 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 ******************************<GINKGO LICENSE>*******************************/
32 
33 #ifndef GKO_CORE_MATRIX_IDENTITY_HPP_
34 #define GKO_CORE_MATRIX_IDENTITY_HPP_
35 
36 
37 #include <ginkgo/core/base/lin_op.hpp>
38 
39 
40 namespace gko {
41 namespace matrix {
42 
43 
62 template <typename ValueType = default_precision>
63 class Identity : public EnableLinOp<Identity<ValueType>>,
64  public EnableCreateMethod<Identity<ValueType>> {
65  friend class EnablePolymorphicObject<Identity, LinOp>;
66  friend class EnableCreateMethod<Identity>;
67 
68 public:
71 
72  using value_type = ValueType;
73 
74 protected:
80  explicit Identity(std::shared_ptr<const Executor> exec)
81  : EnableLinOp<Identity>(exec)
82  {}
83 
89  Identity(std::shared_ptr<const Executor> exec, size_type size)
90  : EnableLinOp<Identity>(exec, dim<2>{size})
91  {}
92 
93  void apply_impl(const LinOp *b, LinOp *x) const override;
94 
95  void apply_impl(const LinOp *alpha, const LinOp *b, const LinOp *beta,
96  LinOp *x) const override;
97 };
98 
99 
112 template <typename ValueType = default_precision>
114  : public EnablePolymorphicObject<IdentityFactory<ValueType>, LinOpFactory> {
115  friend class EnablePolymorphicObject<IdentityFactory, LinOpFactory>;
116 
117 public:
118  using value_type = ValueType;
119 
127  static std::unique_ptr<IdentityFactory> create(
128  std::shared_ptr<const Executor> exec)
129  {
130  return std::unique_ptr<IdentityFactory>(
131  new IdentityFactory(std::move(exec)));
132  }
133 
134 protected:
135  std::unique_ptr<LinOp> generate_impl(
136  std::shared_ptr<const LinOp> base) const override;
137 
138  IdentityFactory(std::shared_ptr<const Executor> exec)
140  {}
141 };
142 
143 
144 } // namespace matrix
145 } // namespace gko
146 
147 
148 #endif // GKO_CORE_MATRIX_IDENTITY_HPP_
This mixin implements a static create() method on ConcreteType that dynamically allocates the memory...
Definition: polymorphic_object.hpp:576
This mixin inherits from (a subclass of) PolymorphicObject and provides a base implementation of a ne...
Definition: polymorphic_object.hpp:505
static std::unique_ptr< IdentityFactory > create(std::shared_ptr< const Executor > exec)
Creates a new Identity factory.
Definition: identity.hpp:127
std::size_t size_type
Integral type used for allocation quantities.
Definition: types.hpp:94
The Ginkgo namespace.
Definition: abstract_factory.hpp:45
The EnableLinOp mixin can be used to provide sensible default implementations of the majority of the ...
Definition: lin_op.hpp:509
This factory is a utility which can be used to generate Identity operators.
Definition: identity.hpp:113
This class is a utility which efficiently implements the identity matrix (a linear operator which map...
Definition: identity.hpp:63