Skip to content

Commit

Permalink
Merge pull request #31 from darioizzo/mp
Browse files Browse the repository at this point in the history
Introducing multiple precision differential algebra
  • Loading branch information
darioizzo authored May 25, 2018
2 parents 54b11b1 + 2c68c58 commit 2e0f4de
Show file tree
Hide file tree
Showing 42 changed files with 2,271 additions and 874 deletions.
41 changes: 28 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Main audi/pyaudi project version.
set(AUDI_PROJECT_VERSION 1.3)

# CMake version check.
cmake_minimum_required(VERSION 3.2)

Expand All @@ -17,6 +20,8 @@ endif()
# and only one must be chosen.
option(AUDI_BUILD_AUDI "Build audi." ON)
option(AUDI_BUILD_PYAUDI "Build pyaudi." OFF)
option(AUDI_WITH_MPPP "Enables multiple precision support based on the mp++ project." OFF)


# Check consistency.
if(AUDI_BUILD_AUDI AND AUDI_BUILD_PYAUDI)
Expand All @@ -27,9 +32,6 @@ if((NOT AUDI_BUILD_AUDI) AND (NOT AUDI_BUILD_PYAUDI))
message(FATAL_ERROR "Please select if you want to build audi or pyudi.")
endif()

# Main audi/pyaudi project version.
set(AUDI_PROJECT_VERSION 1.2.4)

if(AUDI_BUILD_AUDI)
# Initial setup of a audi build.
project(audi VERSION ${AUDI_PROJECT_VERSION})
Expand Down Expand Up @@ -87,6 +89,12 @@ endif()
list(REMOVE_ITEM AUDI_CXX_FLAGS_DEBUG "-Wduplicated-branches")
list(REMOVE_ITEM AUDI_CXX_FLAGS_DEBUG "-Wold-style-cast")

# Configure config.hpp.
if(AUDI_WITH_MPPP)
set(AUDI_ENABLE_MPPP "#define AUDI_WITH_MPPP")
endif()
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/config.hpp.in" "${CMAKE_CURRENT_SOURCE_DIR}/include/audi/config.hpp" @ONLY)

if(AUDI_BUILD_PYAUDI)
# audi dependencies.
include(YACMAPythonSetup)
Expand Down Expand Up @@ -125,7 +133,6 @@ if(AUDI_BUILD_AUDI)
message(STATUS "GMP library found.")
message(STATUS "GMP include dir is: ${GMP_INCLUDE_DIR}")
message(STATUS "GMP library is: ${GMP_LIBRARIES}")
include_directories(${GMP_INCLUDE_DIR})

# MPFR setup.
FIND_PACKAGE(MPFR REQUIRED)
Expand All @@ -139,12 +146,20 @@ if(AUDI_BUILD_AUDI)
message(FATAL_ERROR "Unsupported MPFR version, please upgrade.")
endif()
message(STATUS "MPFR version is ok.")
include_directories(${MPFR_INCLUDE_DIR})

if(AUDI_WITH_MPPP)
# MP++ SETUP
find_package(mp++ REQUIRED)
message(STATUS "mp++ library found.")
endif()

# Setup of the header-only audi library.
add_library(audi INTERFACE)
target_link_libraries(audi INTERFACE Threads::Threads Boost::boost Boost::serialization)
target_link_libraries(audi INTERFACE Eigen3::eigen3)
target_link_libraries(audi INTERFACE Eigen3::eigen3 MPFR::MPFR GMP::GMP)
if(AUDI_WITH_MPPP)
target_link_libraries(audi INTERFACE mp++::mp++)
endif()

