diff --git a/core/base/mergeTreeClustering/MergeTreeBarycenter.h b/core/base/mergeTreeClustering/MergeTreeBarycenter.h index b946bf3ecf..f74f1f6a28 100644 --- a/core/base/mergeTreeClustering/MergeTreeBarycenter.h +++ b/core/base/mergeTreeClustering/MergeTreeBarycenter.h @@ -506,7 +506,7 @@ namespace ttk { std::tuple birthDeath; // Normalized Wasserstein if(normalizedWasserstein_) - birthDeath = getNormalizedBirthDeathDouble(tree1, nodeId1); + birthDeath = getNormalizedBirthDeath(tree1, nodeId1); // Classical Wasserstein else birthDeath = tree1->getBirthDeath(nodeId1); @@ -526,10 +526,10 @@ namespace ttk { baryTree, nodeId, newScalarsVector, false); dataType mu_min = getMinMaxLocalFromVector( baryTree, nodeId, newScalarsVector); - double newBirth = 0, newDeath = 0; + dataType newBirth = 0, newDeath = 0; // Compute projection - double tempBirth = 0, tempDeath = 0; + dataType tempBirth = 0, tempDeath = 0; double alphaSum = 0; for(unsigned int i = 0; i < trees.size(); ++i) if(nodes[i] != std::numeric_limits::max()) @@ -539,18 +539,18 @@ namespace ttk { if(nodes[i] != std::numeric_limits::max()) { auto iBirthDeath = getParametrizedBirthDeath(trees[i], nodes[i]); - double tTempBirth = 0, tTempDeath = 0; + dataType tTempBirth = 0, tTempDeath = 0; tTempBirth += std::get<0>(iBirthDeath); tTempDeath += std::get<1>(iBirthDeath); tempBirth += tTempBirth * alphas[i] / alphaSum; tempDeath += tTempDeath * alphas[i] / alphaSum; } } - double const projec = (tempBirth + tempDeath) / 2; + dataType const projec = (tempBirth + tempDeath) / 2; // Compute newBirth and newDeath for(unsigned int i = 0; i < trees.size(); ++i) { - double iBirth = projec, iDeath = projec; + dataType iBirth = projec, iDeath = projec; // if node is matched in trees[i] if(nodes[i] != std::numeric_limits::max()) { auto iBirthDeath @@ -562,8 +562,12 @@ namespace ttk { newDeath += alphas[i] * iDeath; } if(normalizedWasserstein_) { - newBirth = newBirth * (mu_max - mu_min) + mu_min; - newDeath = newDeath * (mu_max - mu_min) + mu_min; + // Forbid compiler optimization to have same results on different + // computers + volatile dataType tempBirthT = newBirth * (mu_max - mu_min); + volatile dataType tempDeathT = newDeath * (mu_max - mu_min); + newBirth = tempBirthT + mu_min; + newDeath = tempDeathT + mu_min; } return std::make_tuple(newBirth, newDeath); @@ -584,21 +588,23 @@ namespace ttk { = getMinMaxLocalFromVector(baryTree, nodeB, newScalarsVector); auto birthDeath = getParametrizedBirthDeath(tree, nodeId); - double newBirth = std::get<0>(birthDeath); - double newDeath = std::get<1>(birthDeath); - double const projec = (newBirth + newDeath) / 2; + dataType newBirth = std::get<0>(birthDeath); + dataType newDeath = std::get<1>(birthDeath); + dataType const projec = (newBirth + newDeath) / 2; newBirth = alpha * newBirth + (1 - alpha) * projec; newDeath = alpha * newDeath + (1 - alpha) * projec; if(normalizedWasserstein_) { - newBirth = newBirth * (mu_max - mu_min) + mu_min; - newDeath = newDeath * (mu_max - mu_min) + mu_min; + // Forbid compiler optimization to have same results on different + // computers + volatile dataType tempBirthT = newBirth * (mu_max - mu_min); + volatile dataType tempDeathT = newDeath * (mu_max - mu_min); + newBirth = tempBirthT + mu_min; + newDeath = tempDeathT + mu_min; } - dataType newBirthT = newBirth; - dataType newDeathT = newDeath; - return std::make_tuple(newBirthT, newDeathT); + return std::make_tuple(newBirth, newDeath); } template diff --git a/core/base/mergeTreeClustering/MergeTreeDistance.h b/core/base/mergeTreeClustering/MergeTreeDistance.h index 2b43efaff8..0ce6bb929f 100644 --- a/core/base/mergeTreeClustering/MergeTreeDistance.h +++ b/core/base/mergeTreeClustering/MergeTreeDistance.h @@ -582,7 +582,7 @@ namespace ttk { ftm::MergeTree &mTree2Int = (saveTree_ ? mTree2Copy : mTree2); ftm::FTMTree_MT *tree1 = &(mTree1Int.tree); ftm::FTMTree_MT *tree2 = &(mTree2Int.tree); - if(not isCalled_) { + if(not isCalled_ and not isPersistenceDiagram_) { verifyMergeTreeStructure(tree1); verifyMergeTreeStructure(tree2); } diff --git a/core/base/mergeTreeClustering/MergeTreeUtils.h b/core/base/mergeTreeClustering/MergeTreeUtils.h index b1ae2d28bd..56d97b19e2 100644 --- a/core/base/mergeTreeClustering/MergeTreeUtils.h +++ b/core/base/mergeTreeClustering/MergeTreeUtils.h @@ -60,26 +60,6 @@ namespace ttk { return std::make_tuple(min, max); } - template - std::tuple - getNormalizedBirthDeathDouble(ftm::FTMTree_MT *tree, - ftm::idNode nodeId, - dataType newMin = 0.0, - dataType newMax = 1.0) { - auto birthDeath = tree->getBirthDeath(nodeId); - double birth = std::get<0>(birthDeath); - double death = std::get<1>(birthDeath); - dataType shiftMin = getMinMaxLocal(tree, nodeId); - dataType shiftMax = getMinMaxLocal(tree, nodeId, false); - if((shiftMax - shiftMin) == 0) - return std::make_tuple(0, 0); - birth = (newMax - newMin) * (birth - shiftMin) - / (shiftMax - shiftMin); // + newMin; - death = (newMax - newMin) * (death - shiftMin) - / (shiftMax - shiftMin); // + newMin; - return std::make_tuple(birth, death); - } - template std::tuple getNormalizedBirthDeath(ftm::FTMTree_MT *tree, ftm::idNode nodeId,