Skip to content

Commit

Permalink
Fix clang-tidy checks
Browse files Browse the repository at this point in the history
  • Loading branch information
angriman committed Jun 17, 2021
1 parent 2ba8188 commit b5cd845
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 41 deletions.
10 changes: 3 additions & 7 deletions include/networkit/algebraic/AlgebraicGlobals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
* Author: Michael Wegner (michael.wegner@student.kit.edu)
*/

// networkit-format

#ifndef NETWORKIT_ALGEBRAIC_ALGEBRAIC_GLOBALS_HPP_
#define NETWORKIT_ALGEBRAIC_ALGEBRAIC_GLOBALS_HPP_

Expand All @@ -19,15 +17,13 @@ struct Triplet {
index row;
index column;
double value;

Triplet() = default;

Triplet(index row, index column, double value) : row(row), column(column), value(value) {}
};

/** Floating point epsilon to use in comparisons. */
constexpr double FLOAT_EPSILON = 1e-9;

} // namespace NetworKit
}



#endif // NETWORKIT_ALGEBRAIC_ALGEBRAIC_GLOBALS_HPP_
67 changes: 34 additions & 33 deletions include/networkit/algebraic/CSRGeneralMatrix.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include <networkit/algebraic/Vector.hpp>
#include <networkit/graph/Graph.hpp>

#include <tlx/unused.hpp>

namespace NetworKit {

/**
Expand Down Expand Up @@ -238,13 +240,13 @@ class CSRGeneralMatrix {
CSRGeneralMatrix(const CSRGeneralMatrix &other) = default;

/** Default move constructor */
CSRGeneralMatrix(CSRGeneralMatrix &&other) = default;
CSRGeneralMatrix(CSRGeneralMatrix &&other) noexcept = default;

/** Default destructor */
~CSRGeneralMatrix() = default;

/** Default move assignment operator */
CSRGeneralMatrix &operator=(CSRGeneralMatrix &&other) = default;
CSRGeneralMatrix &operator=(CSRGeneralMatrix &&other) noexcept = default;

/** Default copy assignment operator */
CSRGeneralMatrix &operator=(const CSRGeneralMatrix &other) = default;
Expand Down Expand Up @@ -404,6 +406,7 @@ class CSRGeneralMatrix {

#ifndef NETWORKIT_SANITY_CHECKS
bool sorted = true;
tlx::unused(sorted);
#pragma omp parallel for
for (omp_index i = 0; i < static_cast<omp_index>(nRows); ++i) {
for (index j = rowIdx[i] + 1; j < rowIdx[i + 1]; ++j) {
Expand Down Expand Up @@ -481,9 +484,8 @@ class CSRGeneralMatrix {
}
} else {
#pragma omp parallel for
for (omp_index i = 0; i < static_cast<omp_index>(diag.getDimension()); ++i) {
for (omp_index i = 0; i < static_cast<omp_index>(diag.getDimension()); ++i)
diag[i] = (*this)(i, i);
}
}

return diag;
Expand Down Expand Up @@ -715,7 +717,7 @@ class CSRGeneralMatrix {
});
}

return CSRGeneralMatrix(A.nCols, B.nCols, columnIdx, values);
return {A.nCols, B.nCols, columnIdx, values};
}

/**
Expand Down Expand Up @@ -755,7 +757,7 @@ class CSRGeneralMatrix {
});
}

return CSRGeneralMatrix(A.nRows, B.nRows, columnIdx, values);
return {A.nRows, B.nRows, columnIdx, values};
}

/**
Expand Down Expand Up @@ -808,7 +810,7 @@ class CSRGeneralMatrix {
}
rowIdx[numberOfColumns()] = nonZeros.size();

return CSRGeneralMatrix(nCols, nRows, rowIdx, columnIdx, nonZeros, getZero());
return {nCols, nRows, rowIdx, columnIdx, nonZeros, getZero()};
}

/**
Expand All @@ -831,7 +833,7 @@ class CSRGeneralMatrix {
for (index i = 0; i < rowIndices.size(); ++i) {
Triplet last = {i, 0, 0};
(*this).forNonZeroElementsInRow(rowIndices[i], [&](index k, double value) {
if (columnMapping[k].size() > 0) {
if (!columnMapping[k].empty()) {
for (index j : columnMapping[k]) {
if (last.row == i && last.column > j)
sorted = false;
Expand All @@ -842,8 +844,7 @@ class CSRGeneralMatrix {
});
}

return CSRGeneralMatrix(rowIndices.size(), columnIndices.size(), triplets, getZero(),
sorted);
return {rowIndices.size(), columnIndices.size(), triplets, getZero(), sorted};
}

/**
Expand Down Expand Up @@ -877,7 +878,7 @@ class CSRGeneralMatrix {
* @param unaryElementFunction
*/
template <typename F>
void apply(const F unaryElementFunction);
void apply(F unaryElementFunction);