# This sets up the include directory to be different if we build
target_include_directories(audi INTERFACE
Expand All @@ -154,13 +169,7 @@ if(AUDI_BUILD_AUDI)

# These lines are temporary with piranha v0.10, will be simplified when this is updated
target_include_directories(audi INTERFACE ${Piranha_INCLUDE_DIR})
target_include_directories(audi INTERFACE ${MPFR_INCLUDE_DIR})
target_include_directories(audi INTERFACE ${GMP_INCLUDE_DIR})
# First mpfr then gmp otherwise mingw is unhappy
target_link_libraries(audi INTERFACE ${MPFR_LIBRARIES})
target_link_libraries(audi INTERFACE ${GMP_LIBRARIES})



# Builds the main file
IF(AUDI_BUILD_MAIN)
add_executable(main main.cpp)
Expand All @@ -181,7 +190,13 @@ if(AUDI_BUILD_AUDI)

# Setup of the export.
install(TARGETS audi EXPORT audi_export)
# Setup of the optional deps.
set(_AUDI_CONFIG_OPTIONAL_DEPS)
if(AUDI_WITH_MPPP)
set(_AUDI_CONFIG_OPTIONAL_DEPS "${_AUDI_CONFIG_OPTIONAL_DEPS}find_package(mp++ REQUIRED)\n")
endif()
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/audi-config.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/audi-config.cmake" @ONLY)

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/audi-config.cmake" DESTINATION "lib/cmake/audi")
install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/FindGMP.cmake" "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/FindMPFR.cmake"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/FindPiranha.cmake" "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/AudiFindBoost.cmake"
Expand Down
1 change: 1 addition & 0 deletions audi-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ find_package(Piranha REQUIRED)
find_package(GMP REQUIRED)
find_package(MPFR REQUIRED)
find_package(Eigen3 REQUIRED)
@_AUDI_CONFIG_OPTIONAL_DEPS@

#Restore original module path.
set(CMAKE_MODULE_PATH "${_AUDI_CONFIG_OLD_MODULE_PATH}")
Expand Down
13 changes: 10 additions & 3 deletions cmake_modules/AudiFindBoost.cmake
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
set(_AUDI_REQUIRED_BOOST_LIBS)
list(APPEND _AUDI_REQUIRED_BOOST_LIBS timer chrono serialization system unit_test_framework)
if(_AUDI_FIND_BOOST_PYTHON)
if(${PYTHON_VERSION_MAJOR} EQUAL 2)
list(APPEND _AUDI_REQUIRED_BOOST_LIBS python)
# NOTE: since Boost 1.67, the naming of the Boost.Python library has changed to include the
# major and minor python version as a suffix. See the release notes:
# https://www.boost.org/users/history/version_1_67_0.html
if(${Boost_MAJOR_VERSION} GREATER 1 OR (${Boost_MAJOR_VERSION} EQUAL 1 AND ${Boost_MINOR_VERSION} GREATER 66))
list(APPEND _AUDI_REQUIRED_BOOST_LIBS "python${PYTHON_VERSION_MAJOR}${PYTHON_VERSION_MINOR}")
else()
list(APPEND _AUDI_REQUIRED_BOOST_LIBS python3)
if(${PYTHON_VERSION_MAJOR} EQUAL 2)
list(APPEND _AUDI_REQUIRED_BOOST_LIBS python)
else()
list(APPEND _AUDI_REQUIRED_BOOST_LIBS python3)
endif()
endif()
endif()
message(STATUS "Required Boost libraries: ${_AUDI_REQUIRED_BOOST_LIBS}")
Expand Down
29 changes: 18 additions & 11 deletions cmake_modules/FindGMP.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# http://websvn.kde.org/trunk/KDE/kdeutils/cmake/modules/FindGMP.cmake?view=markup&pathrev=675218

# Copyright (c) 2006, Laurent Montel, <[email protected]>
# Copyright (c) 2008-2011 Francesco Biscani, <[email protected]>
# Copyright (c) 2008-2018 Francesco Biscani, <[email protected]>

# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
Expand All @@ -13,7 +13,7 @@
# 2. Redistributions in binary form must reproduce the copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. The name of the author may not be used to endorse or promote products
# 3. The name of the author may not be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
Expand All @@ -28,16 +28,23 @@
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# ------------------------------------------------------------------------------------------

IF(GMP_INCLUDE_DIR AND GMP_LIBRARIES)
# Already in cache, be silent
SET(GMP_FIND_QUIETLY TRUE)
ENDIF(GMP_INCLUDE_DIR AND GMP_LIBRARIES)
if(GMP_INCLUDE_DIR AND GMP_LIBRARY)
# Already in cache, be silent
set(GMP_FIND_QUIETLY TRUE)
endif()

FIND_PATH(GMP_INCLUDE_DIR NAMES gmp.h)
FIND_LIBRARY(GMP_LIBRARIES NAMES gmp)
find_path(GMP_INCLUDE_DIR NAMES gmp.h)
find_library(GMP_LIBRARY NAMES gmp)

INCLUDE(FindPackageHandleStandardArgs)
include(FindPackageHandleStandardArgs)

FIND_PACKAGE_HANDLE_STANDARD_ARGS(GMP DEFAULT_MSG GMP_INCLUDE_DIR GMP_LIBRARIES)
find_package_handle_standard_args(GMP DEFAULT_MSG GMP_INCLUDE_DIR GMP_LIBRARY)

MARK_AS_ADVANCED(GMP_INCLUDE_DIR GMP_LIBRARIES)
mark_as_advanced(GMP_INCLUDE_DIR GMP_LIBRARY)

# NOTE: this has been adapted from CMake's FindPNG.cmake.
if(GMP_FOUND AND NOT TARGET GMP::GMP)
add_library(GMP::GMP UNKNOWN IMPORTED)
set_target_properties(GMP::GMP PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${GMP_INCLUDE_DIR}"
IMPORTED_LINK_INTERFACE_LANGUAGES "C" IMPORTED_LOCATION "${GMP_LIBRARY}")
endif()
29 changes: 18 additions & 11 deletions cmake_modules/FindMPFR.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# http://websvn.kde.org/trunk/KDE/kdeutils/cmake/modules/FindGMP.cmake?view=markup&pathrev=675218

# Copyright (c) 2006, Laurent Montel, <[email protected]>
# Copyright (c) 2008-2011 Francesco Biscani, <[email protected]>
# Copyright (c) 2008-2018 Francesco Biscani, <[email protected]>

# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
Expand All @@ -13,7 +13,7 @@
# 2. Redistributions in binary form must reproduce the copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. The name of the author may not be used to endorse or promote products
# 3. The name of the author may not be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
Expand All @@ -28,16 +28,23 @@
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# ------------------------------------------------------------------------------------------

IF(MPFR_INCLUDE_DIR AND MPFR_LIBRARIES)
# Already in cache, be silent
SET(MPFR_FIND_QUIETLY TRUE)
ENDIF(MPFR_INCLUDE_DIR AND MPFR_LIBRARIES)
if(MPFR_INCLUDE_DIR AND MPFR_LIBRARY)
# Already in cache, be silent
set(MPFR_FIND_QUIETLY TRUE)
endif()

FIND_PATH(MPFR_INCLUDE_DIR NAMES mpfr.h)
FIND_LIBRARY(MPFR_LIBRARIES NAMES mpfr)
find_path(MPFR_INCLUDE_DIR NAMES mpfr.h)
find_library(MPFR_LIBRARY NAMES mpfr)

INCLUDE(FindPackageHandleStandardArgs)
include(FindPackageHandleStandardArgs)

FIND_PACKAGE_HANDLE_STANDARD_ARGS(MPFR DEFAULT_MSG MPFR_INCLUDE_DIR MPFR_LIBRARIES)
find_package_handle_standard_args(MPFR DEFAULT_MSG MPFR_INCLUDE_DIR MPFR_LIBRARY)

MARK_AS_ADVANCED(MPFR_INCLUDE_DIR MPFR_LIBRARIES)
mark_as_advanced(MPFR_INCLUDE_DIR MPFR_LIBRARY)

# NOTE: this has been adapted from CMake's FindPNG.cmake.
if(MPFR_FOUND AND NOT TARGET MPFR::MPFR)
add_library(MPFR::MPFR UNKNOWN IMPORTED)
set_target_properties(MPFR::MPFR PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${MPFR_INCLUDE_DIR}"
IMPORTED_LINK_INTERFACE_LANGUAGES "C" IMPORTED_LOCATION "${MPFR_LIBRARY}")
endif()
11 changes: 11 additions & 0 deletions config.hpp.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef AUDI_CONFIG_HPP
#define AUDI_CONFIG_HPP

// Start of defines instantiated by CMake.
// clang-format off
#define AUDI_VERSION_STRING "@audi_VERSION@"
#define AUDI_VERSION_MAJOR @audi_VERSION_MAJOR@
#define AUDI_VERSION_MINOR @audi_VERSION_MINOR@
@AUDI_ENABLE_MPPP@

#endif
4 changes: 3 additions & 1 deletion doc/sphinx/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Audi and pyaudi
================================

Audi (not the car, rather from latin: "listen!") is an open source, header only, C++ library
(exposed to python in the pyaudi package) that implements the algebra of Taylor truncated polynomials and
(exposed to python in the pyaudi package) that implements the differential algebra of Taylor truncated polynomials and
a few algorithms useful for its applications (Differential Intelligence, automatic differentiation, Taylor Models, etc.)

When used for automated differentiation only, other automated differentiation codes may be more
Expand Down Expand Up @@ -45,6 +45,8 @@ Audi is open source (GPL3) and its code available in github <https://github.com/
notebooks/example00.ipynb
notebooks/example01.ipynb
notebooks/vectorized_double.ipynb
notebooks/mp_gdual.ipynb


.. toctree::
:maxdepth: 2
Expand Down
2 changes: 1 addition & 1 deletion doc/sphinx/notebooks/map_inversion.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.4"
"version": "3.6.5"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 2e0f4de

Please sign in to comment.