Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move hera to submodule #371

Merged
merged 14 commits into from
Mar 20, 2020
Merged
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
path = gtda/externals/gudhi-devel
url = https://github.com/giotto-ai/gudhi-devel
branch = giotto
[submodule "gtda/externals/hera"]
path = gtda/externals/hera
url = https://github.com/grey-narn/hera
9 changes: 8 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ find_package(OpenMP)

set(RIPSER_SRC_DIR "gtda/externals/ripser")
set(GUDHI_SRC_DIR "gtda/externals/gudhi-devel/src")
set(HERA_DIR "gtda/externals/hera")

#######################################################################
# Ripser #
Expand Down Expand Up @@ -56,10 +57,13 @@ endif()
# Wasserstein #
#######################################################################

pybind11_add_module(gtda_wasserstein "${BINDINGS_DIR}/wasserstein_bindings.cpp")
pybind11_add_module(gtda_wasserstein ${BINDINGS_DIR}/wasserstein_bindings.cpp)
target_link_libraries(gtda_wasserstein LINK_PUBLIC ${Boost_LIBRARIES})
target_compile_definitions(gtda_wasserstein PRIVATE BOOST_RESULT_OF_USE_DECLTYPE=1 BOOST_ALL_NO_LIB=1 BOOST_SYSTEM_NO_DEPRECATED=1)

target_include_directories(gtda_wasserstein PRIVATE "${HERA_DIR}")
target_include_directories(gtda_wasserstein PRIVATE "${HERA_DIR}/wasserstein/include")

if(MSVC)
target_compile_options(gtda_wasserstein PUBLIC $<$<CONFIG:RELEASE>: /Wall /O2>)
target_compile_options(gtda_wasserstein PUBLIC $<$<CONFIG:DEBUG>:/O1 /DEBUG:FULL /Zi /Zo>)
Expand All @@ -76,6 +80,9 @@ pybind11_add_module(gtda_bottleneck "${BINDINGS_DIR}/bottleneck_bindings.cpp")
target_link_libraries(gtda_bottleneck LINK_PUBLIC ${Boost_LIBRARIES})
target_compile_definitions(gtda_bottleneck PRIVATE BOOST_RESULT_OF_USE_DECLTYPE=1 BOOST_ALL_NO_LIB=1 BOOST_SYSTEM_NO_DEPRECATED=1)

target_include_directories(gtda_bottleneck PRIVATE "${HERA_DIR}")
target_include_directories(gtda_bottleneck PRIVATE "${HERA_DIR}/bottleneck/include")

if(MSVC)
target_compile_options(gtda_bottleneck PUBLIC $<$<CONFIG:RELEASE>: /Wall /O2>)
target_compile_options(gtda_bottleneck PUBLIC $<$<CONFIG:DEBUG>:/O1 /DEBUG:FULL /Zi /Zo>)
Expand Down
4 changes: 2 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:

- task: Cache@2
inputs:
key: '"ccache-wheels-v2020.03.12" | $(Agent.OS) | "$(python.version)"'
key: '"ccache-wheels-v2020.03.18" | $(Agent.OS) | "$(python.version)"'
path: $(CCACHE_DIR)
displayName: ccache

Expand Down Expand Up @@ -133,7 +133,7 @@ jobs:

- task: Cache@2
inputs:
key: '"ccache-v2020.03.12" | $(Agent.OS) | "$(python.version)"'
key: '"ccache-v2020.03.18" | $(Agent.OS) | "$(python.version)"'
path: $(CCACHE_DIR)
displayName: ccache

Expand Down
15 changes: 12 additions & 3 deletions gtda/externals/bindings/bottleneck_bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,23 @@
* License: Apache 2.0
*****************************************************************************/

#include "../hera/bottleneck/bottleneck.h"
/* ssize_t is not standard C, it is a typedef from Posix.
* Following solution is copy/pasted from solution found in
* https://stackoverflow.com/a/35368387
*/
#if defined(_MSC_VER)
#include <BaseTsd.h>
typedef SSIZE_T ssize_t;
#endif

#include <bottleneck/include/bottleneck.h>

// PYBIND11
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>

double bottleneck_distance(const std::vector<std::pair<double, double>>& dgm1,
const std::vector<std::pair<double, double>>& dgm2,
double bottleneck_distance(std::vector<std::pair<double, double>>& dgm1,
std::vector<std::pair<double, double>>& dgm2,
double delta) {
if (delta == 0.0)
return hera::bottleneckDistExact(dgm1, dgm2);
Expand Down
14 changes: 9 additions & 5 deletions gtda/externals/bindings/wasserstein_bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* License: Apache 2.0
*****************************************************************************/

#include "../hera/wasserstein/wasserstein.h"
#include <wasserstein/include/wasserstein.h>

// PYBIND11
#include <pybind11/pybind11.h>
Expand All @@ -12,17 +12,18 @@
double wasserstein_distance(const std::vector<std::pair<double, double>>& dgm1,
const std::vector<std::pair<double, double>>& dgm2,
double q, double delta, double internal_p,
double initial_eps, double eps_factor) {
double initial_eps, double eps_factor,
int max_bids_per_round) {
hera::AuctionParams<double> params;
params.wasserstein_power = q;
params.delta = delta;
params.internal_p = internal_p;
params.max_bids_per_round = max_bids_per_round;
params.epsilon_common_ratio = eps_factor;

if (initial_eps != 0) params.initial_epsilon = initial_eps;

if (eps_factor != 0.) params.epsilon_common_ratio = eps_factor;

return hera::wasserstein_dist(dgm1, dgm2, params);
return hera::wasserstein_dist<>(dgm1, dgm2, params);
}

namespace py = pybind11;
Expand All @@ -34,5 +35,8 @@ PYBIND11_MODULE(gtda_wasserstein, m) {
py::arg("q") = 2.0, py::arg("delta") = .01,
py::arg("internal_p") = hera::get_infinity<double>(),
py::arg("initial_eps") = 0., py::arg("eps_factor") = 0.,
py::arg("max_bids_per_round") = 1,
"compute Wasserstein distance between two persistence diagrams");
m.def("hera_get_infinity", hera::get_infinity<double>,
"hera infinity is not equal float('inf'), but -1, be careful");
}
1 change: 1 addition & 0 deletions gtda/externals/hera
Submodule hera added at 2c5e6c
98 changes: 0 additions & 98 deletions gtda/externals/hera/bottleneck/README

This file was deleted.

Loading