From d7677b1f3f5ceee9cfdb5275ef00cbf79a714122 Mon Sep 17 00:00:00 2001 From: Bryn Keller Date: Mon, 7 Mar 2016 13:51:48 -0800 Subject: Python interface to PHAT --- python/README.rst | 110 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 python/README.rst (limited to 'python/README.rst') diff --git a/python/README.rst b/python/README.rst new file mode 100644 index 0000000..b67ff47 --- /dev/null +++ b/python/README.rst @@ -0,0 +1,110 @@ +Persistent Homology Algorithm Toolkit (PHAT) +============================================ + +This is a Python interface for the `Persistent Homology Algorithm Toolkit`_, a software library +that contains methods for computing the persistence pairs of a +filtered cell complex represented by an ordered boundary matrix with Z\ :sub:`2` coefficients. + +For an introduction to persistent homology, see the textbook [1]_. This software package +contains code for several algorithmic variants: + +* The "standard" algorithm (see [1]_, p.153) +* The "row" algorithm from [2]_ (called pHrow in that paper) +* The "twist" algorithm, as described in [3]_ (default algorithm) +* The "chunk" algorithm presented in [4]_ +* The "spectral sequence" algorithm (see [1]_, p.166) + +All but the standard algorithm exploit the special structure of the boundary matrix +to take shortcuts in the computation. The chunk and the spectral sequence algorithms +make use of multiple CPU cores if PHAT is compiled with OpenMP support. + +All algorithms are implemented as function objects that manipulate a given +``boundary_matrix`` (to be defined below) object to reduced form. +From this reduced form one can then easily extract the persistence pairs. +Alternatively, one can use the ``compute_persistence_pairs function`` which takes an +algorithm as a parameter, reduces the given ``boundary_matrix`` and stores the +resulting pairs in a given ``persistence_pairs`` object. + +The ``boundary_matrix`` class takes a "Representation" class as a parameter. +This representation defines how columns of the matrix are represented and how +low-level operations (e.g., column additions) are performed. The right choice of the +representation class can be as important for the performance of the program as choosing +the algorithm. We provide the following choices of representation classes: + +* ``vector_vector``: Each column is represented as a sorted ``std::vector`` of integers, containing the indices of the non-zero entries of the column. The matrix itself is a ``std::vector`` of such columns. +* ``vector_heap``: Each column is represented as a heapified ``std::vector`` of integers, containing the indices of the non-zero entries of the column. The matrix itself is a ``std::vector`` of such columns. +* ``vector_set``: Each column is a ``std::set`` of integers, with the same meaning as above. The matrix is stored as a ``std::vector`` of such columns. +* ``vector_list``: Each column is a sorted ``std::list`` of integers, with the same meaning as above. The matrix is stored as a ``std::vector`` of such columns. +* ``sparse_pivot_column``: The matrix is stored as in the vector_vector representation. However, when a column is manipulated, it is first converted into a ``std::set``, using an extra data field called the "pivot column". When another column is manipulated later, the pivot column is converted back to the ``std::vector`` representation. This can lead to significant speed improvements when many columns are added to a given pivot column consecutively. In a multicore setup, there is one pivot column per thread. +* ``heap_pivot_column``: The same idea as in the sparse version. Instead of a ``std::set``, the pivot column is represented by a ``std::priority_queue``. +* ``full_pivot_column``: The same idea as in the sparse version. However, instead of a ``std::set``, the pivot column is expanded into a bit vector of size n (the dimension of the matrix). To avoid costly initializations, the class remembers which entries have been manipulated for a pivot column and updates only those entries when another column becomes the pivot. +* ``bit_tree_pivot_column`` (default representation): Similar to the ``full_pivot_column`` but the implementation is more efficient. Internally it is a bit-set with fast iteration over nonzero elements, and fast access to the maximal element. + +Sample usage +------------ + +From src/simple_example.py in the source:: + + print(""" + we will build an ordered boundary matrix of this simplicial complex consisting of a single triangle: + + 3 + |\\ + | \\ + | \\ + | \\ 4 + 5| \\ + | \\ + | 6 \\ + | \\ + |________\\ + 0 2 1 + + """) + + import phat + + # set the dimension of the cell that each column represents: + dimensions = [0, 0, 1, 0, 1, 1, 2] + + # define a boundary matrix with the chosen internal representation + boundary_matrix = phat.boundary_matrix(representation = phat.representations.vector_vector) + + # set the respective columns -- the columns entries have to be sorted + boundary_matrix.set_dims(dimensions) + boundary_matrix.set_col(0, []) + boundary_matrix.set_col(1, []) + boundary_matrix.set_col(2, [0,1]) + boundary_matrix.set_col(3, []) + boundary_matrix.set_col(4, [1,3]) + boundary_matrix.set_col(5, [0,3]) + boundary_matrix.set_col(6, [2,4,5]) + + # print some information of the boundary matrix: + print() + print("the boundary matrix has %d columns:" % boundary_matrix.get_num_cols()) + for col_idx in range(boundary_matrix.get_num_cols()): + s = "column %d represents a cell of dimension %d." % (col_idx, boundary_matrix.get_dim(col_idx)) + if (not boundary_matrix.is_empty(col_idx)): + s = s + " its boundary consists of the cells " + " ".join([str(c) for c in boundary_matrix.get_col(col_idx)]) + print(s) + print("overall, the boundary matrix has %d entries." % boundary_matrix.get_num_entries()) + + pairs = phat.compute_persistence_pairs(boundary_matrix) + + pairs.sort() + + print() + + print("there are %d persistence pairs: " % len(pairs)) + for pair in pairs: + print("birth: %d, death: %d" % pair) + +References: + +.. [1] H.Edelsbrunner, J.Harer: Computational Topology, An Introduction. American Mathematical Society, 2010, ISBN 0-8218-4925-5 +.. [2] V.de Silva, D.Morozov, M.Vejdemo-Johansson: Dualities in persistent (co)homology. Inverse Problems 27, 2011 +.. [3] C.Chen, M.Kerber: Persistent Homology Computation With a Twist. 27th European Workshop on Computational Geometry, 2011. +.. [4] U.Bauer, M.Kerber, J.Reininghaus: Clear and Compress: Computing Persistent Homology in Chunks. arXiv:1303.0477_ +.. _arXiv:1303.0477: http://arxiv.org/pdf/1303.0477.pdf +.. _`Persistent Homology Algorithm Toolkit`: https://bitbucket.org/phat/phat-code -- cgit v1.2.3 From 833c52094f6a90228901fd9278d1cd68bd3f7bdc Mon Sep 17 00:00:00 2001 From: Bryn Keller Date: Fri, 11 Mar 2016 11:35:37 -0800 Subject: Updated README to use the more pythonic API --- python/README.rst | 51 ++++++++++++++++++++++----------------------------- 1 file changed, 22 insertions(+), 29 deletions(-) (limited to 'python/README.rst') diff --git a/python/README.rst b/python/README.rst index b67ff47..ab4142c 100644 --- a/python/README.rst +++ b/python/README.rst @@ -43,11 +43,8 @@ the algorithm. We provide the following choices of representation classes: Sample usage ------------ -From src/simple_example.py in the source:: +We will build an ordered boundary matrix of this simplicial complex consisting of a single triangle: - print(""" - we will build an ordered boundary matrix of this simplicial complex consisting of a single triangle: - 3 |\\ | \\ @@ -60,45 +57,41 @@ From src/simple_example.py in the source:: |________\\ 0 2 1 - """) +Now the code:: import phat - # set the dimension of the cell that each column represents: - dimensions = [0, 0, 1, 0, 1, 1, 2] - # define a boundary matrix with the chosen internal representation boundary_matrix = phat.boundary_matrix(representation = phat.representations.vector_vector) - # set the respective columns -- the columns entries have to be sorted - boundary_matrix.set_dims(dimensions) - boundary_matrix.set_col(0, []) - boundary_matrix.set_col(1, []) - boundary_matrix.set_col(2, [0,1]) - boundary_matrix.set_col(3, []) - boundary_matrix.set_col(4, [1,3]) - boundary_matrix.set_col(5, [0,3]) - boundary_matrix.set_col(6, [2,4,5]) + # set the respective columns -- (dimension, boundary) pairs + boundary_matrix.columns = [ (0, []), + (0, []), + (1, [0,1]), + (0, []), + (1, [1,3]), + (1, [0,3]), + (2, [2,4,5])] + + # or equivalently, boundary_matrix = phat.boundary_matrix(representation = ..., columns = ...) + # would combine the creation of the matrix and the assignment of the columns # print some information of the boundary matrix: - print() - print("the boundary matrix has %d columns:" % boundary_matrix.get_num_cols()) - for col_idx in range(boundary_matrix.get_num_cols()): - s = "column %d represents a cell of dimension %d." % (col_idx, boundary_matrix.get_dim(col_idx)) - if (not boundary_matrix.is_empty(col_idx)): - s = s + " its boundary consists of the cells " + " ".join([str(c) for c in boundary_matrix.get_col(col_idx)]) + print("\nThe boundary matrix has %d columns:" % len(boundary_matrix.columns)) + for col in boundary_matrix.columns: + s = "Column %d represents a cell of dimension %d." % (col.index, col.dimension) + if (col.boundary): + s = s + " Its boundary consists of the cells " + " ".join([str(c) for c in col.boundary]) print(s) - print("overall, the boundary matrix has %d entries." % boundary_matrix.get_num_entries()) + print("Overall, the boundary matrix has %d entries." % len(boundary_matrix)) - pairs = phat.compute_persistence_pairs(boundary_matrix) + pairs = boundary_matrix.compute_persistence_pairs() pairs.sort() - print() - - print("there are %d persistence pairs: " % len(pairs)) + print("\nThere are %d persistence pairs: " % len(pairs)) for pair in pairs: - print("birth: %d, death: %d" % pair) + print("Birth: %d, Death: %d" % pair) References: -- cgit v1.2.3 From 2e08d6bf56f4c28e1fa583fe4f0f3d539b8dfec3 Mon Sep 17 00:00:00 2001 From: Bryn Keller Date: Fri, 11 Mar 2016 11:50:04 -0800 Subject: Fixed sample complex diagram formatting in readme and doc string --- python/README.rst | 2 +- python/phat.py | 16 +++++++++++----- 2 files changed, 12 insertions(+), 6 deletions(-) (limited to 'python/README.rst') diff --git a/python/README.rst b/python/README.rst index ab4142c..8495e5f 100644 --- a/python/README.rst +++ b/python/README.rst @@ -43,7 +43,7 @@ the algorithm. We provide the following choices of representation classes: Sample usage ------------ -We will build an ordered boundary matrix of this simplicial complex consisting of a single triangle: +We will build an ordered boundary matrix of this simplicial complex consisting of a single triangle:: 3 |\\ diff --git a/python/phat.py b/python/phat.py index 6537b26..ab8a7bc 100644 --- a/python/phat.py +++ b/python/phat.py @@ -6,7 +6,7 @@ algorithms and column data representations. Here is a simple example of usage. -We will build an ordered boundary matrix of this simplicial complex consisting of a single triangle: +We will build an ordered boundary matrix of this simplicial complex consisting of a single triangle:: 3 |\\ @@ -36,11 +36,15 @@ Now the code:: (1, [0,3]), (2, [2,4,5])] - # or equivalently, boundary_matrix = phat.boundary_matrix(representation = ..., columns = ...) - # would combine the creation of the matrix and the assignment of the columns + # or equivalently, + # boundary_matrix = phat.boundary_matrix(representation = ..., + # columns = ...) + # would combine the creation of the matrix and + # the assignment of the columns # print some information of the boundary matrix: - print("\nThe boundary matrix has %d columns:" % len(boundary_matrix.columns)) + print() + print("The boundary matrix has %d columns:" % len(boundary_matrix.columns)) for col in boundary_matrix.columns: s = "Column %d represents a cell of dimension %d." % (col.index, col.dimension) if (col.boundary): @@ -52,10 +56,12 @@ Now the code:: pairs.sort() - print("\nThere are %d persistence pairs: " % len(pairs)) + print() + print("There are %d persistence pairs: " % len(pairs)) for pair in pairs: print("Birth: %d, Death: %d" % pair) + Please see https://bitbucket.org/phat-code/phat/python for more information. """ -- cgit v1.2.3 From 83e49c569c2b53a7068f42df616ed8ee695a0fb8 Mon Sep 17 00:00:00 2001 From: Bryn Keller Date: Mon, 2 May 2016 11:50:31 -0700 Subject: Added readme section on installation, removed code that blocked execution under 2.7. Still needs work to build on desired platforms --- python/README.rst | 18 ++++++++++++++++++ python/setup.py | 3 ++- 2 files changed, 20 insertions(+), 1 deletion(-) (limited to 'python/README.rst') diff --git a/python/README.rst b/python/README.rst index 8495e5f..3fd685d 100644 --- a/python/README.rst +++ b/python/README.rst @@ -40,6 +40,24 @@ the algorithm. We provide the following choices of representation classes: * ``full_pivot_column``: The same idea as in the sparse version. However, instead of a ``std::set``, the pivot column is expanded into a bit vector of size n (the dimension of the matrix). To avoid costly initializations, the class remembers which entries have been manipulated for a pivot column and updates only those entries when another column becomes the pivot. * ``bit_tree_pivot_column`` (default representation): Similar to the ``full_pivot_column`` but the implementation is more efficient. Internally it is a bit-set with fast iteration over nonzero elements, and fast access to the maximal element. +Installation +------------ + +Suppose you have checked out the PHAT repository at location $PHAT. Then you can: + +``` +cd $PHAT/python + +pip install . +``` + +This will install PHAT for whatever Python installation your `pip` executable is associated with. +Also note that this will install dependencies (pybind11) as well. +If you already have pybind11 installed, then `python setup.py install` will most likely work too. + +Currently, the PHAT Python bindings are known to work on Mac OS X with Python 3.5. Other configurations are untested but in progress. +Please let us know if there is a platform you'd like us to support, we will do so if we can. + Sample usage ------------ diff --git a/python/setup.py b/python/setup.py index 5e71cc7..2c6d65d 100644 --- a/python/setup.py +++ b/python/setup.py @@ -2,6 +2,7 @@ from setuptools import setup, Extension, find_packages from setuptools.command.build_ext import build_ext import sys import os.path + ext_modules = [ Extension( '_phat', @@ -14,7 +15,7 @@ ext_modules = [ here = os.path.abspath(os.path.dirname(__file__)) # Get the long description from the README file -with open(os.path.join(here, 'README.rst'), encoding='utf-8') as f: +with open(os.path.join(here, 'README.rst')) as f: long_description = f.read() class BuildExt(build_ext): -- cgit v1.2.3 From a0d647b35e2cd7702eaffbd2074cb2914c6383cd Mon Sep 17 00:00:00 2001 From: Bryn Keller Date: Mon, 2 May 2016 13:23:42 -0700 Subject: Tested with system Python 2.7 on Ubuntu as well as Anaconda Python 3.5 on Ubuntu --- python/README.rst | 14 +++++++++----- python/_phat.cpp | 2 +- python/setup.py | 8 ++++++-- 3 files changed, 16 insertions(+), 8 deletions(-) (limited to 'python/README.rst') diff --git a/python/README.rst b/python/README.rst index 3fd685d..9f7fe41 100644 --- a/python/README.rst +++ b/python/README.rst @@ -48,14 +48,18 @@ Suppose you have checked out the PHAT repository at location $PHAT. Then you can ``` cd $PHAT/python -pip install . +ln -s ../include include # (or copy, we just need $PHAT/include to be in the current folder as well) + +pip install pybind11 + +python setup.py install ``` -This will install PHAT for whatever Python installation your `pip` executable is associated with. -Also note that this will install dependencies (pybind11) as well. -If you already have pybind11 installed, then `python setup.py install` will most likely work too. +This will install PHAT for whatever Python installation your `python` executable is associated with. +Please ensure you use the `pip` that comes from the same directory where your `python` executable lives! -Currently, the PHAT Python bindings are known to work on Mac OS X with Python 3.5. Other configurations are untested but in progress. +Currently, the PHAT Python bindings are known to work on Linux with Python 2.7 and Python 3.5. +Other configurations are untested but in progress. Please let us know if there is a platform you'd like us to support, we will do so if we can. Sample usage diff --git a/python/_phat.cpp b/python/_phat.cpp index 40a9421..9883c97 100644 --- a/python/_phat.cpp +++ b/python/_phat.cpp @@ -227,7 +227,7 @@ void wrap_persistence_pairs(py::module &m) { .def("__len__", &phat::persistence_pairs::get_num_pairs) // Unlike set_pair, this takes a Python 2-tuple .def("__setitem__", - [](phat::persistence_pairs &p, int index, std::pair &pair) { + [](phat::persistence_pairs &p, int index, std::pair pair) { phat::index idx = fix_index(p, index); p.set_pair(idx, pair.first, pair.second); }) diff --git a/python/setup.py b/python/setup.py index 2c6d65d..133a204 100644 --- a/python/setup.py +++ b/python/setup.py @@ -2,12 +2,14 @@ from setuptools import setup, Extension, find_packages from setuptools.command.build_ext import build_ext import sys import os.path +from io import open ext_modules = [ Extension( '_phat', ['_phat.cpp'], - include_dirs=['include', '../include'], + include_dirs=['include', + '../include'], language='c++', ), ] @@ -15,7 +17,7 @@ ext_modules = [ here = os.path.abspath(os.path.dirname(__file__)) # Get the long description from the README file -with open(os.path.join(here, 'README.rst')) as f: +with open(os.path.join(here, 'README.rst'), encoding = 'utf8') as f: long_description = f.read() class BuildExt(build_ext): @@ -31,8 +33,10 @@ class BuildExt(build_ext): def build_extensions(self): ct = self.compiler.compiler_type opts = self.c_opts.get(ct, []) + import pybind11 for ext in self.extensions: ext.extra_compile_args = opts + ext.include_dirs.append(pybind11.get_include()) build_ext.build_extensions(self) setup( -- cgit v1.2.3 From 5e060fd1a8e2f36e7b2a3a0297e1301d89231365 Mon Sep 17 00:00:00 2001 From: Bryn Keller Date: Mon, 2 May 2016 13:32:02 -0700 Subject: Updated to show Linux and Mac both working for 2.7 and 3.5 --- python/README.rst | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'python/README.rst') diff --git a/python/README.rst b/python/README.rst index 9f7fe41..792fc6e 100644 --- a/python/README.rst +++ b/python/README.rst @@ -58,8 +58,15 @@ python setup.py install This will install PHAT for whatever Python installation your `python` executable is associated with. Please ensure you use the `pip` that comes from the same directory where your `python` executable lives! -Currently, the PHAT Python bindings are known to work on Linux with Python 2.7 and Python 3.5. -Other configurations are untested but in progress. +Currently, the PHAT Python bindings are known to work on: + +* Linux with Python 2.7 (tested on Ubuntu 14.04 with system Python) +* Linux with Python 3.5 (tested on Ubuntu 14.04 with Anaconda) +* Mac OS X with Python 2.7 (tested on El Capitan with Anaconda) +* Mac OS X with Python 3.5 (tested on El Capitan with Anaconda) + +Other configurations are untested. + Please let us know if there is a platform you'd like us to support, we will do so if we can. Sample usage -- cgit v1.2.3 From 13f2865522c0201d4bce90f0d4c959883f9b4849 Mon Sep 17 00:00:00 2001 From: Bryn Keller Date: Mon, 2 May 2016 13:35:19 -0700 Subject: RST literal format different from markdown's --- python/README.rst | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'python/README.rst') diff --git a/python/README.rst b/python/README.rst index 792fc6e..0b71257 100644 --- a/python/README.rst +++ b/python/README.rst @@ -45,18 +45,16 @@ Installation Suppose you have checked out the PHAT repository at location $PHAT. Then you can: -``` -cd $PHAT/python + cd $PHAT/python -ln -s ../include include # (or copy, we just need $PHAT/include to be in the current folder as well) + ln -s ../include include # (or copy, we just need $PHAT/include to be in the current folder as well) -pip install pybind11 + pip install pybind11 -python setup.py install -``` + python setup.py install -This will install PHAT for whatever Python installation your `python` executable is associated with. -Please ensure you use the `pip` that comes from the same directory where your `python` executable lives! +This will install PHAT for whatever Python installation your ``python`` executable is associated with. +Please ensure you use the ``pip`` that comes from the same directory where your ``python`` executable lives! Currently, the PHAT Python bindings are known to work on: -- cgit v1.2.3 From a99e8a72971e4e02fef05e40a9ff28057540b754 Mon Sep 17 00:00:00 2001 From: Bryn Keller Date: Mon, 2 May 2016 13:37:04 -0700 Subject: Typo --- python/README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'python/README.rst') diff --git a/python/README.rst b/python/README.rst index 0b71257..9436ae1 100644 --- a/python/README.rst +++ b/python/README.rst @@ -43,7 +43,7 @@ the algorithm. We provide the following choices of representation classes: Installation ------------ -Suppose you have checked out the PHAT repository at location $PHAT. Then you can: +Suppose you have checked out the PHAT repository at location $PHAT. Then you can:: cd $PHAT/python -- cgit v1.2.3 From cdcf5f101523ca2edc497a8de559b2c538ddbd89 Mon Sep 17 00:00:00 2001 From: Bryn Keller Date: Wed, 30 Nov 2016 20:26:34 -0800 Subject: Moved setup.py to root so that we could avoid need for symbolic link. Updated readme.rst and other files to reflect this change, added requirement for enum34 when using python 2.7. Also added explanation that the system python 2.7.10 on Mac OS X is to be avoided. --- python/README.rst | 24 +++++++++++------- python/setup.py | 68 --------------------------------------------------- setup.py | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+), 77 deletions(-) delete mode 100644 python/setup.py create mode 100644 setup.py (limited to 'python/README.rst') diff --git a/python/README.rst b/python/README.rst index 9436ae1..7d9a1e6 100644 --- a/python/README.rst +++ b/python/README.rst @@ -45,26 +45,31 @@ Installation Suppose you have checked out the PHAT repository at location $PHAT. Then you can:: - cd $PHAT/python + cd $PHAT - ln -s ../include include # (or copy, we just need $PHAT/include to be in the current folder as well) + pip install . - pip install pybind11 - - python setup.py install - -This will install PHAT for whatever Python installation your ``python`` executable is associated with. +This will install PHAT for whatever Python installation your ``pip`` executable is associated with. Please ensure you use the ``pip`` that comes from the same directory where your ``python`` executable lives! Currently, the PHAT Python bindings are known to work on: * Linux with Python 2.7 (tested on Ubuntu 14.04 with system Python) * Linux with Python 3.5 (tested on Ubuntu 14.04 with Anaconda) -* Mac OS X with Python 2.7 (tested on El Capitan with Anaconda) -* Mac OS X with Python 3.5 (tested on El Capitan with Anaconda) +* Mac OS X with Python 2.7.12 (tested on Sierra with homebrew) +* Mac OS X with Python 3.5 (tested on Sierra with homebrew) Other configurations are untested. +Please note that this package DOES NOT work with the Python 2.7.10 that ships with the operating +system in Mac OS X. These words of wisdom from `python.org`_ are worth heeding: + + The version of Python that ships with OS X is great for learning but it’s not good for development. + The version shipped with OS X may be out of date from the official current Python release, + which is considered the stable production version. + +We recommend installing Python on Mac OS X using either homebrew or Anaconda, according to your taste. + Please let us know if there is a platform you'd like us to support, we will do so if we can. Sample usage @@ -128,3 +133,4 @@ References: .. [4] U.Bauer, M.Kerber, J.Reininghaus: Clear and Compress: Computing Persistent Homology in Chunks. arXiv:1303.0477_ .. _arXiv:1303.0477: http://arxiv.org/pdf/1303.0477.pdf .. _`Persistent Homology Algorithm Toolkit`: https://bitbucket.org/phat/phat-code +.. _`python.org`:http://docs.python-guide.org/en/latest/starting/install/osx/ diff --git a/python/setup.py b/python/setup.py deleted file mode 100644 index f366e88..0000000 --- a/python/setup.py +++ /dev/null @@ -1,68 +0,0 @@ -from setuptools import setup, Extension, find_packages -from setuptools.command.build_ext import build_ext -import sys -import os.path -from io import open - -if sys.version_info < (2, 7, 11): - print("Sorry, PHAT requires Python 2.7.11 or later") - sys.exit(1) - - -ext_modules = [ - Extension( - '_phat', - ['_phat.cpp'], - include_dirs=['include', - '../include'], - language='c++', - ), -] - -here = os.path.abspath(os.path.dirname(__file__)) - -# Get the long description from the README file -with open(os.path.join(here, 'README.rst'), encoding = 'utf8') as f: - long_description = f.read() - -class BuildExt(build_ext): - """A custom build extension for adding compiler-specific options.""" - c_opts = { - 'msvc': ['/EHsc'], - 'unix': ['-std=c++11'], - } - - if sys.platform == 'darwin': - c_opts['unix'] += ['-stdlib=libc++', '-mmacosx-version-min=10.7'] - - def build_extensions(self): - ct = self.compiler.compiler_type - opts = self.c_opts.get(ct, []) - import pybind11 - for ext in self.extensions: - ext.extra_compile_args = opts - ext.include_dirs.append(pybind11.get_include()) - ext.include_dirs.append(pybind11.get_include(user=True)) - build_ext.build_extensions(self) - -setup( - name='phat', - version='0.0.1', - author='Bryn Keller', - author_email='bryn.keller@intel.com', - url='https://bitbucket.org/phat-code/phat', - description='Python bindings for PHAT', - license = 'LGPL', - keywords='algebraic-topology PHAT distributed topology persistent-homology', - long_description=long_description, - ext_modules=ext_modules, - install_requires=['pybind11'], - cmdclass={'build_ext': BuildExt}, - py_modules = ['phat'], - # packages = find_packages(exclude = ['doc', 'test']) - ) - - - - - diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..6d082d7 --- /dev/null +++ b/setup.py @@ -0,0 +1,73 @@ +from setuptools import setup, Extension, find_packages +from setuptools.command.build_ext import build_ext +import sys +import os.path +from io import open + +if sys.version_info < (2, 7, 12): + print("Sorry, PHAT requires Python 2.7.12 or later") + sys.exit(1) + + +ext_modules = [ + Extension( + '_phat', + ['python/_phat.cpp'], + include_dirs=['include'], + language='c++', + ), +] + +here = os.path.abspath(os.path.dirname(__file__)) + +# Get the long description from the README file +with open(os.path.join(here, 'python', 'README.rst'), encoding = 'utf8') as f: + long_description = f.read() + +class BuildExt(build_ext): + """A custom build extension for adding compiler-specific options.""" + c_opts = { + 'msvc': ['/EHsc'], + 'unix': ['-std=c++11'], + } + + if sys.platform == 'darwin': + c_opts['unix'] += ['-stdlib=libc++', '-mmacosx-version-min=10.7'] + + def build_extensions(self): + ct = self.compiler.compiler_type + opts = self.c_opts.get(ct, []) + import pybind11 + for ext in self.extensions: + ext.extra_compile_args = opts + ext.include_dirs.append(pybind11.get_include()) + ext.include_dirs.append(pybind11.get_include(user=True)) + build_ext.build_extensions(self) + +requires = ['pybind11'] + +if sys.version_info < (3,4,0): + requires.append('enum34') + +setup( + name='phat', + version='0.0.1', + author='Bryn Keller', + author_email='bryn.keller@intel.com', + url='https://bitbucket.org/phat-code/phat', + description='Python bindings for PHAT', + license = 'LGPL', + keywords='algebraic-topology PHAT distributed topology persistent-homology', + long_description=long_description, + ext_modules=ext_modules, + install_requires=requires, + cmdclass={'build_ext': BuildExt}, + package_dir={'':'python'}, + py_modules = ['phat'], + # packages = find_packages(exclude = ['doc', 'test']) + ) + + + + + -- cgit v1.2.3 From d8ef50e225f7abfbf8d085c808e77857827e5274 Mon Sep 17 00:00:00 2001 From: Bryn Keller Date: Thu, 8 Dec 2016 18:14:18 -0800 Subject: Added note that phat module can be installed with pip, without downloading source --- python/README.rst | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'python/README.rst') diff --git a/python/README.rst b/python/README.rst index 7d9a1e6..0c6c391 100644 --- a/python/README.rst +++ b/python/README.rst @@ -43,6 +43,12 @@ the algorithm. We provide the following choices of representation classes: Installation ------------ +If you wish to use the released version of PHAT, you can simply install from PyPI:: + + pip install phat + +Installation from Source +------------------------ Suppose you have checked out the PHAT repository at location $PHAT. Then you can:: cd $PHAT -- cgit v1.2.3