ginkgo/core/matrix/diagonal.hpp Source File

ginkgo/core/matrix/diagonal.hpp Source File#

Reference API: ginkgo/core/matrix/diagonal.hpp Source File
Reference API
diagonal.hpp
1// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
5#ifndef GKO_PUBLIC_CORE_MATRIX_DIAGONAL_HPP_
6#define GKO_PUBLIC_CORE_MATRIX_DIAGONAL_HPP_
7
8
9#include <ginkgo/core/base/array.hpp>
10#include <ginkgo/core/base/lin_op.hpp>
11
12
13namespace gko {
14namespace matrix {
15
16
17template <typename ValueType, typename IndexType>
18class Csr;
19
20template <typename ValueType>
21class Dense;
22
23
38template <typename ValueType = default_precision>
40 : public EnableLinOp<Diagonal<ValueType>>,
41 public ConvertibleTo<Csr<ValueType, int32>>,
42 public ConvertibleTo<Csr<ValueType, int64>>,
43 public ConvertibleTo<Diagonal<next_precision<ValueType>>>,
44#if GINKGO_ENABLE_HALF
45 public ConvertibleTo<Diagonal<next_precision<next_precision<ValueType>>>>,
46#endif
47 public Transposable,
48 public WritableToMatrixData<ValueType, int32>,
49 public WritableToMatrixData<ValueType, int64>,
50 public ReadableFromMatrixData<ValueType, int32>,
51 public ReadableFromMatrixData<ValueType, int64>,
52 public EnableAbsoluteComputation<remove_complex<Diagonal<ValueType>>> {
54 friend class Csr<ValueType, int32>;
55 friend class Csr<ValueType, int64>;
56 friend class Diagonal<to_complex<ValueType>>;
57
58public:
59 using EnableLinOp<Diagonal>::convert_to;
60 using EnableLinOp<Diagonal>::move_to;
61 using ConvertibleTo<Csr<ValueType, int32>>::convert_to;
63 using ConvertibleTo<Csr<ValueType, int64>>::convert_to;
67
68 using value_type = ValueType;
69 using index_type = int64;
74 using absolute_type = remove_complex<Diagonal>;
75
76 friend class Diagonal<previous_precision<ValueType>>;
77
78 std::unique_ptr<LinOp> transpose() const override;
79
80 std::unique_ptr<LinOp> conj_transpose() const override;
81
82 void convert_to(Diagonal<next_precision<ValueType>>* result) const override;
83
84 void move_to(Diagonal<next_precision<ValueType>>* result) override;
85
86#if GINKGO_ENABLE_HALF
87 friend class Diagonal<previous_precision<previous_precision<ValueType>>>;
88 using ConvertibleTo<
90 using ConvertibleTo<
92
93 void convert_to(Diagonal<next_precision<next_precision<ValueType>>>* result)
94 const override;
95
96 void move_to(
98#endif
99
100 void convert_to(Csr<ValueType, int32>* result) const override;
101
102 void move_to(Csr<ValueType, int32>* result) override;
103
104 void convert_to(Csr<ValueType, int64>* result) const override;
105
106 void move_to(Csr<ValueType, int64>* result) override;
107
108 std::unique_ptr<absolute_type> compute_absolute() const override;
109
111
117 value_type* get_values() noexcept { return values_.get_data(); }
118
126 const value_type* get_const_values() const noexcept
127 {
128 return values_.get_const_data();
129 }
130
139 {
140 GKO_ASSERT_REVERSE_CONFORMANT(this, b);
141 GKO_ASSERT_EQUAL_ROWS(b, x);
142 GKO_ASSERT_EQUAL_COLS(this, x);
143
144 this->rapply_impl(b.get(), x.get());
145 }
146
157 {
158 GKO_ASSERT_CONFORMANT(this, b);
159 GKO_ASSERT_EQUAL_ROWS(b, x);
160 GKO_ASSERT_EQUAL_ROWS(this, x);
161
162 this->inverse_apply_impl(b.get(), x.get());
163 }
164
165 void read(const mat_data& data) override;
166
167 void read(const mat_data32& data) override;
168
169 void read(const device_mat_data& data) override;
170
171 void read(const device_mat_data32& data) override;
172
173 void read(device_mat_data&& data) override;
174
175 void read(device_mat_data32&& data) override;
176
177 void write(mat_data& data) const override;
178
179 void write(mat_data32& data) const override;
180
189 static std::unique_ptr<Diagonal> create(
190 std::shared_ptr<const Executor> exec, size_type size = 0);
191
206 static std::unique_ptr<Diagonal> create(
207 std::shared_ptr<const Executor> exec, const size_type size,
208 array<value_type> values);
209
214 template <typename InputValueType>
215 GKO_DEPRECATED(
216 "explicitly construct the gko::array argument instead of passing an"
217 "initializer list")
218 static std::unique_ptr<Diagonal> create(
219 std::shared_ptr<const Executor> exec, const size_type size,
220 std::initializer_list<InputValueType> values)
221 {
222 return create(exec, size, array<value_type>{exec, std::move(values)});
223 }
224
235 static std::unique_ptr<const Diagonal> create_const(
236 std::shared_ptr<const Executor> exec, size_type size,
237 gko::detail::const_array_view<ValueType>&& values);
238
239protected:
240 Diagonal(std::shared_ptr<const Executor> exec, size_type size = 0);
241
242 Diagonal(std::shared_ptr<const Executor> exec, const size_type size,
243 array<value_type> values);
244
245 void apply_impl(const LinOp* b, LinOp* x) const override;
246
247 void apply_impl(const LinOp* alpha, const LinOp* b, const LinOp* beta,
248 LinOp* x) const override;
249
250 void rapply_impl(const LinOp* b, LinOp* x) const;
251
252 void inverse_apply_impl(const LinOp* b, LinOp* x) const;
253
254private:
255 array<value_type> values_;
256};
257
258
259} // namespace matrix
260} // namespace gko
261
262
263#endif // GKO_PUBLIC_CORE_MATRIX_DIAGONAL_HPP_
Definition polymorphic_object.hpp:479
Definition lin_op.hpp:793
Definition lin_op.hpp:878
Definition polymorphic_object.hpp:668
Definition executor.hpp:615
Definition lin_op.hpp:117
Definition lin_op.hpp:605
Definition lin_op.hpp:433
Definition lin_op.hpp:660
Definition array.hpp:166
value_type * get_data() noexcept
Definition array.hpp:673
const value_type * get_const_data() const noexcept
Definition array.hpp:682
Definition device_matrix_data.hpp:36
Definition csr.hpp:123
Definition diagonal.hpp:52
static std::unique_ptr< const Diagonal > create_const(std::shared_ptr< const Executor > exec, size_type size, gko::detail::const_array_view< ValueType > &&values)
void rapply(ptr_param< const LinOp > b, ptr_param< LinOp > x) const
Definition diagonal.hpp:138
static std::unique_ptr< Diagonal > create(std::shared_ptr< const Executor > exec, size_type size=0)
void inverse_apply(ptr_param< const LinOp > b, ptr_param< LinOp > x) const
Definition diagonal.hpp:156
value_type * get_values() noexcept
Definition diagonal.hpp:117
std::unique_ptr< LinOp > conj_transpose() const override
static std::unique_ptr< Diagonal > create(std::shared_ptr< const Executor > exec, const size_type size, array< value_type > values)
std::unique_ptr< absolute_type > compute_absolute() const override
const value_type * get_const_values() const noexcept
Definition diagonal.hpp:126
void compute_absolute_inplace() override
std::unique_ptr< LinOp > transpose() const override
Definition utils_helper.hpp:41
T * get() const
Definition utils_helper.hpp:75
The Ginkgo namespace.
Definition abstract_factory.hpp:20
std::int32_t int32
Definition types.hpp:106
typename detail::next_precision_impl< T >::type next_precision
Definition math.hpp:438
std::int64_t int64
Definition types.hpp:112
std::size_t size_type
Definition types.hpp:89
typename detail::to_complex_s< T >::type to_complex
Definition math.hpp:279
typename detail::remove_complex_s< T >::type remove_complex
Definition math.hpp:260
STL namespace.
Definition matrix_data.hpp:126