20 using auto_const_t =
typename Base::template auto_const_t<U>;
23 using BlockMatrix = Eigen::Matrix<T, N, N>;
30 MUDA_GENERIC
CTriplet(
int row_index,
int col_index,
const BlockMatrix& block)
31 : block_row_index(row_index)
32 , block_col_index(col_index)
38 const BlockMatrix& block_value;
44 int m_total_block_rows = 0;
45 int m_total_block_cols = 0;
48 int m_triplet_index_offset = 0;
49 int m_triplet_count = 0;
50 int m_total_triplet_count = 0;
53 int2 m_submatrix_offset = {0, 0};
54 int2 m_submatrix_extent = {0, 0};
57 auto_const_t<int>* m_block_row_indices;
58 auto_const_t<int>* m_block_col_indices;
59 auto_const_t<BlockMatrix>* m_block_values;
63 MUDA_GENERIC TripletMatrixViewerBase() =
default;
64 MUDA_GENERIC TripletMatrixViewerBase(
int total_block_rows,
66 int triplet_index_offset,
68 int total_triplet_count,
70 int2 submatrix_offset,
71 int2 submatrix_extent,
73 auto_const_t<int>* block_row_indices,
74 auto_const_t<int>* block_col_indices,
75 auto_const_t<BlockMatrix>* block_values)
76 : m_total_block_rows(total_block_rows)
77 , m_total_block_cols(total_block_cols)
78 , m_triplet_index_offset(triplet_index_offset)
79 , m_triplet_count(triplet_count)
80 , m_total_triplet_count(total_triplet_count)
81 , m_submatrix_offset(submatrix_offset)
82 , m_submatrix_extent(submatrix_extent)
83 , m_block_row_indices(block_row_indices)
84 , m_block_col_indices(block_col_indices)
85 , m_block_values(block_values)
87 MUDA_KERNEL_ASSERT(triplet_index_offset + triplet_count <= total_triplet_count,
88 "TripletMatrixViewer [%s:%s]: out of range, m_total_triplet_count=%d, "
89 "your triplet_index_offset=%d, triplet_count=%d",
96 MUDA_KERNEL_ASSERT(submatrix_offset.x >= 0 && submatrix_offset.y >= 0,
97 "TripletMatrixViewer[%s:%s]: submatrix_offset is out of range, submatrix_offset.x=%d, submatrix_offset.y=%d",
103 MUDA_KERNEL_ASSERT(submatrix_offset.x + submatrix_extent.x <= total_block_rows,
104 "TripletMatrixViewer[%s:%s]: submatrix is out of range, submatrix_offset.x=%d, submatrix_extent.x=%d, total_block_rows=%d",
111 MUDA_KERNEL_ASSERT(submatrix_offset.y + submatrix_extent.y <= total_block_cols,
112 "TripletMatrixViewer[%s:%s]: submatrix is out of range, submatrix_offset.y=%d, submatrix_extent.y=%d, total_block_cols=%d",
120 MUDA_GENERIC ConstViewer as_const()
const
122 return ConstViewer{m_total_block_rows,
124 m_triplet_index_offset,
126 m_total_triplet_count,
134 MUDA_GENERIC
operator ConstViewer()
const {
return as_const(); }
138 MUDA_GENERIC
auto total_block_rows()
const {
return m_total_block_rows; }
139 MUDA_GENERIC
auto total_block_cols()
const {
return m_total_block_cols; }
140 MUDA_GENERIC
auto total_extent()
const
142 return int2{m_total_block_rows, m_total_block_cols};
145 MUDA_GENERIC
auto submatrix_offset()
const {
return m_submatrix_offset; }
146 MUDA_GENERIC
auto extent()
const {
return m_submatrix_extent; }
148 MUDA_GENERIC
auto triplet_count()
const {
return m_triplet_count; }
149 MUDA_GENERIC
auto tripet_index_offset()
const
151 return m_triplet_index_offset;
153 MUDA_GENERIC
auto total_triplet_count()
const
155 return m_total_triplet_count;
158 MUDA_GENERIC CTriplet operator()(
int i)
const
160 auto index = get_index(i);
161 auto global_i = m_block_row_indices[index];
162 auto global_j = m_block_col_indices[index];
163 auto sub_i = global_i - m_submatrix_offset.x;
164 auto sub_j = global_j - m_submatrix_offset.y;
165 check_in_submatrix(sub_i, sub_j);
166 return CTriplet{sub_i, sub_j, m_block_values[index]};
170 MUDA_INLINE MUDA_GENERIC
int get_index(
int i)
const noexcept
173 MUDA_KERNEL_ASSERT(i >= 0 && i < m_triplet_count,
174 "TripletMatrixViewer [%s:%s]: triplet_index out of range, block_count=%d, your index=%d",
179 auto index = i + m_triplet_index_offset;
183 MUDA_INLINE MUDA_GENERIC
void check_in_submatrix(
int i,
int j)
const noexcept
185 MUDA_KERNEL_ASSERT(i >= 0 && i < m_submatrix_extent.x,
186 "TripletMatrixViewer [%s:%s]: row index out of submatrix range, submatrix_extent.x=%d, your i=%d",
189 m_submatrix_extent.x,
192 MUDA_KERNEL_ASSERT(j >= 0 && j < m_submatrix_extent.y,
193 "TripletMatrixViewer [%s:%s]: col index out of submatrix range, submatrix_extent.y=%d, your j=%d",
196 m_submatrix_extent.y,
284 template <
typename U>
285 using auto_const_t =
typename Base::template auto_const_t<U>;
294 MUDA_GENERIC CTriplet(
int row_index,
int col_index,
const T& block)
295 : row_index(row_index)
296 , col_index(col_index)
307 int m_total_rows = 0;
308 int m_total_cols = 0;
311 int m_triplet_index_offset = 0;
312 int m_triplet_count = 0;
313 int m_total_triplet_count = 0;
316 int2 m_submatrix_offset = {0, 0};
317 int2 m_submatrix_extent = {0, 0};
320 auto_const_t<int>* m_row_indices;
321 auto_const_t<int>* m_col_indices;
322 auto_const_t<T>* m_values;
325 MUDA_GENERIC TripletMatrixViewerBase() =
default;
326 MUDA_GENERIC TripletMatrixViewerBase(
int total_rows,
329 int triplet_index_offset,
331 int total_triplet_count,
333 int2 submatrix_offset,
334 int2 submatrix_extent,
336 auto_const_t<int>* row_indices,
337 auto_const_t<int>* col_indices,
338 auto_const_t<T>* values)
339 : m_total_rows(total_rows)
340 , m_total_cols(total_cols)
341 , m_triplet_index_offset(triplet_index_offset)
342 , m_triplet_count(triplet_count)
343 , m_total_triplet_count(total_triplet_count)
344 , m_submatrix_offset(submatrix_offset)
345 , m_submatrix_extent(submatrix_extent)
346 , m_row_indices(row_indices)
347 , m_col_indices(col_indices)
350 MUDA_KERNEL_ASSERT(triplet_index_offset + triplet_count <= total_triplet_count,
351 "TripletMatrixViewer [%s:%s]: out of range, m_total_triplet_count=%d, "
352 "your triplet_index_offset=%d, triplet_count=%d",
356 triplet_index_offset,
359 MUDA_KERNEL_ASSERT(submatrix_offset.x >= 0 && submatrix_offset.y >= 0,
360 "TripletMatrixViewer [%s:%s]: submatrix_offset is out of range, submatrix_offset.x=%d, submatrix_offset.y=%d",
366 MUDA_KERNEL_ASSERT(submatrix_offset.x + submatrix_extent.x <= total_rows,
367 "TripletMatrixViewer [%s:%s]: submatrix is out of range, submatrix_offset.x=%d, submatrix_extent.x=%d, rows=%d",
374 MUDA_KERNEL_ASSERT(submatrix_offset.y + submatrix_extent.y <= total_cols,
375 "TripletMatrixViewer [%s:%s]: submatrix is out of range, submatrix_offset.y=%d, submatrix_extent.y=%d, cols=%d",
385 MUDA_GENERIC ConstViewer as_const()
const
387 return ConstViewer{m_total_rows,
389 m_triplet_index_offset,
391 m_total_triplet_count,
399 MUDA_GENERIC
operator ConstViewer()
const {
return as_const(); }
402 MUDA_GENERIC CTriplet operator()(
int i)
const
404 auto index = get_index(i);
406 auto global_i = m_row_indices[index];
407 auto global_j = m_col_indices[index];
408 auto sub_i = global_i - m_submatrix_offset.x;
409 auto sub_j = global_j - m_submatrix_offset.y;
410 check_in_submatrix(sub_i, sub_j);
411 return CTriplet{sub_i, sub_j, m_values[index]};
414 auto total_rows()
const {
return m_total_rows; }
415 auto total_cols()
const {
return m_total_cols; }
417 auto triplet_count()
const {
return m_triplet_count; }
418 auto tripet_index_offset()
const {
return m_triplet_index_offset; }
419 auto total_triplet_count()
const {
return m_total_triplet_count; }
421 auto submatrix_offset()
const {
return m_submatrix_offset; }
422 auto extent()
const {
return m_submatrix_extent; }
423 auto total_extent()
const {
return int2{m_total_rows, m_total_cols}; }
426 MUDA_INLINE MUDA_GENERIC
int get_index(
int i)
const noexcept
429 MUDA_KERNEL_ASSERT(i >= 0 && i < m_triplet_count,
430 "TripletMatrixViewer [%s:%s]: triplet_index out of range, block_count=%d, your index=%d",
435 auto index = i + m_triplet_index_offset;
439 MUDA_INLINE MUDA_GENERIC
void check_in_submatrix(
int i,
int j)
const noexcept
441 MUDA_KERNEL_ASSERT(i >= 0 && i < m_submatrix_extent.x,
442 "TripletMatrixViewer [%s:%s]: row index out of submatrix range, submatrix_extent.x=%d, yours=%d",
445 m_submatrix_extent.x,
448 MUDA_KERNEL_ASSERT(j >= 0 && j < m_submatrix_extent.y,
449 "TripletMatrixViewer [%s:%s]: col index out of submatrix range, submatrix_extent.y=%d, yours=%d",
452 m_submatrix_extent.y,