diff --git a/.gitignore b/.gitignore index 66de543..988d148 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,3 @@ -# ignore all files -* - # tags file tags diff --git a/.gitmodules b/.gitmodules index 696f36a..0ff90eb 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,3 +10,6 @@ [submodule "yaml-cpp"] path = yaml-cpp url = https://github.com/jbeder/yaml-cpp +[submodule "pybind11"] + path = pybind11 + url = https://github.com/pybind/pybind11 diff --git a/CMakeLists.txt b/CMakeLists.txt index ac89c90..fe3d872 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,6 @@ project(coefficient-flow CXX) # * Gudhi under /usr/include/gudhi # * Eigen3 under /usr/include/eigen3 # * boost under /usr/include/boost -# # in case Eigen, and/or GUDHI are not found by find_package # try setting the paths to them manually @@ -21,6 +20,9 @@ project(coefficient-flow CXX) add_subdirectory(yaml-cpp) include_directories("./yaml-cpp/include/") +add_subdirectory(pybind11) +include_directories("./pybind11/include/") + add_subdirectory(KDTree) include_directories("./KDTree") @@ -56,7 +58,6 @@ set(CMAKE_BUILD_TYPE Release) include_directories( "./lib" ) - add_library(scomplex SHARED "./lib/scomplex/simplicial_complex.cpp") add_library(pathsnap SHARED "./lib/scomplex/path_snapper.cpp") target_link_libraries(pathsnap KDTree) @@ -75,3 +76,7 @@ add_custom_target(timing_test COMMAND "${CMAKE_CURRENT_BINARY_DIR}/run_dumb_tests.sh" "1" DEPENDS yamltest qhull2ply "test/run_dumb_tests.sh" "test/dumbexample.yaml") +#Python bindings: +add_library(coeffflow MODULE python/bindings.cpp) +target_link_libraries(coeffflow PRIVATE scomplex pybind11::module) +set_target_properties(coeffflow PROPERTIES PREFIX "" SUFFIX .so) diff --git a/README.md b/README.md index a4a0fa4..6a2e658 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,23 @@ make timing-test to run the timing tests, the files for the other tests, are still not provided. +### Using Python bindings + +In the python bindings we provide bindings for the `simplicial_complex` which uses only cells to for construction, and provides also bindings for the functions `cell_to_index` and `index_to_cell`. Furthermore we provide bindings for `coeff_flow` and `coeff_flow_embedded`. Below is a toy example run: + +```{python} +>>> import coeffflow +>>> a = coeffflow.simplicial_complex([[0,1,2]]) +>>> a.cell_to_index([0,2]) +1 +>>> a.index_to_cell(0,1) +[1] +>>> a.index_to_cell(1,2) +[2, 1] +>>> coeffflow.coeff_flow_embedded(a ,(1, [1,-1,1])) +(2, [1.0]) +``` + ### References/links [1]: Carvalho JF, Vejdemo-Johansson M, Kragic D, Pokorny FT. _An algorithm for calculating top-dimensional bounding chains._ 2017 [PeerJ Preprints 5:e3151v1](https://doi.org/10.7287/peerj.preprints.3151v1) diff --git a/pybind11 b/pybind11 new file mode 160000 index 0000000..534b756 --- /dev/null +++ b/pybind11 @@ -0,0 +1 @@ +Subproject commit 534b756cb3244aca959359c07d44e4fed3498ba8 diff --git a/python/bindings.cpp b/python/bindings.cpp new file mode 100644 index 0000000..d8c2132 --- /dev/null +++ b/python/bindings.cpp @@ -0,0 +1,23 @@ +#include + +#include +#include + +#include "scomplex/coeff_flow.hpp" +#include "scomplex/simplicial_complex.hpp" +#include "scomplex/types.hpp" + +using namespace gsimp; + +namespace py = pybind11; + +PYBIND11_MODULE(coeffflow, m) { + py::class_< simplicial_complex >(m, "simplicial_complex") // + .def(py::init< std::vector< cell_t >& >()) // + .def("cell_to_index", &simplicial_complex::cell_to_index) // + .def("index_to_cell", &simplicial_complex::index_to_cell); + + m.def("coeff_flow", coeff_flow); + + m.def("coeff_flow_embedded", coeff_flow_embedded); +};