ginkgo/core/matrix/coo.hpp Source File

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

Reference API: ginkgo/core/matrix/coo.hpp Source File
Reference API
coo.hpp
1// SPDX-FileCopyrightText: 2017 - 2025 The Ginkgo authors
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
5#ifndef GKO_PUBLIC_CORE_MATRIX_COO_HPP_
6#define GKO_PUBLIC_CORE_MATRIX_COO_HPP_
7
8
9#include <ginkgo/core/base/array.hpp>
10#include <ginkgo/core/base/lin_op.hpp>
11
12
13namespace gko {
19namespace matrix {
20
21
22template <typename ValueType, typename IndexType>
23class Csr;
24
25template <typename ValueType>
26class Dense;
27
28template <typename ValueType, typename IndexType>
30
31template <typename ValueType, typename IndexType>
32class Hybrid;
33
34
48template <typename ValueType = default_precision, typename IndexType = int32>
49class Coo : public EnableLinOp<Coo<ValueType, IndexType>>,
50 public ConvertibleTo<Coo<next_precision<ValueType>, IndexType>>,
51#if GINKGO_ENABLE_HALF
52 public ConvertibleTo<
53 Coo<next_precision<next_precision<ValueType>>, IndexType>>,
54#endif
55 public ConvertibleTo<Csr<ValueType, IndexType>>,
56 public ConvertibleTo<Dense<ValueType>>,
57 public DiagonalExtractable<ValueType>,
58 public ReadableFromMatrixData<ValueType, IndexType>,
59 public WritableToMatrixData<ValueType, IndexType>,
61 remove_complex<Coo<ValueType, IndexType>>> {
62 friend class EnablePolymorphicObject<Coo, LinOp>;
63 friend class Csr<ValueType, IndexType>;
64 friend class Dense<ValueType>;
65 friend class CooBuilder<ValueType, IndexType>;
66 friend class Coo<to_complex<ValueType>, IndexType>;
67 friend class Hybrid<ValueType, IndexType>;
68
69public:
70 using EnableLinOp<Coo>::convert_to;
71 using EnableLinOp<Coo>::move_to;
72 using ConvertibleTo<Coo<next_precision<ValueType>, IndexType>>::convert_to;
73 using ConvertibleTo<Coo<next_precision<ValueType>, IndexType>>::move_to;
76 using ConvertibleTo<Dense<ValueType>>::convert_to;
77 using ConvertibleTo<Dense<ValueType>>::move_to;
78 using ReadableFromMatrixData<ValueType, IndexType>::read;
79
80 using value_type = ValueType;
81 using index_type = IndexType;
84 using absolute_type = remove_complex<Coo>;
85
86 friend class Coo<previous_precision<ValueType>, IndexType>;
87
88 void convert_to(
89 Coo<next_precision<ValueType>, IndexType>* result) const override;
90
91 void move_to(Coo<next_precision<ValueType>, IndexType>* result) override;
92
93#if GINKGO_ENABLE_HALF
94 friend class Coo<previous_precision<previous_precision<ValueType>>,
95 IndexType>;
96 using ConvertibleTo<
97 Coo<next_precision<next_precision<ValueType>>, IndexType>>::convert_to;
98 using ConvertibleTo<
100
101 void convert_to(Coo<next_precision<next_precision<ValueType>>, IndexType>*
102 result) const override;
103
104 void move_to(Coo<next_precision<next_precision<ValueType>>, IndexType>*
105 result) override;
106#endif
107
108 void convert_to(Csr<ValueType, IndexType>* other) const override;
109
110 void move_to(Csr<ValueType, IndexType>* other) override;
111
112 void convert_to(Dense<ValueType>* other) const override;
113
114 void move_to(Dense<ValueType>* other) override;
115
116 void read(const mat_data& data) override;
117
118 void read(const device_mat_data& data) override;
119
120 void read(device_mat_data&& data) override;
121
122 void write(mat_data& data) const override;
123
124 std::unique_ptr<Diagonal<ValueType>> extract_diagonal() const override;
125
126 std::unique_ptr<absolute_type> compute_absolute() const override;
127
129
135 value_type* get_values() noexcept { return values_.get_data(); }
136
144 const value_type* get_const_values() const noexcept
145 {
146 return values_.get_const_data();
147 }
148
154 index_type* get_col_idxs() noexcept { return col_idxs_.get_data(); }
155
163 const index_type* get_const_col_idxs() const noexcept
164 {
165 return col_idxs_.get_const_data();
166 }
167
173 index_type* get_row_idxs() noexcept { return row_idxs_.get_data(); }
174
182 const index_type* get_const_row_idxs() const noexcept
183 {
184 return row_idxs_.get_const_data();
185 }
186
193 {
194 return values_.get_size();
195 }
196
208
213
225
230 ptr_param<LinOp> x) const;
231
241 static std::unique_ptr<Coo> create(std::shared_ptr<const Executor> exec,
242 const dim<2>& size = dim<2>{},
243 size_type num_nonzeros = {});
244
265 static std::unique_ptr<Coo> create(std::shared_ptr<const Executor> exec,
266 const dim<2>& size,
267 array<value_type> values,
268 array<index_type> col_idxs,
269 array<index_type> row_idxs);
270
275 template <typename InputValueType, typename InputColumnIndexType,
276 typename InputRowIndexType>
277 GKO_DEPRECATED(
278 "explicitly construct the gko::array argument instead of passing "
279 "initializer lists")
280 static std::unique_ptr<Coo> create(
281 std::shared_ptr<const Executor> exec, const dim<2>& size,
282 std::initializer_list<InputValueType> values,
283 std::initializer_list<InputColumnIndexType> col_idxs,
284 std::initializer_list<InputRowIndexType> row_idxs)
285 {
286 return create(exec, size, array<value_type>{exec, std::move(values)},
287 array<index_type>{exec, std::move(col_idxs)},
288 array<index_type>{exec, std::move(row_idxs)});
289 }
290
304 static std::unique_ptr<const Coo> create_const(
305 std::shared_ptr<const Executor> exec, const dim<2>& size,
306 gko::detail::const_array_view<ValueType>&& values,
307 gko::detail::const_array_view<IndexType>&& col_idxs,
308 gko::detail::const_array_view<IndexType>&& row_idxs);
309
310protected:
311 Coo(std::shared_ptr<const Executor> exec, const dim<2>& size = dim<2>{},
312 size_type num_nonzeros = {});
313
314 Coo(std::shared_ptr<const Executor> exec, const dim<2>& size,
315 array<value_type> values, array<index_type> col_idxs,
316 array<index_type> row_idxs);
317
325 void resize(dim<2> new_size, size_type nnz);
326
327 void apply_impl(const LinOp* b, LinOp* x) const override;
328
329 void apply_impl(const LinOp* alpha, const LinOp* b, const LinOp* beta,
330 LinOp* x) const override;
331
332 void apply2_impl(const LinOp* b, LinOp* x) const;
333
334 void apply2_impl(const LinOp* alpha, const LinOp* b, LinOp* x) const;
335
336private:
337 array<value_type> values_;
338 array<index_type> col_idxs_;
339 array<index_type> row_idxs_;
340};
341
342
343} // namespace matrix
344} // namespace gko
345
346
347#endif // GKO_PUBLIC_CORE_MATRIX_COO_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:29
Definition coo.hpp:61
index_type * get_col_idxs() noexcept
Definition coo.hpp:154
const index_type * get_const_col_idxs() const noexcept
Definition coo.hpp:163
void read(const device_mat_data &data) override
static std::unique_ptr< const Coo > 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, gko::detail::const_array_view< IndexType > &&row_idxs)
void resize(dim< 2 > new_size, size_type nnz)
void read(device_mat_data &&data) override
const LinOp * apply2(ptr_param< const LinOp > alpha, ptr_param< const LinOp > b, ptr_param< LinOp > x) const
LinOp * apply2(ptr_param< const LinOp > b, ptr_param< LinOp > x)
LinOp * apply2(ptr_param< const LinOp > alpha, ptr_param< const LinOp > b, ptr_param< LinOp > x)
void compute_absolute_inplace() override
const value_type * get_const_values() const noexcept
Definition coo.hpp:144
void read(const mat_data &data) override
const index_type * get_const_row_idxs() const noexcept
Definition coo.hpp:182
const LinOp * apply2(ptr_param< const LinOp > b, ptr_param< LinOp > x) const
std::unique_ptr< absolute_type > compute_absolute() const override
static std::unique_ptr< Coo > create(std::shared_ptr< const Executor > exec, const dim< 2 > &size=dim< 2 >{}, size_type num_nonzeros={})
void write(mat_data &data) const override
size_type get_num_stored_elements() const noexcept
Definition coo.hpp:192
std::unique_ptr< Diagonal< ValueType > > extract_diagonal() const override
index_type * get_row_idxs() noexcept
Definition coo.hpp:173
static std::unique_ptr< Coo > create(std::shared_ptr< const Executor > exec, const dim< 2 > &size, array< value_type > values, array< index_type > col_idxs, array< index_type > row_idxs)
value_type * get_values() noexcept
Definition coo.hpp:135
Definition csr.hpp:123
Definition dense.hpp:116
Definition hybrid.hpp:54
Definition utils_helper.hpp:41
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