Skip to content

Commit

Permalink
fix sonarqube warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
upsj committed Feb 25, 2020
1 parent abd143d commit 9ad9ab7
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 25 deletions.
3 changes: 2 additions & 1 deletion core/base/composition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,13 @@ namespace {
template <typename ValueType, typename OpIterator, typename VecIterator>
inline void allocate_vectors(OpIterator begin, OpIterator end, VecIterator res)
{
for (auto it = begin; it != end; ++it, ++res) {
for (auto it = begin; it != end; ++it) {
if (*res != nullptr && (*res)->get_size()[0] == (*it)->get_size()[0]) {
continue;
}
*res = matrix::Dense<ValueType>::create(
(*it)->get_executor(), gko::dim<2>{(*it)->get_size()[0], 1});
++res;
}
}

Expand Down
9 changes: 4 additions & 5 deletions include/ginkgo/core/base/array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define GKO_CORE_BASE_ARRAY_H_


#include <algorithm>
#include <iterator>
#include <memory>
#include <utility>

Expand Down Expand Up @@ -178,11 +180,8 @@ class Array {
RandomAccessIterator end)
: Array(exec)
{
Array tmp(exec->get_master(), end - begin);
int i = 0;
for (auto it = begin; it != end; ++it, ++i) {
tmp.data_[i] = *it;
}
Array tmp(exec->get_master(), std::distance(begin, end));
std::copy(begin, end, tmp.data_.get());
*this = std::move(tmp);
}

Expand Down
3 changes: 2 additions & 1 deletion omp/factorization/par_ilu_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ void add_missing_diagonal_elements(const matrix::Csr<ValueType, IndexType> *mtx,
IndexType new_idx = new_row_start;
bool diagonal_added{false};
for (IndexType old_idx = old_row_start; old_idx < old_row_end;
++old_idx, ++new_idx) {
++old_idx) {
const auto col_idx = old_col_idxs[old_idx];
if (!diagonal_added && row < col_idx) {
new_values[new_idx] = zero<ValueType>();
Expand All @@ -153,6 +153,7 @@ void add_missing_diagonal_elements(const matrix::Csr<ValueType, IndexType> *mtx,
}
new_values[new_idx] = old_values[old_idx];
new_col_idxs[new_idx] = col_idx;
++new_idx;
}
if (!diagonal_added) {
new_values[new_idx] = zero<ValueType>();
Expand Down
13 changes: 4 additions & 9 deletions omp/preconditioner/jacobi_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

#include <algorithm>
#include <cmath>
#include <iterator>
#include <numeric>
#include <vector>

Expand Down Expand Up @@ -83,15 +84,9 @@ inline bool has_same_nonzero_pattern(const IndexType *prev_row_ptr,
const IndexType *curr_row_ptr,
const IndexType *next_row_ptr)
{
if (next_row_ptr - curr_row_ptr != curr_row_ptr - prev_row_ptr) {
return false;
}
for (; curr_row_ptr < next_row_ptr; ++prev_row_ptr, ++curr_row_ptr) {
if (*curr_row_ptr != *prev_row_ptr) {
return false;
}
}
return true;
return std::distance(curr_row_ptr, next_row_ptr) ==
std::distance(prev_row_ptr, curr_row_ptr) &&
std::equal(curr_row_ptr, next_row_ptr, prev_row_ptr);
}


Expand Down
14 changes: 5 additions & 9 deletions reference/preconditioner/jacobi_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "core/preconditioner/jacobi_kernels.hpp"


#include <algorithm>
#include <cmath>
#include <iterator>
#include <numeric>
#include <vector>

Expand Down Expand Up @@ -66,15 +68,9 @@ inline bool has_same_nonzero_pattern(const IndexType *prev_row_ptr,
const IndexType *curr_row_ptr,
const IndexType *next_row_ptr)
{
if (next_row_ptr - curr_row_ptr != curr_row_ptr - prev_row_ptr) {
return false;
}
for (; curr_row_ptr < next_row_ptr; ++prev_row_ptr, ++curr_row_ptr) {
if (*curr_row_ptr != *prev_row_ptr) {
return false;
}
}
return true;
return std::distance(curr_row_ptr, next_row_ptr) ==
std::distance(prev_row_ptr, curr_row_ptr) &&
std::equal(curr_row_ptr, next_row_ptr, prev_row_ptr);
}


Expand Down

0 comments on commit 9ad9ab7

Please sign in to comment.