Skip to content

Commit

Permalink
Merge pull request #958 from julien-tierny/dev
Browse files Browse the repository at this point in the history
Fixes for clang-tidy 16
  • Loading branch information
julien-tierny authored Aug 3, 2023
2 parents fe58448 + 5cf0db0 commit db472ff
Show file tree
Hide file tree
Showing 233 changed files with 2,814 additions and 2,688 deletions.
54 changes: 24 additions & 30 deletions core/base/approximateTopology/ApproximateTopology.h
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ int ttk::ApproximateTopology::executeApproximateTopology(
std::vector<Lock> vertLockMin(vertexNumber), vertLockMax(vertexNumber);

if(preallocateMemory_) {
double tm_prealloc = timer.getElapsedTime();
const double tm_prealloc = timer.getElapsedTime();
printMsg("Pre-allocating data structures", 0, 0, threadNumber_,
ttk::debug::LineMode::REPLACE);
for(SimplexId i = 0; i < vertexNumber; ++i) {
Expand Down Expand Up @@ -400,10 +400,9 @@ int ttk::ApproximateTopology::executeApproximateTopology(
initGlobalPolarity(isNew, vertexLinkPolarity, toProcess, fakeScalars, offsets,
monotonyOffsets);

double delta = epsilon_ * delta_;
double const delta = epsilon_ * delta_;

while(decimationLevel_ > stoppingDecimationLevel_) {
Timer tmIter{};
decimationLevel_--;
multiresTriangulation_.setDecimationLevel(decimationLevel_);
// double progress = (double)(startingDecimationLevel_ - decimationLevel_)
Expand All @@ -412,9 +411,9 @@ int ttk::ApproximateTopology::executeApproximateTopology(
// progress, timer.getElapsedTime() - tm_allocation,
// threadNumber_);

int ret = updateGlobalPolarity(delta, isNew, vertexLinkPolarity, toProcess,
toReprocess, fakeScalars, offsets,
monotonyOffsets);
int const ret = updateGlobalPolarity(delta, isNew, vertexLinkPolarity,
toProcess, toReprocess, fakeScalars,
offsets, monotonyOffsets);
if(ret == -1) {
std::cout << "Found ERROR - aborting" << std::endl;
return -1;
Expand Down Expand Up @@ -474,7 +473,8 @@ void ttk::ApproximateTopology::computePersistencePairsFromSaddles(
const SimplexId nbDecVert = multiresTriangulation_.getDecimatedVertexNumber();

for(SimplexId localId = 0; localId < nbDecVert; localId++) {
SimplexId globalId = multiresTriangulation_.localToGlobalVertexId(localId);
const SimplexId globalId
= multiresTriangulation_.localToGlobalVertexId(localId);
if(toPropagateMin[globalId]) {
getTripletsFromSaddles(globalId, tripletsMin, vertexRepresentativesMin);
}
Expand Down Expand Up @@ -595,7 +595,7 @@ void ttk::ApproximateTopology::tripletsToPersistencePairs(
SimplexId r1 = getRep(std::get<1>(t));
SimplexId r2 = getRep(std::get<2>(t));
if(r1 != r2) {
SimplexId s = std::get<0>(t);
SimplexId const s = std::get<0>(t);

// Add pair
if(splitTree) {
Expand Down Expand Up @@ -625,7 +625,7 @@ void ttk::ApproximateTopology::tripletsToPersistencePairs(
}

if(debugLevel_ > 3) {
std::string prefix = splitTree ? "[sad-max]" : "[min-sad]";
const std::string prefix = splitTree ? "[sad-max]" : "[min-sad]";
std::cout << prefix << " found all pairs in " << tm.getElapsedTime()
<< " s." << std::endl;
}
Expand All @@ -640,8 +640,6 @@ void ttk::ApproximateTopology::sortVertices(
const offsetType *const offsets,
const int *const monotonyOffsets) {

Timer tm;

sortedVertices.resize(vertexNumber);

// fill with numbers from 0 to vertexNumber - 1
Expand All @@ -663,10 +661,6 @@ void ttk::ApproximateTopology::sortVertices(
for(size_t i = 0; i < sortedVertices.size(); ++i) {
vertsOrder[sortedVertices[i]] = i;
}

// if(debugLevel_ > 2) {
// std::cout << "SORT " << tm.getElapsedTime() << std::endl;
// }
}

template <typename scalarType, typename offsetType>
Expand Down Expand Up @@ -706,19 +700,19 @@ int ttk::ApproximateTopology::getMonotonyChangeByOldPointCPApproximate(

if(isUpperDynamic != isUpperOld) { // change of monotony
SimplexId oldNeighbor = -1;
int oldDecimation = pow(2, decimationLevel_ + 1);
const int oldDecimation = pow(2, decimationLevel_ + 1);
multiresTriangulation_.getVertexNeighborAtDecimation(
vertexId, i, oldNeighbor, oldDecimation);

double replacementValueDynamic
double const replacementValueDynamic
= (0.5 * (double)fakeScalars[oldNeighbor]
+ .5 * (double)fakeScalars[vertexId]); // depends on epsilon
double deltaDynamic
double const deltaDynamic
= fabs((double)fakeScalars[neighborId] - replacementValueDynamic);

//=====================
SimplexId oldNeighNumber = 0;
SimplexId nnumber
const SimplexId nnumber
= multiresTriangulation_.getVertexNeighborNumber(neighborId);
for(SimplexId iii = 0; iii < nnumber; iii++) {
SimplexId neighborId2 = -1;
Expand Down Expand Up @@ -849,13 +843,13 @@ ttk::SimplexId ttk::ApproximateTopology::propagateFromSaddles(
reps.reserve(CC.size());
for(size_t r = 0; r < CC.size(); r++) {
SimplexId neighborId = -1;
SimplexId localId = CC[r];
const SimplexId localId = CC[r];
multiresTriangulation_.getVertexNeighbor(vertexId, localId, neighborId);
// printMsg(" CC " + std::to_string(CC[r]) + " "
// + std::to_string(neighborId) + " ("
// + std::to_string(fakeScalars[neighborId]) + " , "
// + std::to_string(offsets[neighborId]) + ")");
SimplexId ret = propagateFromSaddles(
SimplexId const ret = propagateFromSaddles(
neighborId, vertLock, toPropagate, vertexRepresentatives, saddleCC,
isUpdated, globalExtremum, splitTree, fakeScalars, offsets,
monotonyOffsets);
Expand All @@ -882,7 +876,7 @@ ttk::SimplexId ttk::ApproximateTopology::propagateFromSaddles(
+ std::to_string(saddleCC[vertexId].size()));

SimplexId ret = vertexId;
SimplexId neighborNumber
const SimplexId neighborNumber
= multiresTriangulation_.getVertexNeighborNumber(vertexId);
SimplexId maxNeighbor = vertexId;
// std::cout << "neigh number" << neighborNumber << std::endl;
Expand Down Expand Up @@ -962,7 +956,7 @@ void ttk::ApproximateTopology::updatePropagation(
#pragma omp parallel for num_threads(threadNumber_)
#endif // TTK_ENABLE_OPENMP
for(size_t i = 0; i < nDecVerts; i++) {
SimplexId v = multiresTriangulation_.localToGlobalVertexId(i);
const SimplexId v = multiresTriangulation_.localToGlobalVertexId(i);
isUpdatedMin[v] = 0;
isUpdatedMax[v] = 0;
}
Expand All @@ -972,7 +966,7 @@ void ttk::ApproximateTopology::updatePropagation(
#pragma omp parallel for num_threads(threadNumber_)
#endif // TTK_ENABLE_OPENMP
for(size_t i = 0; i < nDecVerts; i++) {
SimplexId v = multiresTriangulation_.localToGlobalVertexId(i);
SimplexId const v = multiresTriangulation_.localToGlobalVertexId(i);
if(toPropagateMin[v]) {
propagateFromSaddles(v, vertLockMin, toPropagateMin,
vertexRepresentativesMin, saddleCCMin, isUpdatedMin,
Expand Down Expand Up @@ -1003,7 +997,7 @@ void ttk::ApproximateTopology::updatePropagation(
#pragma omp parallel for num_threads(threadNumber_)
#endif // TTK_ENABLE_OPENMP
for(size_t i = 0; i < nDecVerts; i++) {
SimplexId v = multiresTriangulation_.localToGlobalVertexId(i);
SimplexId const v = multiresTriangulation_.localToGlobalVertexId(i);

#ifdef TTK_ENABLE_OPENMP
const auto tid = omp_get_thread_num();
Expand Down Expand Up @@ -1190,7 +1184,7 @@ void ttk::ApproximateTopology::initGlobalPolarity(
#pragma omp parallel for num_threads(threadNumber_)
#endif // TTK_ENABLE_OPENMP
for(size_t i = 0; i < nDecVerts; i++) {
SimplexId globalId = multiresTriangulation_.localToGlobalVertexId(i);
SimplexId const globalId = multiresTriangulation_.localToGlobalVertexId(i);
buildVertexLinkPolarityApproximate(globalId, vertexLinkPolarity[globalId],
fakeScalars, offsets, monotonyOffsets);
toProcess[globalId] = 255;
Expand All @@ -1211,14 +1205,14 @@ int ttk::ApproximateTopology::updateGlobalPolarity(
const offsetType *const offsets,
int *monotonyOffsets) const {

Timer tm;
const auto nDecVerts = multiresTriangulation_.getDecimatedVertexNumber();

#ifdef TTK_ENABLE_OPENMP
#pragma omp parallel for num_threads(threadNumber_)
#endif // TTK_ENABLE_OPENMP
for(SimplexId localId = 0; localId < nDecVerts; localId++) {
SimplexId globalId = multiresTriangulation_.localToGlobalVertexId(localId);
SimplexId const globalId
= multiresTriangulation_.localToGlobalVertexId(localId);
if(!isNew[globalId]) {
getMonotonyChangeByOldPointCPApproximate(
globalId, eps, isNew, toProcess, toReprocess,
Expand All @@ -1231,7 +1225,7 @@ int ttk::ApproximateTopology::updateGlobalPolarity(
#pragma omp parallel for num_threads(threadNumber_)
#endif
for(int i = 0; i < multiresTriangulation_.getDecimatedVertexNumber(); i++) {
SimplexId globalId = multiresTriangulation_.localToGlobalVertexId(i);
SimplexId const globalId = multiresTriangulation_.localToGlobalVertexId(i);
if(isNew[globalId]) { // new point
if(decimationLevel_ > stoppingDecimationLevel_) {
buildVertexLinkPolarityApproximate(
Expand Down Expand Up @@ -1273,7 +1267,7 @@ void ttk::ApproximateTopology::computeCriticalPoints(
#pragma omp parallel for num_threads(threadNumber_)
#endif
for(int i = 0; i < multiresTriangulation_.getDecimatedVertexNumber(); i++) {
SimplexId globalId = multiresTriangulation_.localToGlobalVertexId(i);
SimplexId const globalId = multiresTriangulation_.localToGlobalVertexId(i);

if(toProcess[globalId]) {
// nbComputations++;
Expand Down
5 changes: 5 additions & 0 deletions core/base/arrayPreconditioning/ArrayPreconditioning.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ namespace ttk {
const GVLID &getVertexLocalId,
const size_t nVerts,
const int burstSize,
#ifdef TTK_ENABLE_MPI
std::vector<int> neighbors
#else
const std::vector<int> &neighbors
#endif

= {}) const { // start global timer
ttk::Timer globalTimer;

Expand Down
25 changes: 13 additions & 12 deletions core/base/assignmentSolver/AssignmentAuction.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ namespace ttk {
template <class dataType>
dataType getMaxValue(std::vector<std::vector<dataType>> &matrix,
bool balancedAsgn) {
unsigned int nRows = matrix.size();
unsigned int nCols = matrix[0].size();
unsigned int const nRows = matrix.size();
unsigned int const nCols = matrix[0].size();
dataType maxValue = std::numeric_limits<dataType>::lowest();
for(unsigned int i = 0; i < nRows; ++i) {
for(unsigned int j = 0; j < nCols; ++j) {
Expand Down Expand Up @@ -155,13 +155,13 @@ namespace ttk {
template <typename dataType>
void AssignmentAuction<dataType>::makeBalancedMatrix(
std::vector<std::vector<dataType>> &matrix) {
unsigned int nRows = matrix.size();
unsigned int nCols = matrix[0].size();
unsigned int const nRows = matrix.size();
unsigned int const nCols = matrix[0].size();
matrix[nRows - 1][nCols - 1] = 0;

// Add rows
for(unsigned int i = 0; i < nCols - 2; ++i) {
std::vector<dataType> newLine(matrix[nRows - 1]);
std::vector<dataType> const newLine(matrix[nRows - 1]);
matrix.push_back(newLine);
}
// Add columns
Expand All @@ -183,7 +183,7 @@ namespace ttk {
unassignedBidders.push(i);

while(!unassignedBidders.empty()) {
int bidderId = unassignedBidders.front();
int const bidderId = unassignedBidders.front();
unassignedBidders.pop();

// Get good with highest value
Expand Down Expand Up @@ -214,7 +214,7 @@ namespace ttk {
bestSecondValue = bestValue;

// Update price
double delta = abs<dataType>(bestValue - bestSecondValue) + epsilon;
double const delta = abs<dataType>(bestValue - bestSecondValue) + epsilon;
double newPrice = goodPrices[bestGoodId] + delta;
if(newPrice > std::numeric_limits<double>::max() / 2) {
// Avoid price explosion
Expand Down Expand Up @@ -253,7 +253,8 @@ namespace ttk {
dataType bestCost = std::numeric_limits<dataType>::max();

// Try to avoid price war
double tempPrice = *std::max_element(goodPrices.begin(), goodPrices.end());
double const tempPrice
= *std::max_element(goodPrices.begin(), goodPrices.end());
std::vector<double> savedPrices;
for(unsigned int i = 0; i < goodPrices.size(); ++i) {
auto old = goodPrices[i];
Expand Down Expand Up @@ -293,8 +294,8 @@ namespace ttk {
// Create output matching
for(unsigned int bidderId = 0; bidderId < bidderAssignments.size();
++bidderId) {
int i = bidderId;
int j = bidderAssignments[bidderId];
int const i = bidderId;
int const j = bidderAssignments[bidderId];
if(this->balancedAssignment
or (not this->balancedAssignment
and not(i >= this->rowSize - 1 and j >= this->colSize - 1))) {
Expand Down Expand Up @@ -346,8 +347,8 @@ namespace ttk {
dataType d = 0;
for(unsigned int bidderId = 0; bidderId < bidderAssignments.size();
++bidderId) {
int i = bidderId;
int j = bidderAssignments[bidderId];
int const i = bidderId;
int const j = bidderAssignments[bidderId];
d += cMatrix[i][j];
}
return d;
Expand Down
46 changes: 22 additions & 24 deletions core/base/assignmentSolver/AssignmentExhaustive.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,19 @@ namespace ttk {
queue;

std::vector<int> asgn_temp, unasgn_temp;
std::vector<bool> done_temp(max_dim, false);
queue.push(std::make_tuple(asgn_temp, unasgn_temp, false, done_temp, -1));
std::vector<bool> const done_temp(max_dim, false);
queue.emplace(asgn_temp, unasgn_temp, false, done_temp, -1);

while(!queue.empty()) {
auto queueElem = queue.front();
queue.pop();
std::vector<int> asgn = std::get<0>(queueElem);
std::vector<int> unasgn = std::get<1>(queueElem);
bool toUnasgn = std::get<2>(queueElem);
std::vector<int> const asgn = std::get<0>(queueElem);
std::vector<int> const unasgn = std::get<1>(queueElem);
bool const toUnasgn = std::get<2>(queueElem);
std::vector<bool> done = std::get<3>(queueElem);
unsigned int maxDone = std::get<4>(queueElem);
unsigned int const maxDone = std::get<4>(queueElem);

unsigned int ind = asgn.size();
unsigned int const ind = asgn.size();
for(unsigned int j = 0; j < max_dim + 1; ++j) {
std::vector<int> new_asgn(asgn);
std::vector<int> new_unasgn(unasgn);
Expand All @@ -95,22 +95,20 @@ namespace ttk {
}
new_done[j] = true;

unsigned int new_ind = new_asgn.size();
unsigned int const new_ind = new_asgn.size();
if(new_ind == max_dim) {
// A new assignment is made here
for(auto &new_unasgn_elem : new_unasgn)
new_asgn.push_back(new_unasgn_elem);
// std::sort(new_asgn.begin()+min_dim, new_asgn.end());
allAsgn.push_back(new_asgn);
} else
queue.push(std::make_tuple(
new_asgn, new_unasgn, false, new_done, new_maxDone));
queue.emplace(new_asgn, new_unasgn, false, new_done, new_maxDone);

} else {
if(not toUnasgn and ind < min_dim) {
new_asgn.push_back(max_dim);
queue.push(std::make_tuple(
new_asgn, new_unasgn, true, new_done, new_maxDone));
queue.emplace(new_asgn, new_unasgn, true, new_done, new_maxDone);
}
}
}
Expand Down Expand Up @@ -145,17 +143,17 @@ namespace ttk {
template <typename dataType>
dataType AssignmentExhaustive<dataType>::tryAssignment(
std::vector<int> &asgn, std::vector<MatchingType> &matchings) {
unsigned int nRows = this->costMatrix.size() - 1;
unsigned int nCols = this->costMatrix[0].size() - 1;
unsigned int const nRows = this->costMatrix.size() - 1;
unsigned int const nCols = this->costMatrix[0].size() - 1;
// int max_dim = std::max(nRows, nCols);
unsigned int min_dim = std::min(nRows, nCols);
bool transpose = nRows > nCols;
unsigned int const min_dim = std::min(nRows, nCols);
bool const transpose = nRows > nCols;

dataType cost = 0;
for(unsigned int ind = 0; ind < asgn.size(); ++ind) {
int indMatrix = std::min(ind, min_dim);
int i = (!transpose) ? indMatrix : asgn[ind];
int j = (!transpose) ? asgn[ind] : indMatrix;
int const indMatrix = std::min(ind, min_dim);
int const i = (!transpose) ? indMatrix : asgn[ind];
int const j = (!transpose) ? asgn[ind] : indMatrix;
cost += this->costMatrix[i][j];
matchings.push_back(std::make_tuple(i, j, this->costMatrix[i][j]));
}
Expand All @@ -165,10 +163,10 @@ namespace ttk {
template <typename dataType>
int AssignmentExhaustive<dataType>::run(
std::vector<MatchingType> &matchings) {
int nRows = this->costMatrix.size() - 1;
int nCols = this->costMatrix[0].size() - 1;
int max_dim = std::max(nRows, nCols);
int min_dim = std::min(nRows, nCols);
int const nRows = this->costMatrix.size() - 1;
int const nCols = this->costMatrix[0].size() - 1;
int const max_dim = std::max(nRows, nCols);
int const min_dim = std::min(nRows, nCols);

// --- Construct all possible assignments
std::vector<std::vector<int>> allAsgn;
Expand Down Expand Up @@ -200,7 +198,7 @@ namespace ttk {
else {
std::stringstream ss;
ss << min_dim << "_" << max_dim;
std::string asgnName = ss.str();
std::string const asgnName = ss.str();
// not found
if(not saveAsgn or savedAsgn.find(asgnName) == savedAsgn.end()) {
if(saveAsgn)
Expand Down
Loading

0 comments on commit db472ff

Please sign in to comment.