diff options
author | mcarrier <mcarrier@636b058d-ea47-450e-bf9e-a15bfbe3eedb> | 2018-02-27 15:56:28 +0000 |
---|---|---|
committer | mcarrier <mcarrier@636b058d-ea47-450e-bf9e-a15bfbe3eedb> | 2018-02-27 15:56:28 +0000 |
commit | 220a91b55e0952947f96ea4a09085b0720466c64 (patch) | |
tree | 3a0285a0333500c9e87ba68ecd3648d976bf3e9f /src/Persistence_representations/include/gudhi/Sliced_Wasserstein.h | |
parent | ff0dc023588e3b33bc4bc7f26ce1f68c647ae441 (diff) |
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/kernels@3259 636b058d-ea47-450e-bf9e-a15bfbe3eedb
Former-commit-id: eedc1bf47f0194b23dfc02425bedd2682bd3f573
Diffstat (limited to 'src/Persistence_representations/include/gudhi/Sliced_Wasserstein.h')
-rw-r--r-- | src/Persistence_representations/include/gudhi/Sliced_Wasserstein.h | 38 |
1 files changed, 10 insertions, 28 deletions
diff --git a/src/Persistence_representations/include/gudhi/Sliced_Wasserstein.h b/src/Persistence_representations/include/gudhi/Sliced_Wasserstein.h index ad1a6c42..6196e207 100644 --- a/src/Persistence_representations/include/gudhi/Sliced_Wasserstein.h +++ b/src/Persistence_representations/include/gudhi/Sliced_Wasserstein.h @@ -23,10 +23,6 @@ #ifndef SLICED_WASSERSTEIN_H_ #define SLICED_WASSERSTEIN_H_ -#ifdef GUDHI_USE_TBB -#include <tbb/parallel_for.h> -#endif - // gudhi include #include <gudhi/read_persistence_from_file.h> @@ -242,31 +238,17 @@ class Sliced_Wasserstein { int n = diagram1.size(); // Sort and compare all projections. - #ifdef GUDHI_USE_TBB - tbb::parallel_for(0, this->approx, [&](int i){ - std::vector<std::pair<int,double> > l1, l2; - for (int j = 0; j < n; j++){ - l1.emplace_back( j, diagram1[j].first*cos(-pi/2+i*step) + diagram1[j].second*sin(-pi/2+i*step) ); - l2.emplace_back( j, diagram2[j].first*cos(-pi/2+i*step) + diagram2[j].second*sin(-pi/2+i*step) ); - } - std::sort(l1.begin(),l1.end(), [=](const std::pair<int,double> & p1, const std::pair<int,double> & p2){return p1.second < p2.second;}); - std::sort(l2.begin(),l2.end(), [=](const std::pair<int,double> & p1, const std::pair<int,double> & p2){return p1.second < p2.second;}); - double f = 0; for (int j = 0; j < n; j++) f += std::abs(l1[j].second - l2[j].second); - sw += f*step; - }); - #else - for (int i = 0; i < this->approx; i++){ - std::vector<std::pair<int,double> > l1, l2; - for (int j = 0; j < n; j++){ - l1.emplace_back( j, diagram1[j].first*cos(-pi/2+i*step) + diagram1[j].second*sin(-pi/2+i*step) ); - l2.emplace_back( j, diagram2[j].first*cos(-pi/2+i*step) + diagram2[j].second*sin(-pi/2+i*step) ); - } - std::sort(l1.begin(),l1.end(), [=](const std::pair<int,double> & p1, const std::pair<int,double> & p2){return p1.second < p2.second;}); - std::sort(l2.begin(),l2.end(), [=](const std::pair<int,double> & p1, const std::pair<int,double> & p2){return p1.second < p2.second;}); - double f = 0; for (int j = 0; j < n; j++) f += std::abs(l1[j].second - l2[j].second); - sw += f*step; + for (int i = 0; i < this->approx; i++){ + std::vector<std::pair<int,double> > l1, l2; + for (int j = 0; j < n; j++){ + l1.emplace_back( j, diagram1[j].first*cos(-pi/2+i*step) + diagram1[j].second*sin(-pi/2+i*step) ); + l2.emplace_back( j, diagram2[j].first*cos(-pi/2+i*step) + diagram2[j].second*sin(-pi/2+i*step) ); } - #endif + std::sort(l1.begin(),l1.end(), [=](const std::pair<int,double> & p1, const std::pair<int,double> & p2){return p1.second < p2.second;}); + std::sort(l2.begin(),l2.end(), [=](const std::pair<int,double> & p1, const std::pair<int,double> & p2){return p1.second < p2.second;}); + double f = 0; for (int j = 0; j < n; j++) f += std::abs(l1[j].second - l2[j].second); + sw += f*step; + } } return sw/pi; |