Skip to content

Commit ea313eb

Browse files
committed
reduced level of nesting in fbcsr read
1 parent f7b869a commit ea313eb

1 file changed

Lines changed: 35 additions & 32 deletions

File tree

core/matrix/fbcsr.cpp

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -336,43 +336,46 @@ void Fbcsr<ValueType, IndexType>::read(const mat_data &data)
336336
blocks.size() * bs * bs, bs);
337337

338338
tmp->row_ptrs_.get_data()[0] = 0;
339-
if (data.nonzeros.size() > 0) {
340-
index_type cur_brow = 0;
341-
index_type cur_bnz = 0;
342-
index_type cur_bcol = blocks.begin()->first.block_column;
343-
const index_type num_brows = detail::get_num_blocks(bs, data.size[0]);
344-
345-
acc::range<acc::block_col_major<value_type, 3>> values(
346-
std::array<size_type, 3>{blocks.size(), static_cast<size_type>(bs),
347-
static_cast<size_type>(bs)},
348-
tmp->values_.get_data());
349-
350-
for (auto it = blocks.begin(); it != blocks.end(); it++) {
351-
GKO_ENSURE_IN_BOUNDS(cur_brow, num_brows);
352-
353-
tmp->col_idxs_.get_data()[cur_bnz] = it->first.block_column;
354-
for (int ibr = 0; ibr < bs; ibr++) {
355-
for (int jbr = 0; jbr < bs; jbr++) {
356-
values(cur_bnz, ibr, jbr) = it->second(ibr, jbr);
357-
}
358-
}
359-
if (it->first.block_row > cur_brow) {
360-
tmp->row_ptrs_.get_data()[++cur_brow] = cur_bnz;
361-
} else {
362-
assert(cur_brow == it->first.block_row);
363-
assert(cur_bcol <= it->first.block_column);
364-
}
339+
if (data.nonzeros.size() == 0) {
340+
tmp->move_to(this);
341+
return;
342+
}
365343

366-
cur_bcol = it->first.block_column;
367-
cur_bnz++;
368-
}
344+
index_type cur_brow = 0;
345+
index_type cur_bnz = 0;
346+
index_type cur_bcol = blocks.begin()->first.block_column;
347+
const index_type num_brows = detail::get_num_blocks(bs, data.size[0]);
348+
349+
acc::range<acc::block_col_major<value_type, 3>> values(
350+
std::array<size_type, 3>{blocks.size(), static_cast<size_type>(bs),
351+
static_cast<size_type>(bs)},
352+
tmp->values_.get_data());
369353

370-
tmp->row_ptrs_.get_data()[++cur_brow] =
371-
static_cast<index_type>(blocks.size());
354+
for (auto it = blocks.begin(); it != blocks.end(); it++) {
355+
GKO_ENSURE_IN_BOUNDS(cur_brow, num_brows);
372356

373-
assert(cur_brow == tmp->get_size()[0] / bs);
357+
tmp->col_idxs_.get_data()[cur_bnz] = it->first.block_column;
358+
for (int ibr = 0; ibr < bs; ibr++) {
359+
for (int jbr = 0; jbr < bs; jbr++) {
360+
values(cur_bnz, ibr, jbr) = it->second(ibr, jbr);
361+
}
362+
}
363+
if (it->first.block_row > cur_brow) {
364+
tmp->row_ptrs_.get_data()[++cur_brow] = cur_bnz;
365+
} else {
366+
assert(cur_brow == it->first.block_row);
367+
assert(cur_bcol <= it->first.block_column);
368+
}
369+
370+
cur_bcol = it->first.block_column;
371+
cur_bnz++;
374372
}
375373

374+
tmp->row_ptrs_.get_data()[++cur_brow] =
375+
static_cast<index_type>(blocks.size());
376+
377+
assert(cur_brow == tmp->get_size()[0] / bs);
378+
376379
tmp->move_to(this);
377380
}
378381

0 commit comments

Comments
 (0)