Skip to content

Commit

Permalink
Merge pull request #21 from crvs/python3
Browse files Browse the repository at this point in the history
Python3
  • Loading branch information
crvs authored Jun 28, 2018
2 parents 994805b + 242bba5 commit 4d01e49
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 5 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# ignore all files
*

# tags file
tags

Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 7 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")

Expand Down Expand Up @@ -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)
Expand All @@ -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)
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions pybind11
Submodule pybind11 added at 534b75
23 changes: 23 additions & 0 deletions python/bindings.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <vector>

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

#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);
};

1 comment on commit 4d01e49

@crvs
Copy link
Owner Author

@crvs crvs commented on 4d01e49 Jun 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixes #20

Please sign in to comment.