Skip to content

Commit

Permalink
reduced nesting of loops as demanded by Sonarcloud
Browse files Browse the repository at this point in the history
  • Loading branch information
Slaedr committed Apr 1, 2021
1 parent f2de6e4 commit 7dbb295
Showing 1 changed file with 36 additions and 32 deletions.
68 changes: 36 additions & 32 deletions core/matrix/fbcsr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,43 +336,47 @@ void Fbcsr<ValueType, IndexType>::read(const mat_data &data)
blocks.size() * bs * bs, bs);

tmp->row_ptrs_.get_data()[0] = 0;
if (data.nonzeros.size() > 0) {
index_type cur_brow = 0;
index_type cur_bnz = 0;
index_type cur_bcol = blocks.begin()->first.block_column;
const index_type num_brows = detail::get_num_blocks(bs, data.size[0]);

acc::range<acc::block_col_major<value_type, 3>> values(
std::array<size_type, 3>{blocks.size(), static_cast<size_type>(bs),
static_cast<size_type>(bs)},
tmp->values_.get_data());

for (auto it = blocks.begin(); it != blocks.end(); it++) {
GKO_ENSURE_IN_BOUNDS(cur_brow, num_brows);

tmp->col_idxs_.get_data()[cur_bnz] = it->first.block_column;
for (int ibr = 0; ibr < bs; ibr++) {
for (int jbr = 0; jbr < bs; jbr++) {
values(cur_bnz, ibr, jbr) = it->second(ibr, jbr);
}
}
if (it->first.block_row > cur_brow) {
tmp->row_ptrs_.get_data()[++cur_brow] = cur_bnz;
} else {
assert(cur_brow == it->first.block_row);
assert(cur_bcol <= it->first.block_column);
}

cur_bcol = it->first.block_column;
cur_bnz++;
}
if (data.nonzeros.size() == 0) {
tmp->move_to(this);
return;
}

index_type cur_brow = 0;
index_type cur_bnz = 0;
index_type cur_bcol = blocks.begin()->first.block_column;
const index_type num_brows = detail::get_num_blocks(bs, data.size[0]);

tmp->row_ptrs_.get_data()[++cur_brow] =
static_cast<index_type>(blocks.size());
acc::range<acc::block_col_major<value_type, 3>> values(
std::array<size_type, 3>{blocks.size(), static_cast<size_type>(bs),
static_cast<size_type>(bs)},
tmp->values_.get_data());

assert(cur_brow == tmp->get_size()[0] / bs);
for (auto it = blocks.begin(); it != blocks.end(); it++) {
GKO_ENSURE_IN_BOUNDS(cur_brow, num_brows);

tmp->col_idxs_.get_data()[cur_bnz] = it->first.block_column;
for (int ibr = 0; ibr < bs; ibr++) {
for (int jbr = 0; jbr < bs; jbr++) {
values(cur_bnz, ibr, jbr) = it->second(ibr, jbr);
}
}
if (it->first.block_row > cur_brow) {
tmp->row_ptrs_.get_data()[++cur_brow] = cur_bnz;
} else {
assert(cur_brow == it->first.block_row);
assert(cur_bcol <= it->first.block_column);
}

cur_bcol = it->first.block_column;
cur_bnz++;
}

tmp->row_ptrs_.get_data()[++cur_brow] =
static_cast<index_type>(blocks.size());

assert(cur_brow == tmp->get_size()[0] / bs);

tmp->move_to(this);
}

Expand Down

0 comments on commit 7dbb295

Please sign in to comment.