MUDA
Loading...
Searching...
No Matches
doublet_vector_view.h
1#pragma once
2#include <muda/view/view_base.h>
3#include <muda/ext/linear_system/doublet_vector_viewer.h>
4
5namespace muda
6{
7template <bool IsConst, typename T, int N>
8class DoubletVectorViewBase : public ViewBase<IsConst>
9{
10 using Base = ViewBase<IsConst>;
11 template <typename U>
12 using auto_const_t = typename Base::template auto_const_t<U>;
13
14 public:
15 using SegmentVector = Eigen::Matrix<T, N, 1>;
19
22 using ThisViewer = std::conditional_t<IsConst, ConstViewer, NonConstViewer>;
23
24 protected:
25 // vector info
26 int m_total_segment_count = 0;
27
28 // doublet info
29 int m_doublet_index_offset = 0;
30 int m_doublet_count = 0;
31 int m_total_doublet_count = 0;
32
33 // subvector info
34 int m_subvector_offset = 0;
35 int m_subvector_extent = 0;
36
37 // data
38 auto_const_t<int>* m_segment_indices;
39 auto_const_t<SegmentVector>* m_segment_values;
40
41 public:
42 MUDA_GENERIC DoubletVectorViewBase() = default;
43 MUDA_GENERIC DoubletVectorViewBase(int total_segment_count,
44 int doublet_index_offset,
45 int doublet_count,
46 int total_doublet_count,
47
48 int subvector_offset,
49 int subvector_extent,
50
51 auto_const_t<int>* segment_indices,
52 auto_const_t<SegmentVector>* segment_values)
53 : m_total_segment_count(total_segment_count)
54 , m_doublet_index_offset(doublet_index_offset)
55 , m_doublet_count(doublet_count)
56 , m_total_doublet_count(total_doublet_count)
57 , m_subvector_offset(subvector_offset)
58 , m_subvector_extent(subvector_extent)
59 , m_segment_indices(segment_indices)
60 , m_segment_values(segment_values)
61 {
62 MUDA_KERNEL_ASSERT(doublet_index_offset + doublet_count <= total_doublet_count,
63 "DoubletVectorView: out of range, m_total_doublet_count=%d, "
64 "your doublet_index_offset=%d, doublet_count=%d",
65 m_total_doublet_count,
66 doublet_index_offset,
67 doublet_count);
68
69 MUDA_KERNEL_ASSERT(subvector_offset + subvector_extent <= total_segment_count,
70 "DoubletVectorView: out of range, m_total_segment_count=%d, "
71 "your subvector_offset=%d, subvector_extent=%d",
72 m_total_segment_count,
73 subvector_offset,
74 subvector_extent);
75 }
76
77 MUDA_GENERIC DoubletVectorViewBase(int total_segment_count,
78 int total_doublet_count,
79 auto_const_t<int>* segment_indices,
80 auto_const_t<SegmentVector>* segment_values)
81 : DoubletVectorViewBase(total_segment_count,
82 0,
83 total_doublet_count,
84 total_doublet_count,
85 0,
86 total_segment_count,
87 segment_indices,
88 segment_values)
89 {
90 }
91
92 // implicit conversion
93
94 MUDA_GENERIC ConstView as_const() const noexcept
95 {
96 return ConstView{m_total_segment_count,
97 m_doublet_index_offset,
98 m_doublet_count,
99 m_total_doublet_count,
100 m_subvector_offset,
101 m_subvector_extent,
102 m_segment_indices,
103 m_segment_values};
104 }
105
106 MUDA_GENERIC operator ConstView() const noexcept { return as_const(); }
107
108 // non-const access
109
110 MUDA_GENERIC ThisView subview(int offset, int count) const noexcept
111 {
112
113 MUDA_KERNEL_ASSERT(offset + count <= m_doublet_count,
114 "DoubletVectorView : offset is out of range, size=%d, your offset=%d",
115 m_doublet_count,
116 offset);
117
118 return ThisView{m_total_segment_count,
119 m_doublet_index_offset + offset,
120 count,
121 m_total_doublet_count,
122 m_subvector_offset,
123 m_subvector_extent,
124 m_segment_indices,
125 m_segment_values};
126 }
127
128 MUDA_GENERIC ThisView subview(int offset) const noexcept
129 {
130 return subview(offset, m_doublet_count - offset);
131 }
132
133 MUDA_GENERIC auto subvector(int offset, int extent) const noexcept
134 {
135 MUDA_KERNEL_ASSERT(offset + extent <= m_subvector_extent,
136 "DoubletVectorView : subvector out of range, extent=%d, your offset=%d, your extent=%d",
137 m_subvector_extent,
138 offset,
139 extent);
140
141 return ThisView{m_total_segment_count,
142 m_doublet_index_offset,
143 m_doublet_count,
144 m_total_doublet_count,
145 m_subvector_offset + offset,
146 extent,
147 m_segment_indices,
148 m_segment_values};
149 }
150
151 MUDA_GENERIC ThisViewer viewer() noexcept
152 {
153 return ThisViewer{m_total_segment_count,
154 m_doublet_index_offset,
155 m_doublet_count,
156 m_total_doublet_count,
157 m_subvector_offset,
158 m_subvector_extent,
159 m_segment_indices,
160 m_segment_values};
161 }
162
163 MUDA_GENERIC ConstViewer cviewer() const noexcept
164 {
165 return ConstViewer{m_total_segment_count,
166 m_doublet_index_offset,
167 m_doublet_count,
168 m_total_doublet_count,
169 m_subvector_offset,
170 m_subvector_extent,
171 m_segment_indices,
172 m_segment_values};
173 }
174
175 MUDA_GENERIC int extent() const noexcept { return m_subvector_extent; }
176
177 MUDA_GENERIC int total_extent() const noexcept
178 {
179 return m_total_segment_count;
180 }
181
182 MUDA_GENERIC int subvector_offset() const noexcept
183 {
184 return m_subvector_offset;
185 }
186
187 MUDA_GENERIC int doublet_count() const noexcept { return m_doublet_count; }
188 MUDA_GENERIC int total_doublet_count() const noexcept
189 {
190 return m_total_doublet_count;
191 }
192};
193
194template <bool IsConst, typename T>
195class DoubletVectorViewBase<IsConst, T, 1> : public ViewBase<IsConst>
196{
197 using Base = ViewBase<IsConst>;
198 protected:
199 template <typename U>
200 using auto_const_t = typename Base::template auto_const_t<U>;
201 public:
205
208 using ThisViewer = std::conditional_t<IsConst, ConstViewer, NonConstViewer>;
209
210 protected:
211 int m_total_count = 0;
212
213 int m_doublet_index_offset = 0;
214 int m_doublet_count = 0;
215 int m_total_doublet_count = 0;
216
217 int m_subvector_offset = 0;
218 int m_subvector_extent = 0;
219
220 auto_const_t<int>* m_indices;
221 auto_const_t<T>* m_values;
222
223
224 public:
225 MUDA_GENERIC DoubletVectorViewBase() = default;
226 MUDA_GENERIC DoubletVectorViewBase(int total_count,
227 int doublet_index_offset,
228 int doublet_count,
229 int total_doublet_count,
230 int subvector_offset,
231 int subvector_extent,
232 auto_const_t<int>* indices,
233 auto_const_t<T>* values)
234 : m_total_count(total_count)
235 , m_doublet_index_offset(doublet_index_offset)
236 , m_doublet_count(doublet_count)
237 , m_total_doublet_count(total_doublet_count)
238 , m_subvector_offset(subvector_offset)
239 , m_subvector_extent(subvector_extent)
240 , m_indices(indices)
241 , m_values(values)
242 {
243 MUDA_KERNEL_ASSERT(doublet_index_offset + doublet_count <= total_doublet_count,
244 "DoubletVectorView: out of range, m_total_count=%d, "
245 "your doublet_index_offset=%d, doublet_count=%d",
246 m_total_doublet_count,
247 doublet_index_offset,
248 doublet_count);
249
250 MUDA_KERNEL_ASSERT(subvector_offset + subvector_extent <= total_count,
251 "DoubletVectorView: out of range, m_total_count=%d, "
252 "your subvector_offset=%d, subvector_extent=%d",
253 total_count,
254 subvector_offset,
255 subvector_extent);
256 }
257
258 MUDA_GENERIC DoubletVectorViewBase(int total_count,
259 int total_doublet_count,
260 auto_const_t<int>* indices,
261 auto_const_t<T>* values)
263 total_count, 0, total_doublet_count, total_doublet_count, 0, total_count, indices, values)
264 {
265 }
266
267 // implicit conversion
268
269 MUDA_GENERIC ConstView as_const() const noexcept
270 {
271 return ConstView{m_total_count,
272 m_doublet_index_offset,
273 m_doublet_count,
274 m_total_doublet_count,
275 m_subvector_offset,
276 m_subvector_extent,
277 m_indices,
278 m_values};
279 }
280
281 MUDA_GENERIC operator ConstView() const noexcept { return as_const(); }
282
283 // non-const access
284
285 MUDA_GENERIC auto subview(int offset, int count) const noexcept
286 {
287 MUDA_KERNEL_ASSERT(offset + count <= m_doublet_count,
288 "DoubletVectorView : offset is out of range, size=%d, your offset=%d",
289 m_doublet_count,
290 offset);
291
292 return ThisView{m_total_count,
293 m_doublet_index_offset + offset,
294 count,
295 m_total_doublet_count,
296 m_subvector_offset,
297 m_subvector_extent,
298 m_indices,
299 m_values};
300 }
301
302 MUDA_GENERIC auto subview(int offset) const noexcept
303 {
304 return subview(offset, m_doublet_count - offset);
305 }
306
307 MUDA_GENERIC auto subvector(int offset, int extent) const noexcept
308 {
309 MUDA_KERNEL_ASSERT(offset + extent <= m_subvector_extent,
310 "DoubletVectorView : subvector out of range, extent=%d, your offset=%d, your extent=%d",
311 m_subvector_extent,
312 offset,
313 extent);
314
315 return ThisView{m_total_count,
316 m_doublet_index_offset,
317 m_doublet_count,
318 m_total_doublet_count,
319 m_subvector_offset + offset,
320 extent,
321 m_indices,
322 m_values};
323 }
324
325 MUDA_GENERIC ThisViewer viewer() noexcept
326 {
327 return ThisViewer{m_total_count,
328 m_doublet_index_offset,
329 m_doublet_count,
330 m_total_doublet_count,
331
332 m_subvector_offset,
333 m_subvector_extent,
334
335 m_indices,
336 m_values};
337 }
338
339 MUDA_GENERIC ConstViewer cviewer() const noexcept
340 {
341 return ConstViewer{m_total_count,
342 m_doublet_index_offset,
343 m_doublet_count,
344 m_total_doublet_count,
345 m_subvector_offset,
346 m_subvector_extent,
347 m_indices,
348 m_values};
349 }
350
351
352 MUDA_GENERIC int doublet_count() const noexcept { return m_doublet_count; }
353 MUDA_GENERIC int total_doublet_count() const noexcept
354 {
355 return m_total_doublet_count;
356 }
357
358 MUDA_GENERIC int extent() const noexcept { return m_subvector_extent; }
359 MUDA_GENERIC int total_extent() const noexcept { return m_total_count; }
360
361 MUDA_GENERIC int subvector_offset() const noexcept
362 {
363 return m_subvector_offset;
364 }
365};
366
367template <typename T, int N>
369template <typename T, int N>
371} // namespace muda
372
373namespace muda
374{
375template <typename Ty, int N>
380
381template <typename Ty, int N>
386} // namespace muda
387
388#include "details/doublet_vector_view.inl"
Definition doublet_vector_viewer.h:356
Definition doublet_vector_viewer.h:148
Definition doublet_vector_view.h:196
Definition doublet_vector_view.h:9
Definition doublet_vector_viewer.h:371
Definition doublet_vector_viewer.h:163
Definition view_base.h:8
Definition type_modifier.h:22
Definition type_modifier.h:28