13 using auto_const_t =
typename Base::template auto_const_t<U>;
16 static_assert(!std::is_const_v<Ty>,
"Ty must be non-const");
24 using ThisViewer = std::conditional_t<IsConst, ConstViewer, NonConstViewer>;
27 using BlockMatrix = Eigen::Matrix<Ty, N, N>;
31 int m_total_block_rows = 0;
32 int m_total_block_cols = 0;
35 int m_triplet_index_offset = 0;
36 int m_triplet_count = 0;
37 int m_total_triplet_count = 0;
40 int2 m_submatrix_offset = {0, 0};
41 int2 m_submatrix_extent = {0, 0};
44 auto_const_t<int>* m_block_row_indices =
nullptr;
45 auto_const_t<int>* m_block_col_indices =
nullptr;
46 auto_const_t<BlockMatrix>* m_block_values =
nullptr;
53 int triplet_index_offset,
55 int total_triplet_count,
57 int2 submatrix_offset,
58 int2 submatrix_extent,
60 auto_const_t<int>* block_row_indices,
61 auto_const_t<int>* block_col_indices,
62 auto_const_t<BlockMatrix>* block_values)
63 : m_total_block_rows(total_block_rows)
64 , m_total_block_cols(total_block_cols)
65 , m_triplet_index_offset(triplet_index_offset)
66 , m_triplet_count(triplet_count)
67 , m_total_triplet_count(total_triplet_count)
68 , m_block_row_indices(block_row_indices)
69 , m_block_col_indices(block_col_indices)
70 , m_block_values(block_values)
71 , m_submatrix_offset(submatrix_offset)
72 , m_submatrix_extent(submatrix_extent)
74 MUDA_KERNEL_ASSERT(triplet_index_offset + triplet_count <= total_triplet_count,
75 "TripletMatrixView: out of range, m_total_triplet_count=%d, "
76 "your triplet_index_offset=%d, triplet_count=%d",
81 MUDA_KERNEL_ASSERT(submatrix_offset.x >= 0 && submatrix_offset.y >= 0,
82 "TripletMatrixView: submatrix_offset is out of range, submatrix_offset.x=%d, submatrix_offset.y=%d",
86 MUDA_KERNEL_ASSERT(submatrix_offset.x + submatrix_extent.x <= total_block_rows,
87 "TripletMatrixView: submatrix is out of range, submatrix_offset.x=%d, submatrix_extent.x=%d, total_block_rows=%d",
92 MUDA_KERNEL_ASSERT(submatrix_offset.y + submatrix_extent.y <= total_block_cols,
93 "TripletMatrixView: submatrix is out of range, submatrix_offset.y=%d, submatrix_extent.y=%d, total_block_cols=%d",
100 int total_block_cols,
101 int total_triplet_count,
102 auto_const_t<int>* block_row_indices,
103 auto_const_t<int>* block_col_indices,
104 auto_const_t<BlockMatrix>* block_values)
111 {total_block_rows, total_block_cols},
123 m_triplet_index_offset,
125 m_total_triplet_count,
134 MUDA_GENERIC
operator ConstView()
const {
return as_const(); }
136 MUDA_GENERIC
auto subview(
int offset,
int count)
const
138 MUDA_ASSERT(offset + count <= m_triplet_count,
139 "TripletMatrixView: offset is out of range, size=%d, your offset=%d, your count=%d",
146 m_triplet_index_offset + offset,
148 m_total_triplet_count,
156 MUDA_GENERIC
auto subview(
int offset)
const
158 return subview(offset, m_triplet_count - offset);
161 MUDA_GENERIC
auto cviewer()
const
165 m_triplet_index_offset,
167 m_total_triplet_count,
175 MUDA_GENERIC
auto viewer()
177 return ThisViewer{m_total_block_rows,
179 m_triplet_index_offset,
181 m_total_triplet_count,
190 MUDA_GENERIC auto_const_t<BlockMatrix>* block_values()
192 return m_block_values;
194 MUDA_GENERIC auto_const_t<int>* block_row_indices()
196 return m_block_row_indices;
198 MUDA_GENERIC auto_const_t<int>* block_col_indices()
200 return m_block_col_indices;
203 MUDA_GENERIC
auto submatrix(int2 offset, int2 extent)
const
205 MUDA_KERNEL_ASSERT(offset.x >= 0 && offset.y >= 0,
206 "TripletMatrixView: submatrix is out of range, offset=(%d, %d)",
210 MUDA_KERNEL_ASSERT(offset.x + extent.x <= m_submatrix_extent.x
211 && offset.y + extent.y <= m_submatrix_extent.y,
212 "TripletMatrixView: submatrix is out of range, offset=(%d, %d), extent=(%d, %d), origin offset=(%d,%d), extent(%d,%d).",
217 m_submatrix_offset.x,
218 m_submatrix_offset.y,
219 m_submatrix_extent.x,
220 m_submatrix_extent.y);
224 m_triplet_index_offset,
226 m_total_triplet_count,
227 m_submatrix_offset + offset,
235 MUDA_GENERIC
auto total_block_rows()
const {
return m_total_block_rows; }
236 MUDA_GENERIC
auto total_block_cols()
const {
return m_total_block_cols; }
237 MUDA_GENERIC
auto total_extent()
const
239 return int2{m_total_block_rows, m_total_block_cols};
242 MUDA_GENERIC
auto submatrix_offset()
const {
return m_submatrix_offset; }
243 MUDA_GENERIC
auto extent()
const {
return m_submatrix_extent; }
245 MUDA_GENERIC
auto triplet_count()
const {
return m_triplet_count; }
246 MUDA_GENERIC
auto tripet_index_offset()
const
248 return m_triplet_index_offset;
250 MUDA_GENERIC
auto total_triplet_count()
const
252 return m_total_triplet_count;
262 template <
typename U>
263 using auto_const_t =
typename Base::template auto_const_t<U>;
266 static_assert(!std::is_const_v<Ty>,
"Ty must be non-const");
274 using ThisViewer = std::conditional_t<IsConst, ConstViewer, NonConstViewer>;
278 int m_total_rows = 0;
279 int m_total_cols = 0;
282 int m_triplet_index_offset = 0;
283 int m_triplet_count = 0;
284 int m_total_triplet_count = 0;
287 int2 m_submatrix_offset = {0, 0};
288 int2 m_submatrix_extent = {0, 0};
291 auto_const_t<int>* m_row_indices;
292 auto_const_t<int>* m_col_indices;
293 auto_const_t<Ty>* m_values;
301 int triplet_index_offset,
303 int total_triplet_count,
305 int2 submatrix_offset,
306 int2 submatrix_extent,
308 auto_const_t<int>* row_indices,
309 auto_const_t<int>* col_indices,
310 auto_const_t<Ty>* values)
311 : m_total_rows(total_rows)
312 , m_total_cols(total_cols)
313 , m_triplet_index_offset(triplet_index_offset)
314 , m_triplet_count(triplet_count)
315 , m_total_triplet_count(total_triplet_count)
316 , m_submatrix_offset(submatrix_offset)
317 , m_submatrix_extent(submatrix_extent)
318 , m_row_indices(row_indices)
319 , m_col_indices(col_indices)
322 MUDA_KERNEL_ASSERT(triplet_index_offset + triplet_count <= total_triplet_count,
323 "TripletMatrixView: out of range, m_total_triplet_count=%d, "
324 "your triplet_index_offset=%d, triplet_count=%d",
326 triplet_index_offset,
329 MUDA_KERNEL_ASSERT(submatrix_offset.x >= 0 && submatrix_offset.y >= 0,
330 "TripletMatrixView: submatrix_offset is out of range, submatrix_offset.x=%d, submatrix_offset.y=%d",
334 MUDA_KERNEL_ASSERT(submatrix_offset.x + submatrix_extent.x <= total_rows,
335 "TripletMatrixView: submatrix is out of range, submatrix_offset.x=%d, submatrix_extent.x=%d, total_rows=%d",
340 MUDA_KERNEL_ASSERT(submatrix_offset.y + submatrix_extent.y <= total_cols,
341 "TripletMatrixView: submatrix is out of range, submatrix_offset.y=%d, submatrix_extent.y=%d, total_cols=%d",
350 int total_triplet_count,
351 auto_const_t<int>* row_indices,
352 auto_const_t<int>* col_indices,
353 auto_const_t<Ty>* values)
360 {total_rows, total_cols},
373 m_triplet_index_offset,
375 m_total_triplet_count,
384 MUDA_GENERIC
operator ConstView()
const {
return as_const(); }
386 MUDA_GENERIC
auto subview(
int offset,
int count)
const
388 MUDA_ASSERT(offset + count < m_triplet_count,
389 "TripletMatrixView: offset is out of range, size=%d, your offset=%d, your count=%d",
396 m_triplet_index_offset + offset,
398 m_total_triplet_count,
406 MUDA_GENERIC
auto submatrix(int2 offset, int2 extent)
const
408 MUDA_KERNEL_ASSERT(offset.x >= 0 && offset.y >= 0,
409 "TripletMatrixView: submatrix is out of range, submatrix_offset.x=%d, submatrix_offset.y=%d",
413 MUDA_KERNEL_ASSERT(offset.x + extent.x <= m_submatrix_extent.x
414 && offset.y + extent.y <= m_submatrix_extent.y,
415 "TripletMatrixView: submatrix is out of range, submatrix_offset.x=%d, submatrix_extent.x=%d, submatrix_offset.y=%d, submatrix_extent.y=%d",
417 m_submatrix_extent.x,
419 m_submatrix_extent.y);
423 m_triplet_index_offset,
425 m_total_triplet_count,
426 m_submatrix_offset + offset,
433 MUDA_GENERIC
auto subview(
int offset)
const
435 return subview(offset, m_triplet_count - offset);
438 MUDA_GENERIC
auto cviewer()
const
442 m_triplet_index_offset,
444 m_total_triplet_count,
452 MUDA_GENERIC
auto viewer()
454 return ThisViewer{m_total_rows,
456 m_triplet_index_offset,
458 m_total_triplet_count,
467 MUDA_GENERIC auto_const_t<Ty>* values() {
return m_values; }
468 MUDA_GENERIC auto_const_t<int>* row_indices() {
return m_row_indices; }
469 MUDA_GENERIC auto_const_t<int>* col_indices() {
return m_col_indices; }
473 MUDA_GENERIC
auto values()
const {
return m_values; }
474 MUDA_GENERIC
auto row_indices()
const {
return m_row_indices; }
475 MUDA_GENERIC
auto col_indices()
const {
return m_col_indices; }
477 MUDA_GENERIC
auto total_rows()
const {
return m_total_rows; }
478 MUDA_GENERIC
auto total_cols()
const {
return m_total_cols; }
480 MUDA_GENERIC
auto triplet_count()
const {
return m_triplet_count; }
481 MUDA_GENERIC
auto tripet_index_offset()
const
483 return m_triplet_index_offset;
485 MUDA_GENERIC
auto total_triplet_count()
const
487 return m_total_triplet_count;
490 MUDA_GENERIC
auto submatrix_offset()
const {
return m_submatrix_offset; }
491 MUDA_GENERIC
auto extent()
const {
return m_submatrix_extent; }
492 MUDA_GENERIC
auto total_extent()
const
494 return int2{m_total_rows, m_total_cols};