Added a __iter__ method to the PersistenceDiagram class in python. Renamed the points iterator to the intervals iterator. dev
authorAravindakshan Babu <akshan@stanford.edu>
Wed, 11 Aug 2010 17:07:09 -0700
branchdev
changeset 218 4f70a473e34b
parent 217 64a272a34cb2
child 219 5311343eb2f5
Added a __iter__ method to the PersistenceDiagram class in python. Renamed the points iterator to the intervals iterator.
bindings/python/dionysus/__init__.py
bindings/python/persistence-diagram.cpp
--- a/bindings/python/dionysus/__init__.py	Thu Jul 08 23:50:39 2010 -0700
+++ b/bindings/python/dionysus/__init__.py	Wed Aug 11 17:07:09 2010 -0700
@@ -36,3 +36,16 @@
         yield point.data
 
 Point.__iter__ = point_iterator
+
+def persistence_diagram_iterator( self ):
+    """
+    This returns a list of lists.
+    Whereas the intervals iterator returns a list of dionysus.Point objects
+    """
+
+    # self.intervals is an iterator object,
+    # whose next method returns a Point object
+    for intv in self.intervals:
+        yield [ x for x in intv ]
+
+PersistenceDiagram.__iter__ = persistence_diagram_iterator
--- a/bindings/python/persistence-diagram.cpp	Thu Jul 08 23:50:39 2010 -0700
+++ b/bindings/python/persistence-diagram.cpp	Wed Aug 11 17:07:09 2010 -0700
@@ -85,7 +85,7 @@
     .def( "__init__", bp::make_constructor(  &init_from_points_sequence< dp::PersistenceDiagramD, dp::PointD > ) )
     .def( bp::init< Dimension >( ) )
     .def( "append", &dp::PersistenceDiagramD::push_back )
-    .add_property( "points", bp::range( &dp::PersistenceDiagramD::begin, &dp::PersistenceDiagramD::end ) )
+    .add_property( "intervals", bp::range( &dp::PersistenceDiagramD::begin, &dp::PersistenceDiagramD::end ) )
     .add_property( "dimension", &get_dimension<dp::PersistenceDiagramD> )
     .def( repr(bp::self) )
     .def( "__sub__", &bottleneck_distance<dp::PersistenceDiagramD,dp::PersistenceDiagramD> )