Ginkgo Generated from branch based on main. Ginkgo version 1.11.0
A numerical linear algebra library targeting many-core architectures
Loading...
Searching...
No Matches
batch_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_BATCH_ELL_HPP_
6#define GKO_PUBLIC_CORE_MATRIX_BATCH_ELL_HPP_
7
8
9#include <initializer_list>
10#include <vector>
11
12#include <ginkgo/core/base/array.hpp>
13#include <ginkgo/core/base/batch_lin_op.hpp>
14#include <ginkgo/core/base/batch_multi_vector.hpp>
15#include <ginkgo/core/base/executor.hpp>
16#include <ginkgo/core/base/mtx_io.hpp>
17#include <ginkgo/core/base/range_accessors.hpp>
18#include <ginkgo/core/base/types.hpp>
19#include <ginkgo/core/base/utils.hpp>
20#include <ginkgo/core/base/utils_helper.hpp>
21#include <ginkgo/core/matrix/ell.hpp>
22
23
24namespace gko {
25namespace batch {
26namespace matrix {
27
28
51template <typename ValueType = default_precision, typename IndexType = int32>
52class Ell final
53 : public EnableBatchLinOp<Ell<ValueType, IndexType>>,
54#if GINKGO_ENABLE_HALF || GINKGO_ENABLE_BFLOAT16
55 public ConvertibleTo<Ell<next_precision<ValueType, 2>, IndexType>>,
56#endif
57#if GINKGO_ENABLE_HALF && GINKGO_ENABLE_BFLOAT16
58 public ConvertibleTo<Ell<next_precision<ValueType, 3>, IndexType>>,
59#endif
60 public ConvertibleTo<Ell<next_precision<ValueType>, IndexType>> {
61 friend class EnablePolymorphicObject<Ell, BatchLinOp>;
62 friend class Ell<to_complex<ValueType>, IndexType>;
63 friend class Ell<previous_precision<ValueType>, IndexType>;
64 GKO_ASSERT_SUPPORTED_VALUE_TYPE;
65 static_assert(std::is_same<IndexType, int32>::value,
66 "IndexType must be a 32 bit integer");
67
68public:
69 using EnableBatchLinOp<Ell>::convert_to;
70 using EnableBatchLinOp<Ell>::move_to;
71
72 using value_type = ValueType;
73 using index_type = IndexType;
75 using absolute_type = remove_complex<Ell>;
76 using complex_type = to_complex<Ell>;
77
78 void convert_to(
79 Ell<next_precision<ValueType>, IndexType>* result) const override;
80
81 void move_to(Ell<next_precision<ValueType>, IndexType>* result) override;
82
83#if GINKGO_ENABLE_HALF || GINKGO_ENABLE_BFLOAT16
84 friend class Ell<previous_precision<ValueType, 2>, IndexType>;
85 using ConvertibleTo<
86 Ell<next_precision<ValueType, 2>, IndexType>>::convert_to;
87 using ConvertibleTo<Ell<next_precision<ValueType, 2>, IndexType>>::move_to;
88
89 void convert_to(
90 Ell<next_precision<ValueType, 2>, IndexType>* result) const override;
91
92 void move_to(Ell<next_precision<ValueType, 2>, IndexType>* result) override;
93#endif
94
95#if GINKGO_ENABLE_HALF && GINKGO_ENABLE_BFLOAT16
96 friend class Ell<previous_precision<ValueType, 3>, IndexType>;
97 using ConvertibleTo<
98 Ell<next_precision<ValueType, 3>, IndexType>>::convert_to;
99 using ConvertibleTo<Ell<next_precision<ValueType, 3>, IndexType>>::move_to;
100
101 void convert_to(
102 Ell<next_precision<ValueType, 3>, IndexType>* result) const override;
103
104 void move_to(Ell<next_precision<ValueType, 3>, IndexType>* result) override;
105#endif
106
117 std::unique_ptr<unbatch_type> create_view_for_item(size_type item_id);
118
122 std::unique_ptr<const unbatch_type> create_const_view_for_item(
123 size_type item_id) const;
124
130 value_type* get_values() noexcept { return values_.get_data(); }
131
139 const value_type* get_const_values() const noexcept
140 {
141 return values_.get_const_data();
142 }
143
149 index_type* get_col_idxs() noexcept { return col_idxs_.get_data(); }
150
158 const index_type* get_const_col_idxs() const noexcept
159 {
160 return col_idxs_.get_const_data();
161 }
162
169 index_type get_num_stored_elements_per_row() const noexcept
170 {
171 return num_elems_per_row_;
172 }
173
182 {
183 return values_.get_size();
184 }
185
192 {
193 return this->get_num_stored_elements() / this->get_num_batch_items();
194 }
195
204 index_type* get_col_idxs_for_item(size_type batch_id) noexcept
205 {
206 GKO_ASSERT(batch_id < this->get_num_batch_items());
207 return col_idxs_.get_data();
208 }
209
218 size_type batch_id) const noexcept
219 {
220 GKO_ASSERT(batch_id < this->get_num_batch_items());
221 return col_idxs_.get_const_data();
222 }
223
232 value_type* get_values_for_item(size_type batch_id) noexcept
233 {
234 GKO_ASSERT(batch_id < this->get_num_batch_items());
235 return values_.get_data() +
236 batch_id * this->get_num_elements_per_item();
237 }
238
246 const value_type* get_const_values_for_item(
247 size_type batch_id) const noexcept
248 {
249 GKO_ASSERT(batch_id < this->get_num_batch_items());
250 return values_.get_const_data() +
251 batch_id * this->get_num_elements_per_item();
252 }
253