diff options
author | Bryn Keller <xoltar@xoltar.org> | 2016-05-02 15:46:07 -0700 |
---|---|---|
committer | Bryn Keller <xoltar@xoltar.org> | 2016-05-02 15:46:07 -0700 |
commit | 2f3ed798d26ae4ab31b0b45e5ef5305c58b28be1 (patch) | |
tree | 9ecb340723da96ba943b49f73311840db2d63ff3 | |
parent | a99e8a72971e4e02fef05e40a9ff28057540b754 (diff) |
Various tweaks to support Python 2.7
-rw-r--r-- | python/_phat.cpp | 13 | ||||
-rw-r--r-- | python/phat.py | 15 | ||||
-rw-r--r-- | python/src/self_test.py | 2 |
3 files changed, 27 insertions, 3 deletions
diff --git a/python/_phat.cpp b/python/_phat.cpp index 9883c97..df7449d 100644 --- a/python/_phat.cpp +++ b/python/_phat.cpp @@ -149,6 +149,16 @@ void wrap_boundary_matrix(py::module &mod, const std::string &representation_suf .def("__eq__", &mat::template operator==<phat::vector_set>) .def("__eq__", &mat::template operator==<phat::vector_list>) + //Python 3.x can figure this out for itself, but Python 2.7 needs to be told: + .def("__ne__", &mat::template operator!=<phat::bit_tree_pivot_column>) + .def("__ne__", &mat::template operator!=<phat::sparse_pivot_column>) + .def("__ne__", &mat::template operator!=<phat::heap_pivot_column>) + .def("__ne__", &mat::template operator!=<phat::full_pivot_column>) + .def("__ne__", &mat::template operator!=<phat::vector_vector>) + .def("__ne__", &mat::template operator!=<phat::vector_heap>) + .def("__ne__", &mat::template operator!=<phat::vector_set>) + .def("__ne__", &mat::template operator!=<phat::vector_list>) + //#### Data access // In `get_col`, since Python is garbage collected, the C++ idiom of passing in a collection @@ -241,6 +251,9 @@ void wrap_persistence_pairs(py::module &m) { .def("clear", &phat::persistence_pairs::clear, "Empties the collection") .def("sort", &phat::persistence_pairs::sort, "Sort in place") .def("__eq__", &phat::persistence_pairs::operator==) + .def("__ne__", [](phat::persistence_pairs &p, phat::persistence_pairs &other) { + return p != other; + }) //#### File operations .def("load_ascii", &phat::persistence_pairs::load_ascii, "Load the contents of a text file into this instance") diff --git a/python/phat.py b/python/phat.py index 0aff4bd..70f5b39 100644 --- a/python/phat.py +++ b/python/phat.py @@ -77,6 +77,7 @@ __all__ = ['boundary_matrix', 'representations', 'reductions'] + class representations(enum.Enum): """Available representations for internal storage of columns in a `boundary_matrix` @@ -89,6 +90,7 @@ class representations(enum.Enum): vector_set = 6 vector_list = 7 + class reductions(enum.Enum): """Available reduction algorithms""" twist_reduction = 1 @@ -97,7 +99,8 @@ class reductions(enum.Enum): row_reduction = 4 spectral_sequence_reduction = 5 -class column: + +class column(object): """A view on one column of data in a boundary matrix""" def __init__(self, matrix, index): """INTERNAL. Columns are created automatically by boundary matrices. @@ -128,7 +131,10 @@ class column: def boundary(self, values): return self._matrix._matrix.set_col(self._index, values) -class boundary_matrix: + def __str__(self): + return "(%d, %s)" % (self.dimension, self.boundary) + +class boundary_matrix(object): """Boundary matrices that store the shape information of a cell complex. """ @@ -201,6 +207,11 @@ class boundary_matrix: def __eq__(self, other): return self._matrix == other._matrix + #Note Python 2.7 needs BOTH __eq__ and __ne__ otherwise you get things that + #are both equal and not equal + def __ne__(self, other): + return self._matrix != other._matrix + def __len__(self): return self._matrix.get_num_entries() diff --git a/python/src/self_test.py b/python/src/self_test.py index 3f85fc1..8017387 100644 --- a/python/src/self_test.py +++ b/python/src/self_test.py @@ -1,3 +1,4 @@ +from __future__ import print_function import sys import phat @@ -157,7 +158,6 @@ if __name__=='__main__': print("Error: [load|save]_vector_vector bug", file=sys.stderr) error = True - if error: sys.exit(1) else: |