From 742097aed08265cf30c432946bef8dd79d901481 Mon Sep 17 00:00:00 2001 From: Duy-Nguyen Ta Date: Thu, 27 Jul 2017 22:26:53 -0400 Subject: [PATCH] eigency --> clonedEigency. Fixing bugs and improve eigency build. --- cmake/CMakeLists.txt | 2 +- cmake/FindClonedEigency.cmake | 27 +++++++++++++++ cmake/FindEigency.cmake | 27 --------------- cmake/GtsamCythonWrap.cmake | 2 +- cython/CMakeLists.txt | 9 +++-- cython/clonedEigency/CMakeLists.txt | 34 +++++++++++++++++++ cython/{eigency => clonedEigency}/LICENSE.txt | 0 .../{eigency => clonedEigency}/__init__.py.in | 0 .../conversions.pxd | 0 .../conversions.pyx | 0 cython/{eigency => clonedEigency}/core.pxd | 0 cython/{eigency => clonedEigency}/core.pyx | 0 .../{eigency => clonedEigency}/eigency_cpp.h | 22 ++++++------ cython/eigency/CMakeLists.txt | 17 ---------- wrap/Module.cpp | 4 +-- wrap/tests/expected-cython/geometry.pxd | 2 +- wrap/tests/expected-cython/geometry.pyx | 2 +- 17 files changed, 82 insertions(+), 66 deletions(-) create mode 100644 cmake/FindClonedEigency.cmake delete mode 100644 cmake/FindEigency.cmake create mode 100644 cython/clonedEigency/CMakeLists.txt rename cython/{eigency => clonedEigency}/LICENSE.txt (100%) rename cython/{eigency => clonedEigency}/__init__.py.in (100%) rename cython/{eigency => clonedEigency}/conversions.pxd (100%) rename cython/{eigency => clonedEigency}/conversions.pyx (100%) rename cython/{eigency => clonedEigency}/core.pxd (100%) rename cython/{eigency => clonedEigency}/core.pyx (100%) rename cython/{eigency => clonedEigency}/eigency_cpp.h (97%) delete mode 100644 cython/eigency/CMakeLists.txt diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index df0ca7582..19a219dd2 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -21,7 +21,7 @@ install(FILES GtsamCythonWrap.cmake GtsamTesting.cmake FindCython.cmake - FindEigency.cmake + FindClonedEigency.cmake FindNumPy.cmake README.html DESTINATION "${SCRIPT_INSTALL_DIR}/GTSAMCMakeTools") diff --git a/cmake/FindClonedEigency.cmake b/cmake/FindClonedEigency.cmake new file mode 100644 index 000000000..1286bfa7a --- /dev/null +++ b/cmake/FindClonedEigency.cmake @@ -0,0 +1,27 @@ +# Find the cloned version of eigency built and installed by gtsam +# +# This code sets the following variables: +# +# CLONEDEIGENCY_FOUND +# CLONEDEIGENCY_INCLUDE_DIRS +# + +# Find python +find_package( PythonInterp ) +if ( PYTHONINTERP_FOUND ) + execute_process( COMMAND "${PYTHON_EXECUTABLE}" "-c" + "import clonedEigency; includes=clonedEigency.get_includes(include_eigen=False); print includes[0], ';', includes[1]" + RESULT_VARIABLE RESULT + OUTPUT_VARIABLE CLONEDEIGENCY_INCLUDE_DIRS + OUTPUT_STRIP_TRAILING_WHITESPACE + ) +endif () + +include( FindPackageHandleStandardArgs ) +find_package_handle_standard_args(ClonedEigency + FOUND_VAR + CLONEDEIGENCY_FOUND + REQUIRED_VARS + CLONEDEIGENCY_INCLUDE_DIRS +) + diff --git a/cmake/FindEigency.cmake b/cmake/FindEigency.cmake deleted file mode 100644 index 3e48dab64..000000000 --- a/cmake/FindEigency.cmake +++ /dev/null @@ -1,27 +0,0 @@ -# Find Eigency -# -# This code sets the following variables: -# -# EIGENCY_FOUND -# EIGENCY_INCLUDE_DIRS -# - -# Find python -find_package( PythonInterp ) -if ( PYTHONINTERP_FOUND ) - execute_process( COMMAND "${PYTHON_EXECUTABLE}" "-c" - "import eigency; includes=eigency.get_includes(include_eigen=False); print includes[0], ';', includes[1]" - RESULT_VARIABLE RESULT - OUTPUT_VARIABLE EIGENCY_INCLUDE_DIRS - OUTPUT_STRIP_TRAILING_WHITESPACE - ) -endif () - -include( FindPackageHandleStandardArgs ) -find_package_handle_standard_args(Eigency - FOUND_VAR - EIGENCY_FOUND - REQUIRED_VARS - EIGENCY_INCLUDE_DIRS -) - diff --git a/cmake/GtsamCythonWrap.cmake b/cmake/GtsamCythonWrap.cmake index 874383199..f49677d0e 100644 --- a/cmake/GtsamCythonWrap.cmake +++ b/cmake/GtsamCythonWrap.cmake @@ -58,7 +58,7 @@ function(pyx_to_cpp target pyx_file generated_cpp include_dirs) add_custom_command( OUTPUT ${generated_cpp} COMMAND - cython --cplus ${includes_for_cython} ${pyx_file} -o ${generated_cpp} + cython -v --cplus ${includes_for_cython} ${pyx_file} -o ${generated_cpp} VERBATIM) add_custom_target(${target} ALL DEPENDS ${generated_cpp}) endfunction() diff --git a/cython/CMakeLists.txt b/cython/CMakeLists.txt index 43e00c139..7ea8cd05b 100644 --- a/cython/CMakeLists.txt +++ b/cython/CMakeLists.txt @@ -3,10 +3,9 @@ include(GtsamCythonWrap) # Create the cython toolbox for the gtsam library if (GTSAM_INSTALL_CYTHON_TOOLBOX) - # build and include eigency - add_subdirectory(eigency) - include_directories(eigency) - file(COPY eigency DESTINATION ".") # so eigency's cython headers can be found when cythonizing gtsam + # build and include the eigency version of eigency + add_subdirectory(clonedEigency) + include_directories(${PROJECT_BINARY_DIR}/cython/clonedEigency) # wrap gtsam add_custom_target(gtsam_header DEPENDS "../gtsam.h") @@ -14,7 +13,7 @@ if (GTSAM_INSTALL_CYTHON_TOOLBOX) "" # extra imports "${GTSAM_CYTHON_INSTALL_PATH}/gtsam" # install path gtsam # library to link with - "wrap;gtsam;gtsam_header" # dependencies which need to be built before wrapping + "wrap;cythonize_eigency;gtsam;gtsam_header" # dependencies which need to be built before wrapping ) # wrap gtsam_unstable diff --git a/cython/clonedEigency/CMakeLists.txt b/cython/clonedEigency/CMakeLists.txt new file mode 100644 index 000000000..92dcb9d31 --- /dev/null +++ b/cython/clonedEigency/CMakeLists.txt @@ -0,0 +1,34 @@ +include(GtsamCythonWrap) + +# Copy eigency's sources to the build folder +# so that the cython-generated header "conversions_api.h" can be found when cythonizing eigency's core +# and eigency's cython pxd headers can be found when cythonizing gtsam +file(COPY "." DESTINATION ".") +set(OUTPUT_DIR "${PROJECT_BINARY_DIR}/cython/clonedEigency") +set(EIGENCY_INCLUDE_DIR ${OUTPUT_DIR}) + +# This is to make the build/cython/clonedEigency folder a python package +configure_file(__init__.py.in ${PROJECT_BINARY_DIR}/cython/clonedEigency/__init__.py) + +# include eigency headers +include_directories(${EIGENCY_INCLUDE_DIR}) + +# Cythonize and build eigency +message(STATUS "Cythonize and build eigency") +# Important trick: use "../clonedEigency/conversions.pyx" to let cython know that the conversions module is +# a part of the clonedEigency package and generate the function call import_clonedEigency__conversions() +# in conversions_api.h correctly!!! +cythonize(cythonize_eigency_conversions "../clonedEigency/conversions.pyx" "conversions" + "${OUTPUT_DIR}" "${EIGENCY_INCLUDE_DIR}" "" "") +cythonize(cythonize_eigency_core "../clonedEigency/core.pyx" "core" + ${OUTPUT_DIR} "${EIGENCY_INCLUDE_DIR}" "" "") +add_dependencies(cythonize_eigency_core cythonize_eigency_conversions) +add_custom_target(cythonize_eigency) +add_dependencies(cythonize_eigency cythonize_eigency_conversions cythonize_eigency_core) + +# install +install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DESTINATION ${GTSAM_CYTHON_INSTALL_PATH}) +install(TARGETS cythonize_eigency_core cythonize_eigency_conversions + DESTINATION "${GTSAM_CYTHON_INSTALL_PATH}/clonedEigency") +install(FILES "${OUTPUT_DIR}/conversions_api.h" DESTINATION ${GTSAM_CYTHON_INSTALL_PATH}/clonedEigency) +configure_file(__init__.py.in ${GTSAM_CYTHON_INSTALL_PATH}/clonedEigency/__init__.py) diff --git a/cython/eigency/LICENSE.txt b/cython/clonedEigency/LICENSE.txt similarity index 100% rename from cython/eigency/LICENSE.txt rename to cython/clonedEigency/LICENSE.txt diff --git a/cython/eigency/__init__.py.in b/cython/clonedEigency/__init__.py.in similarity index 100% rename from cython/eigency/__init__.py.in rename to cython/clonedEigency/__init__.py.in diff --git a/cython/eigency/conversions.pxd b/cython/clonedEigency/conversions.pxd similarity index 100% rename from cython/eigency/conversions.pxd rename to cython/clonedEigency/conversions.pxd diff --git a/cython/eigency/conversions.pyx b/cython/clonedEigency/conversions.pyx similarity index 100% rename from cython/eigency/conversions.pyx rename to cython/clonedEigency/conversions.pyx diff --git a/cython/eigency/core.pxd b/cython/clonedEigency/core.pxd similarity index 100% rename from cython/eigency/core.pxd rename to cython/clonedEigency/core.pxd diff --git a/cython/eigency/core.pyx b/cython/clonedEigency/core.pyx similarity index 100% rename from cython/eigency/core.pyx rename to cython/clonedEigency/core.pyx diff --git a/cython/eigency/eigency_cpp.h b/cython/clonedEigency/eigency_cpp.h similarity index 97% rename from cython/eigency/eigency_cpp.h rename to cython/clonedEigency/eigency_cpp.h index 90a21de07..4eae69869 100644 --- a/cython/eigency/eigency_cpp.h +++ b/cython/clonedEigency/eigency_cpp.h @@ -215,7 +215,7 @@ inline PyArrayObject *_ndarray_copy >(const std::complex inline PyArrayObject *ndarray(Eigen::PlainObjectBase &m) { - import_eigency__conversions(); + import_clonedEigency__conversions(); return _ndarray_view(m.data(), m.rows(), m.cols(), m.IsRowMajor); } // If C++11 is available, check if m is an r-value reference, in @@ -223,56 +223,56 @@ inline PyArrayObject *ndarray(Eigen::PlainObjectBase &m) { #if __cplusplus >= 201103L template inline PyArrayObject *ndarray(Eigen::PlainObjectBase &&m) { - import_eigency__conversions(); + import_clonedEigency__conversions(); return _ndarray_copy(m.data(), m.rows(), m.cols(), m.IsRowMajor); } #endif template inline PyArrayObject *ndarray(const Eigen::PlainObjectBase &m) { - import_eigency__conversions(); + import_clonedEigency__conversions(); return _ndarray_copy(m.data(), m.rows(), m.cols(), m.IsRowMajor); } template inline PyArrayObject *ndarray_view(Eigen::PlainObjectBase &m) { - import_eigency__conversions(); + import_clonedEigency__conversions(); return _ndarray_view(m.data(), m.rows(), m.cols(), m.IsRowMajor); } template inline PyArrayObject *ndarray_view(const Eigen::PlainObjectBase &m) { - import_eigency__conversions(); + import_clonedEigency__conversions(); return _ndarray_view(const_cast(m.data()), m.rows(), m.cols(), m.IsRowMajor); } template inline PyArrayObject *ndarray_copy(const Eigen::PlainObjectBase &m) { - import_eigency__conversions(); + import_clonedEigency__conversions(); return _ndarray_copy(m.data(), m.rows(), m.cols(), m.IsRowMajor); } template inline PyArrayObject *ndarray(Eigen::Map &m) { - import_eigency__conversions(); + import_clonedEigency__conversions(); return _ndarray_view(m.data(), m.rows(), m.cols(), m.IsRowMajor, m.outerStride(), m.innerStride()); } template inline PyArrayObject *ndarray(const Eigen::Map &m) { - import_eigency__conversions(); + import_clonedEigency__conversions(); // Since this is a map, we assume that ownership is correctly taken care // of, and we avoid taking a copy return _ndarray_view(const_cast(m.data()), m.rows(), m.cols(), m.IsRowMajor, m.outerStride(), m.innerStride()); } template inline PyArrayObject *ndarray_view(Eigen::Map &m) { - import_eigency__conversions(); + import_clonedEigency__conversions(); return _ndarray_view(m.data(), m.rows(), m.cols(), m.IsRowMajor, m.outerStride(), m.innerStride()); } template inline PyArrayObject *ndarray_view(const Eigen::Map &m) { - import_eigency__conversions(); + import_clonedEigency__conversions(); return _ndarray_view(const_cast(m.data()), m.rows(), m.cols(), m.IsRowMajor, m.outerStride(), m.innerStride()); } template inline PyArrayObject *ndarray_copy(const Eigen::Map &m) { - import_eigency__conversions(); + import_clonedEigency__conversions(); return _ndarray_copy(m.data(), m.rows(), m.cols(), m.IsRowMajor, m.outerStride(), m.innerStride()); } diff --git a/cython/eigency/CMakeLists.txt b/cython/eigency/CMakeLists.txt deleted file mode 100644 index 536a01626..000000000 --- a/cython/eigency/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -include(GtsamCythonWrap) - -# include eigency headers -set(EIGENCY_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) -include_directories(${EIGENCY_INCLUDE_DIR}) - -# cythonize and build eigency -message(STATUS "Cythonize and build eigency") -cythonize(cythonize_eigency_core "${CMAKE_CURRENT_SOURCE_DIR}/core.pyx" "core" - "${PROJECT_BINARY_DIR}/cython/eigency" "${EIGENCY_INCLUDE_DIR}" "" "") -cythonize(cythonize_eigency_conversions "${CMAKE_CURRENT_SOURCE_DIR}/conversions.pyx" "conversions" - "${PROJECT_BINARY_DIR}/cython/eigency" "${EIGENCY_INCLUDE_DIR}" "" "") - -install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} DESTINATION ${GTSAM_CYTHON_INSTALL_PATH}) -install(TARGETS cythonize_eigency_core cythonize_eigency_conversions - DESTINATION ${GTSAM_CYTHON_INSTALL_PATH}/eigency) -configure_file(__init__.py.in ${GTSAM_CYTHON_INSTALL_PATH}/eigency/__init__.py) diff --git a/wrap/Module.cpp b/wrap/Module.cpp index d071a5e2e..28b96b253 100644 --- a/wrap/Module.cpp +++ b/wrap/Module.cpp @@ -334,7 +334,7 @@ void Module::generate_cython_wrapper(const string& toolboxPath, const std::strin /* ************************************************************************* */ void Module::emit_cython_pxd(FileWriter& pxdFile) const { // headers - pxdFile.oss << "from eigency.core cimport *\n" + pxdFile.oss << "from clonedEigency.core cimport *\n" "from libcpp.string cimport string\n" "from libcpp.vector cimport vector\n" "from libcpp.pair cimport pair\n" @@ -416,7 +416,7 @@ void Module::emit_cython_pyx(FileWriter& pyxFile) const { for(const Qualified& q: Qualified::BasicTypedefs) { pyxFile.oss << "from " << pxdHeader << " cimport " << q.pxdClassName() << "\n"; } - pyxFile.oss << "from eigency.core cimport *\n" + pyxFile.oss << "from clonedEigency.core cimport *\n" "from libcpp cimport bool\n\n" "from libcpp.pair cimport pair\n" "from libcpp.string cimport string\n" diff --git a/wrap/tests/expected-cython/geometry.pxd b/wrap/tests/expected-cython/geometry.pxd index 918eeea6f..b4d36c91a 100644 --- a/wrap/tests/expected-cython/geometry.pxd +++ b/wrap/tests/expected-cython/geometry.pxd @@ -1,5 +1,5 @@ -from eigency.core cimport * +from clonedEigency.core cimport * from libcpp.string cimport string from libcpp.vector cimport vector from libcpp.pair cimport pair diff --git a/wrap/tests/expected-cython/geometry.pyx b/wrap/tests/expected-cython/geometry.pyx index f7361500d..143662537 100644 --- a/wrap/tests/expected-cython/geometry.pyx +++ b/wrap/tests/expected-cython/geometry.pyx @@ -4,7 +4,7 @@ cimport geometry from geometry cimport shared_ptr from geometry cimport dynamic_pointer_cast from geometry cimport make_shared -from eigency.core cimport * +from clonedEigency.core cimport * from libcpp cimport bool from libcpp.pair cimport pair