/**
* Compute the (weighted) adjacency matrix of the (weighted) Graph @a graph.
Expand All @@ -893,7 +894,7 @@ class CSRGeneralMatrix {
triplets[idx++] = {j, i, val};
});

return CSRGeneralMatrix(graph.upperNodeIdBound(), triplets, zero);
return {graph.upperNodeIdBound(), triplets, zero};
}

/**
Expand All @@ -917,7 +918,7 @@ class CSRGeneralMatrix {
nonZeros[j] = diagonalElements[j];
}

return CSRGeneralMatrix(nRows, nCols, rowIdx, columnIdx, nonZeros, zero);
return {nRows, nCols, rowIdx, columnIdx, nonZeros, zero};
}

/**
Expand All @@ -934,26 +935,26 @@ class CSRGeneralMatrix {
graph.forEdges([&](node u, node v, edgeweight weight, edgeid edgeId) {
if (u != v) {
edgeweight w = std::sqrt(weight);
triplets.emplace_back(u, edgeId, w);
triplets.emplace_back(v, edgeId, -w);
triplets.push_back({u, edgeId, w});
triplets.push_back({v, edgeId, -w});
}
});
} else {
graph.forEdges([&](node u, node v, edgeweight weight, edgeid edgeId) {
if (u != v) {
edgeweight w = std::sqrt(weight);
if (u < v) { // orientation: small node number -> great node number
triplets.emplace_back(u, edgeId, w);
triplets.emplace_back(v, edgeId, -w);
triplets.push_back({u, edgeId, w});
triplets.push_back({v, edgeId, -w});
} else {
triplets.emplace_back(u, edgeId, -w);
triplets.emplace_back(v, edgeId, w);
triplets.push_back({u, edgeId, -w});
triplets.push_back({v, edgeId, w});
}
}
});
}

return CSRGeneralMatrix(graph.upperNodeIdBound(), graph.upperEdgeIdBound(), triplets, zero);
return {graph.upperNodeIdBound(), graph.upperEdgeIdBound(), triplets, zero};
}

/**
Expand All @@ -966,17 +967,17 @@ class CSRGeneralMatrix {
graph.forNodes([&](const index i) {
double weightedDegree = 0;
graph.forNeighborsOf(i, [&](const index j, double weight) { // - adjacency matrix
if (i != j) // exclude diagonal since this would be subtracted by
// the adjacency weight
// exclude diagonal since this would be subtracted by the adjacency weight
if (i != j)
weightedDegree += weight;

triples.emplace_back(i, j, -weight);
triples.push_back({i, j, -weight});
});

triples.emplace_back(i, i, weightedDegree); // degree matrix
triples.push_back({i, i, weightedDegree}); // degree matrix
});

return CSRGeneralMatrix(graph.upperNodeIdBound(), triples, zero);
return {graph.upperNodeIdBound(), triples, zero};
}

/**
Expand All @@ -993,19 +994,19 @@ class CSRGeneralMatrix {
graph.forNodes([&](const node i) {
graph.forNeighborsOf(i, [&](const node j, double weight) {
if (i != j)
triples.emplace_back(
i, j, -weight / std::sqrt(weightedDegrees[i] * weightedDegrees[j]));
triples.push_back(
{i, j, -weight / std::sqrt(weightedDegrees[i] * weightedDegrees[j])});
});

if (weightedDegrees[i] != 0) {
if (graph.isWeighted())
triples.emplace_back(i, i, 1 - (graph.weight(i, i)) / weightedDegrees[i]);
triples.push_back({i, i, 1 - (graph.weight(i, i)) / weightedDegrees[i]});
else
triples.emplace_back(i, i, 1);
triples.push_back({i, i, 1});
}
});

return CSRGeneralMatrix(graph.upperNodeIdBound(), triples, zero);
return {graph.upperNodeIdBound(), triples, zero};
}

/**
Expand Down Expand Up @@ -1125,7 +1126,7 @@ CSRGeneralMatrix<ValueType>::binaryOperator(const CSRGeneralMatrix<ValueType> &A
}
}

return CSRGeneralMatrix(A.nRows, A.nCols, rowIdx, columnIdx, nonZeros, A.zero, true);
return {A.nRows, A.nCols, rowIdx, columnIdx, nonZeros, A.zero, true};
} else { // A or B not sorted
std::vector<int64_t> columnPointer(A.nCols, -1);
std::vector<ValueType> Arow(A.nCols, A.zero);
Expand Down Expand Up @@ -1164,7 +1165,7 @@ CSRGeneralMatrix<ValueType>::binaryOperator(const CSRGeneralMatrix<ValueType> &A
for (count k = 0; k < nnz; ++k) {
ValueType value = binaryOp(Arow[listHead], Brow[listHead]);
if (value != A.zero)
triplets.emplace_back(i, listHead, value);
triplets.push_back({i, listHead, value});

index temp = listHead;
listHead = columnPointer[listHead];
Expand All @@ -1178,7 +1179,7 @@ CSRGeneralMatrix<ValueType>::binaryOperator(const CSRGeneralMatrix<ValueType> &A
nnz = 0;
}

return CSRGeneralMatrix(A.numberOfRows(), A.numberOfColumns(), triplets);
return {A.numberOfRows(), A.numberOfColumns(), triplets};
}
}

Expand Down
1 change: 0 additions & 1 deletion networkit/cpp/viz/MaxentStress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

#include <networkit/auxiliary/Log.hpp>
#include <networkit/auxiliary/PrioQueue.hpp>
#include <networkit/auxiliary/Timer.hpp>
#include <networkit/components/ConnectedComponents.hpp>
#include <networkit/distance/BFS.hpp>
#include <networkit/distance/Dijkstra.hpp>
Expand Down

0 comments on commit b5cd845

Please sign in to comment.