ginkgo/core/matrix/ell.hpp Source File

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

Reference API: ginkgo/core/matrix/ell.hpp Source File
Reference API
ell.hpp
1// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
5#ifndef GKO_PUBLIC_CORE_MATRIX_ELL_HPP_
6#define GKO_PUBLIC_CORE_MATRIX_ELL_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>
18class Dense;
19
20template <typename ValueType, typename IndexType>
21class Coo;
22
23template <typename ValueType, typename IndexType>
24class Csr;
25
26template <typename ValueType, typename IndexType>
27class Hybrid;
28
29
50template <typename ValueType = default_precision, typename IndexType = int32>
51class Ell : public EnableLinOp<Ell<ValueType, IndexType>>,
52 public ConvertibleTo<Ell<next_precision<ValueType>, IndexType>>,
53#if GINKGO_ENABLE_HALF
54 public ConvertibleTo<
55 Ell<next_precision<next_precision<ValueType>>, IndexType>>,
56#endif
57 public ConvertibleTo<Dense<ValueType>>,
58 public ConvertibleTo<Csr<ValueType, IndexType>>,
59 public DiagonalExtractable<ValueType>,
60 public ReadableFromMatrixData<ValueType, IndexType>,
61 public WritableToMatrixData<ValueType, IndexType>,
63 remove_complex<Ell<ValueType, IndexType>>> {
64 friend class EnablePolymorphicObject<Ell, LinOp>;
65 friend class Dense<ValueType>;
66 friend class Coo<ValueType, IndexType>;
67 friend class Csr<ValueType, IndexType>;
68 friend class Ell<to_complex<ValueType>, IndexType>;
69 friend class Ell<previous_precision<ValueType>, IndexType>;
70 friend class Hybrid<ValueType, IndexType>;
71
72public:
73 using EnableLinOp<Ell>::convert_to;
74 using EnableLinOp<Ell>::move_to;
75 using ConvertibleTo<Ell<next_precision<ValueType>, IndexType>>::convert_to;
76 using ConvertibleTo<Ell<next_precision<ValueType>, IndexType>>::move_to;
77 using ConvertibleTo<Dense<ValueType>>::convert_to;
78 using ConvertibleTo<Dense<ValueType>>::move_to;
81 using ReadableFromMatrixData<ValueType, IndexType>::read;
82
83 using value_type = ValueType;
84 using index_type = IndexType;
87 using absolute_type = remove_complex<Ell>;
88
89 void convert_to(
90 Ell<next_precision<ValueType>, IndexType>* result) const override;
91
92 void move_to(Ell<next_precision<ValueType>, IndexType>* result) override;
93
94#if GINKGO_ENABLE_HALF
95 friend class Ell<previous_precision<previous_precision<ValueType>>,
96 IndexType>;
97 using ConvertibleTo<
98 Ell<next_precision<next_precision<ValueType>>, IndexType>>::convert_to;
99 using ConvertibleTo<
101
102 void convert_to(Ell<next_precision<next_precision<ValueType>>, IndexType>*
103 result) const override;
104
105 void move_to(Ell<next_precision<next_precision<ValueType>>, IndexType>*
106 result) override;
107#endif
108
109 void convert_to(Dense<ValueType>* other) const override;
110
111 void move_to(Dense<ValueType>* other) override;
112
113 void convert_to(Csr<ValueType, IndexType>* other) const override;
114
115 void move_to(Csr<ValueType, IndexType>* other) override;
116
117 void read(const mat_data& data) override;
118
119 void read(const device_mat_data& data) override;
120
121 void read(device_mat_data&& data) override;
122
123 void write(mat_data& data) const override;
124
125 std::unique_ptr<Diagonal<ValueType>> extract_diagonal() const override;
126
127 std::unique_ptr<absolute_type> compute_absolute() const override;
128
130
136 value_type* get_values() noexcept { return values_.get_data(); }
137
145 const value_type* get_const_values() const noexcept
146 {
147 return values_.get_const_data();
148 }
149
155 index_type* get_col_idxs() noexcept { return col_idxs_.get_data(); }
156
164 const index_type* get_const_col_idxs() const noexcept
165 {
166 return col_idxs_.get_const_data();
167 }
168
175 {
176 return num_stored_elements_per_row_;
177 }
178
184 size_type get_stride() const noexcept { return stride_; }
185
192 {
193 return values_.get_size();
194 }
195
206 value_type& val_at(size_type row, size_type idx) noexcept
207 {
208 return values_.get_data()[this->linearize_index(row, idx)];
209 }
210
214 value_type val_at(size_type row, size_type idx) const noexcept
215 {
216 return values_.get_const_data()[this->linearize_index(row, idx)];
217 }
218
229 index_type& col_at(size_type row, size_type idx) noexcept
230 {
231 return this->get_col_idxs()[this->linearize_index(row, idx)];
232 }
233
237 index_type col_at(size_type row, size_type idx) const noexcept
238 {
239 return this->get_const_col_idxs()[this->linearize_index(row, idx)];
240 }
241
253 static std::unique_ptr<Ell> create(
254 std::shared_ptr<const Executor> exec, const dim<2>& size = {},
255 size_type num_stored_elements_per_row = 0, size_type stride = 0);
256
276 static std::unique_ptr<Ell> create(std::shared_ptr<const Executor> exec,
277 const dim<2>& size,
278 array<value_type> values,
279 array<index_type> col_idxs,
280 size_type num_stored_elements_per_row,
281 size_type stride);
282
288 template <typename InputValueType, typename InputColumnIndexType>
289 GKO_DEPRECATED(
290 "explicitly construct the gko::array argument instead of passing "
291 "initializer lists")
292 static std::unique_ptr<Ell> create(
293 std::shared_ptr<const Executor> exec, const dim<2>& size,
294 std::initializer_list<InputValueType> values,
295 std::initializer_list<InputColumnIndexType> col_idxs,
296 size_type num_stored_elements_per_row, size_type stride)
297 {
298 return create(exec, size, array<value_type>{exec, std::move(values)},
299 array<index_type>{exec, std::move(col_idxs)},
300 num_stored_elements_per_row, stride);
301 }
302
316 static std::unique_ptr<const Ell> create_const(
317 std::shared_ptr<const Executor> exec, const dim<2>& size,
318 gko::detail::const_array_view<ValueType>&& values,
319 gko::detail::const_array_view<IndexType>&& col_idxs,
320 size_type num_stored_elements_per_row, size_type stride);
321
327 Ell& operator=(const Ell&);
328
335
340 Ell(const Ell&);
341
347
348protected:
349 Ell(std::shared_ptr<const Executor> exec, const dim<2>& size = {},
350 size_type num_stored_elements_per_row = 0, size_type stride = 0);
351
352 Ell(std::shared_ptr<const Executor> exec, const dim<2>& size,
353 array<value_type> values, array<index_type> col_idxs,
354 size_type num_stored_elements_per_row, size_type stride);
355
365 void resize(dim<2> new_size, size_type max_row_nnz);
366
367 void apply_impl(const LinOp* b, LinOp* x) const override;
368
369 void apply_impl(const LinOp* alpha, const LinOp* b, const LinOp* beta,
370 LinOp* x) const override;
371
372 size_type linearize_index(size_type row, size_type col) const noexcept
373 {
374 return row + stride_ * col;
375 }
376
377private:
378 size_type num_stored_elements_per_row_;
379 size_type stride_;
380 array<value_type> values_;
381 array<index_type> col_idxs_;
382};
383
384
385} // namespace matrix
386} // namespace gko
387
388
389#endif // GKO_PUBLIC_CORE_MATRIX_ELL_HPP_
Definition polymorphic_object.hpp:479
Definition lin_op.hpp:742
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: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
size_type get_size() const noexcept
Definition array.hpp:656
Definition device_matrix_data.hpp:36
Definition coo.hpp:61
Definition csr.hpp:123
Definition dense.hpp:116
Definition ell.hpp:63
value_type & val_at(size_type row, size_type idx) noexcept
Definition ell.hpp:206
size_type get_num_stored_elements_per_row() const noexcept
Definition ell.hpp:174
size_type get_stride() const noexcept
Definition ell.hpp:184
static std::unique_ptr< Ell > create(std::shared_ptr< const Executor > exec, const dim< 2 > &size={}, size_type num_stored_elements_per_row=0, size_type stride=0)
index_type col_at(size_type row, size_type idx) const noexcept
Definition ell.hpp:237
value_type * get_values() noexcept
Definition ell.hpp:136
void read(const mat_data &data) override
value_type val_at(size_type row, size_type idx) const noexcept
Definition ell.hpp:214
Ell & operator=(Ell &&)
void compute_absolute_inplace() override
void read(const device_mat_data &data) override
void resize(dim< 2 > new_size, size_type max_row_nnz)
std::unique_ptr< Diagonal< ValueType > > extract_diagonal() const override
index_type * get_col_idxs() noexcept
Definition ell.hpp:155
std::unique_ptr< absolute_type > compute_absolute() const override
Ell(const Ell &)
static std::unique_ptr< Ell > create(std::shared_ptr< const Executor > exec, const dim< 2 > &size, array< value_type > values, array< index_type > col_idxs, size_type num_stored_elements_per_row, size_type stride)
const index_type * get_const_col_idxs() const noexcept
Definition ell.hpp:164
static std::unique_ptr< const Ell > create_const(std::shared_ptr< const Executor > exec, const dim< 2 > &size, gko::detail::const_array_view< ValueType > &&values, gko::detail::const_array_view< IndexType > &&col_idxs, size_type num_stored_elements_per_row, size_type stride)
Ell & operator=(const Ell &)
const value_type * get_const_values() const noexcept
Definition ell.hpp:145
index_type & col_at(size_type row, size_type idx) noexcept
Definition ell.hpp:229
void read(device_mat_data &&data) override
size_type get_num_stored_elements() const noexcept
Definition ell.hpp:191
void write(mat_data &data) const override
Definition hybrid.hpp:54
The Ginkgo namespace.
Definition abstract_factory.hpp:20
typename detail::next_precision_impl< T >::type next_precision
Definition math.hpp:438
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 dim.hpp:26
Definition matrix_data.hpp:126