From e4abae7a58633c3c19cf14b6255d705cc5d6f532 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Tue, 9 Feb 2016 22:06:01 +0000 Subject: cython folder containing gudhi module. First shot with SimplexTree and MiniSimplexTree constructor/destructor git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/ST_cythonize@1013 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 83e6607c5d53bd8a414421e50e08f5f8150d2b4d --- src/cython/Makefile | 8 ++++++++ src/cython/cgudhi.pxd | 9 +++++++++ src/cython/gudhi.pyx | 18 ++++++++++++++++++ src/cython/main.py | 5 +++++ src/cython/setup.py | 15 +++++++++++++++ 5 files changed, 55 insertions(+) create mode 100644 src/cython/Makefile create mode 100644 src/cython/cgudhi.pxd create mode 100644 src/cython/gudhi.pyx create mode 100755 src/cython/main.py create mode 100644 src/cython/setup.py (limited to 'src/cython') diff --git a/src/cython/Makefile b/src/cython/Makefile new file mode 100644 index 00000000..b694ab47 --- /dev/null +++ b/src/cython/Makefile @@ -0,0 +1,8 @@ +ext: + python setup.py build_ext --inplace + +test: + python main.py + +clean: + rm -rf build/ *.o *.so *.cpp diff --git a/src/cython/cgudhi.pxd b/src/cython/cgudhi.pxd new file mode 100644 index 00000000..9ba40999 --- /dev/null +++ b/src/cython/cgudhi.pxd @@ -0,0 +1,9 @@ + +cdef extern from "include/gudhi/Simplex_tree.h" namespace "Gudhi": + cdef cppclass Simplex_tree_options_full_featured: + pass + cdef Simplex_tree_options_fast_persistence: + pass + cdef cppclass Simplex_tree[T]: + Simplex_tree() + diff --git a/src/cython/gudhi.pyx b/src/cython/gudhi.pyx new file mode 100644 index 00000000..6fab0726 --- /dev/null +++ b/src/cython/gudhi.pyx @@ -0,0 +1,18 @@ +from cython cimport numeric +cimport cgudhi + +cdef class SimplexTree: + cdef cgudhi.Simplex_tree[cgudhi.Simplex_tree_options_full_featured] *thisptr + def __cinit__(self): + self.thisptr = new cgudhi.Simplex_tree[cgudhi.Simplex_tree_options_full_featured]() + def __dealloc__(self): + if self.thisptr != NULL: + del self.thisptr + +cdef class MiniSimplexTree: + cdef cgudhi.Simplex_tree[cgudhi.Simplex_tree_options_fast_persistence] *thisptr + def __cinit__(self): + self.thisptr = new cgudhi.Simplex_tree[cgudhi.Simplex_tree_options_fast_persistence]() + def __dealloc__(self): + if self.thisptr != NULL: + del self.thisptr diff --git a/src/cython/main.py b/src/cython/main.py new file mode 100755 index 00000000..cb7a4754 --- /dev/null +++ b/src/cython/main.py @@ -0,0 +1,5 @@ +#!/usr/bin/env python + +import gudhi + +st = gudhi.SimplexTree() diff --git a/src/cython/setup.py b/src/cython/setup.py new file mode 100644 index 00000000..26a46590 --- /dev/null +++ b/src/cython/setup.py @@ -0,0 +1,15 @@ +from distutils.core import setup, Extension +from Cython.Build import cythonize + +gudhi = Extension( + "gudhi", + sources = ['gudhi.pyx',], + language = 'c++', + extra_compile_args=['-std=c++11'], + include_dirs = ['..'], +) + +setup( + name = 'gudhi', + ext_modules = cythonize(gudhi), +) -- cgit v1.2.3