From 05c9c0060ec8ff4cbf8619ff74724c2eea426d84 Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Tue, 8 Sep 2020 16:43:36 +0200 Subject: CMake > 3.5 to use Boost targets. Compile only what is available from boost targets --- .../modules/GUDHI_third_party_libraries.cmake | 39 +++------------------- 1 file changed, 4 insertions(+), 35 deletions(-) (limited to 'src/cmake/modules/GUDHI_third_party_libraries.cmake') diff --git a/src/cmake/modules/GUDHI_third_party_libraries.cmake b/src/cmake/modules/GUDHI_third_party_libraries.cmake index a56a2756..489f3de5 100644 --- a/src/cmake/modules/GUDHI_third_party_libraries.cmake +++ b/src/cmake/modules/GUDHI_third_party_libraries.cmake @@ -1,42 +1,11 @@ # This files manage third party libraries required by GUDHI -find_package(Boost 1.56.0 REQUIRED COMPONENTS system filesystem unit_test_framework program_options thread) +find_package(Boost 1.56.0 QUIET OPTIONAL_COMPONENTS system thread filesystem unit_test_framework program_options) -if(NOT Boost_FOUND) +# Boost_FOUND is not reliable +if(NOT Boost_VERSION) message(FATAL_ERROR "NOTICE: This program requires Boost and will not be compiled.") -endif(NOT Boost_FOUND) - -# cf. https://cliutils.gitlab.io/modern-cmake/chapters/packages/Boost.html -# This is needed if your Boost version is newer than your CMake version -# or if you have an old version of CMake (<3.5) -if(NOT TARGET Boost::program_options) - add_library(Boost::program_options IMPORTED INTERFACE) - set_property(TARGET Boost::program_options PROPERTY - INTERFACE_INCLUDE_DIRECTORIES ${Boost_INCLUDE_DIR}) - set_property(TARGET Boost::program_options PROPERTY - INTERFACE_LINK_LIBRARIES ${Boost_LIBRARIES}) -endif() -if(NOT TARGET Boost::filesystem) - add_library(Boost::filesystem IMPORTED INTERFACE) - set_property(TARGET Boost::filesystem PROPERTY - INTERFACE_INCLUDE_DIRECTORIES ${Boost_INCLUDE_DIR}) - set_property(TARGET Boost::filesystem PROPERTY - INTERFACE_LINK_LIBRARIES ${Boost_LIBRARIES}) -endif() -if(NOT TARGET Boost::unit_test_framework) - add_library(Boost::unit_test_framework IMPORTED INTERFACE) - set_property(TARGET Boost::unit_test_framework PROPERTY - INTERFACE_INCLUDE_DIRECTORIES ${Boost_INCLUDE_DIR}) - set_property(TARGET Boost::unit_test_framework PROPERTY - INTERFACE_LINK_LIBRARIES ${Boost_LIBRARIES}) -endif() -if(NOT TARGET Boost::system) - add_library(Boost::system IMPORTED INTERFACE) - set_property(TARGET Boost::system PROPERTY - INTERFACE_INCLUDE_DIRECTORIES ${Boost_INCLUDE_DIR}) - set_property(TARGET Boost::system PROPERTY - INTERFACE_LINK_LIBRARIES ${Boost_LIBRARIES}) -endif() +endif(NOT Boost_VERSION) find_package(GMP) if(GMP_FOUND) -- cgit v1.2.3 From c09f54487cc88eeb3afe1629ff8a3edc223df1eb Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Wed, 9 Sep 2020 11:17:02 +0200 Subject: Even if CGAL was requiring boost::thread no need to find it for gudhi. boost::thread removed from cgal on https://github.com/CGAL/cgal/commit/8a7d3fa --- src/cmake/modules/GUDHI_third_party_libraries.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/cmake/modules/GUDHI_third_party_libraries.cmake') diff --git a/src/cmake/modules/GUDHI_third_party_libraries.cmake b/src/cmake/modules/GUDHI_third_party_libraries.cmake index 489f3de5..1fbc4244 100644 --- a/src/cmake/modules/GUDHI_third_party_libraries.cmake +++ b/src/cmake/modules/GUDHI_third_party_libraries.cmake @@ -1,6 +1,6 @@ # This files manage third party libraries required by GUDHI -find_package(Boost 1.56.0 QUIET OPTIONAL_COMPONENTS system thread filesystem unit_test_framework program_options) +find_package(Boost 1.56.0 QUIET OPTIONAL_COMPONENTS filesystem unit_test_framework program_options) # Boost_FOUND is not reliable if(NOT Boost_VERSION) -- cgit v1.2.3 From e7b7947adf13ec1dcb8c126a4373fa29baaecb63 Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Tue, 29 Sep 2020 13:23:56 +0200 Subject: Added tests for wasserstein distance with tensorflow --- .../modules/GUDHI_third_party_libraries.cmake | 1 + src/python/CMakeLists.txt | 8 +++++++ src/python/doc/installation.rst | 5 +++++ src/python/test/test_wasserstein_with_tensors.py | 25 ++++++++++++++++++++++ 4 files changed, 39 insertions(+) create mode 100755 src/python/test/test_wasserstein_with_tensors.py (limited to 'src/cmake/modules/GUDHI_third_party_libraries.cmake') diff --git a/src/cmake/modules/GUDHI_third_party_libraries.cmake b/src/cmake/modules/GUDHI_third_party_libraries.cmake index 1fbc4244..9dadac4f 100644 --- a/src/cmake/modules/GUDHI_third_party_libraries.cmake +++ b/src/cmake/modules/GUDHI_third_party_libraries.cmake @@ -155,6 +155,7 @@ if( PYTHONINTERP_FOUND ) find_python_module("pykeops") find_python_module("eagerpy") find_python_module_no_version("hnswlib") + find_python_module("tensorflow") endif() if(NOT GUDHI_PYTHON_PATH) diff --git a/src/python/CMakeLists.txt b/src/python/CMakeLists.txt index 4f26481e..cc71503f 100644 --- a/src/python/CMakeLists.txt +++ b/src/python/CMakeLists.txt @@ -103,6 +103,9 @@ if(PYTHONINTERP_FOUND) if(EAGERPY_FOUND) add_gudhi_debug_info("EagerPy version ${EAGERPY_VERSION}") endif() + if(TENSORFLOW_FOUND) + add_gudhi_debug_info("TensorFlow version ${TENSORFLOW_VERSION}") + endif() set(GUDHI_PYTHON_EXTRA_COMPILE_ARGS "${GUDHI_PYTHON_EXTRA_COMPILE_ARGS}'-DBOOST_RESULT_OF_USE_DECLTYPE', ") set(GUDHI_PYTHON_EXTRA_COMPILE_ARGS "${GUDHI_PYTHON_EXTRA_COMPILE_ARGS}'-DBOOST_ALL_NO_LIB', ") @@ -501,6 +504,11 @@ if(PYTHONINTERP_FOUND) endif() add_gudhi_py_test(test_wasserstein_barycenter) endif() + if(OT_FOUND) + if(TENSORFLOW_FOUND AND EAGERPY_FOUND) + add_gudhi_py_test(test_wasserstein_with_tensors) + endif() + endif() # Representations if(SKLEARN_FOUND AND MATPLOTLIB_FOUND) diff --git a/src/python/doc/installation.rst b/src/python/doc/installation.rst index 2f161d66..66efe45a 100644 --- a/src/python/doc/installation.rst +++ b/src/python/doc/installation.rst @@ -394,6 +394,11 @@ mathematics, science, and engineering. :class:`~gudhi.point_cloud.knn.KNearestNeighbors` can use the Python package `SciPy `_ as a backend if explicitly requested. +TensorFlow +---------- + +`TensorFlow `_ is currently only used in some automatic differentiation tests. + Bug reports and contributions ***************************** diff --git a/src/python/test/test_wasserstein_with_tensors.py b/src/python/test/test_wasserstein_with_tensors.py new file mode 100755 index 00000000..8957705d --- /dev/null +++ b/src/python/test/test_wasserstein_with_tensors.py @@ -0,0 +1,25 @@ +""" This file is part of the Gudhi Library - https://gudhi.inria.fr/ - which is released under MIT. + See file LICENSE or go to https://gudhi.inria.fr/licensing/ for full license details. + Author(s): Mathieu Carriere + + Copyright (C) 2020 Inria + + Modification(s): + - YYYY/MM Author: Description of the modification +""" + +from gudhi.wasserstein import wasserstein_distance as pot +import numpy as np + +def test_wasserstein_distance_grad_tensorflow(): + import tensorflow as tf + + with tf.GradientTape() as tape: + diag4 = tf.convert_to_tensor(tf.Variable(initial_value=np.array([[0., 10.]]), trainable=True)) + diag5 = tf.convert_to_tensor(tf.Variable(initial_value=np.array([[1., 11.], [3., 4.]]), trainable=True)) + dist45 = pot(diag4, diag5, internal_p=1, order=1, enable_autodiff=True) + assert dist45 == 3. + + grads = tape.gradient(dist45, [diag4, diag5]) + assert np.array_equal(grads[0].values, [[-1., -1.]]) + assert np.array_equal(grads[1].values, [[1., 1.], [-1., 1.]]) \ No newline at end of file -- cgit v1.2.3 From eed023832e1b917d022fa8fa1a62dac40e88f121 Mon Sep 17 00:00:00 2001 From: ROUVREAU Vincent Date: Mon, 30 Nov 2020 15:31:45 +0100 Subject: Fix pykeops 1.4.2 where version is very verbose on 2 lines --- src/cmake/modules/GUDHI_third_party_libraries.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/cmake/modules/GUDHI_third_party_libraries.cmake') diff --git a/src/cmake/modules/GUDHI_third_party_libraries.cmake b/src/cmake/modules/GUDHI_third_party_libraries.cmake index 9dadac4f..e1566877 100644 --- a/src/cmake/modules/GUDHI_third_party_libraries.cmake +++ b/src/cmake/modules/GUDHI_third_party_libraries.cmake @@ -106,8 +106,8 @@ function( find_python_module PYTHON_MODULE_NAME ) OUTPUT_VARIABLE PYTHON_MODULE_VERSION ERROR_VARIABLE PYTHON_MODULE_ERROR) if(PYTHON_MODULE_RESULT EQUAL 0) - # Remove carriage return - string(STRIP ${PYTHON_MODULE_VERSION} PYTHON_MODULE_VERSION) + # Remove all carriage returns as it can be multiline + string(REGEX REPLACE "\n" " " PYTHON_MODULE_VERSION "${PYTHON_MODULE_VERSION}") message ("++ Python module ${PYTHON_MODULE_NAME} - Version ${PYTHON_MODULE_VERSION} found") set(${PYTHON_MODULE_NAME_UP}_VERSION ${PYTHON_MODULE_VERSION} PARENT_SCOPE) -- cgit v1.2.3