Fixed non-POD array problem in homology-zigzags dev
authorDmitriy Morozov <dmitriy@mrzv.org>
Mon, 10 Jun 2013 17:25:57 +0200
branchdev
changeset 275 5f5f4cc70333
parent 274 73d69c01ed6c
child 276 4e136f6afbb5
Fixed non-POD array problem in homology-zigzags
examples/homology-zigzags/M-ZZ.cpp
examples/homology-zigzags/dM-ZZ.cpp
examples/homology-zigzags/iR-ZZ.cpp
examples/homology-zigzags/oR-ZZ.cpp
examples/homology-zigzags/rips-pairwise.cpp
--- a/examples/homology-zigzags/M-ZZ.cpp	Mon Jun 10 16:58:01 2013 +0200
+++ b/examples/homology-zigzags/M-ZZ.cpp	Mon Jun 10 17:25:57 2013 +0200
@@ -80,6 +80,8 @@
                             Smplx::VertexDimensionComparison>       Complex;
 typedef     Zigzag::ZColumn                                         Boundary;
 
+typedef     std::vector<std::list<std::pair<double, double> > >     IntervalsVector;
+
 // Information we need to know when a class dies
 struct      BirthInfo
 {
@@ -91,8 +93,8 @@
 
 // Forward declarations of auxilliary functions
 // Note: min_value is used only for log-scale, so set it up to zero by default
-void write_intervals(std::ostream& out, std::list<std::pair<double,double> >* intervals, int skeleton_dimension, bool logscale, double min_value=0);
-void        report_death(std::list<std::pair<double, double> >* intervals, Death d, DistanceType epsilon, DistanceType birthEpsilon, Dimension skeleton_dimension);
+void write_intervals(std::ostream& out, const IntervalsVector& intervals, int skeleton_dimension, bool logscale, double min_value=0);
+void        report_death(IntervalsVector& intervals, Death d, DistanceType epsilon, DistanceType birthEpsilon, Dimension skeleton_dimension);
 void        make_boundary(const Smplx& s, Complex& c, const Zigzag& zz, Boundary& b);
 std::ostream&   operator<<(std::ostream& out, const BirthInfo& bi);
 void        process_command_line_options(int           argc,
@@ -138,7 +140,7 @@
     PairDistances distances(points);
     
     // Create intervals DS
-    std::list<std::pair<double, double> > intervals [skeleton_dimension];
+    IntervalsVector intervals(skeleton_dimension);
     // for (int i=0; i<skeleton_dimension; i++)
     //   intervals[i] = new std::list<std::pair<double, double> > ();
 
@@ -331,11 +333,11 @@
   return std::log(x) / LOG2;
 }
 
-void write_intervals(std::ostream& out, std::list<std::pair<double,double> >* intervals, int skeleton_dimension, bool logscale, double min_value) {
+void write_intervals(std::ostream& out, const IntervalsVector& intervals, int skeleton_dimension, bool logscale, double min_value) {
   out << "I = { ";
     for (int d = 0; d<skeleton_dimension; d++) {
       out << "[ ";
-      for (std::list<std::pair<double,double> >::iterator pit = intervals[d].begin(); pit != intervals[d].end(); pit++)
+      for (std::list<std::pair<double,double> >::const_iterator pit = intervals[d].begin(); pit != intervals[d].end(); pit++)
 	if (logscale)
 	  out << "[" << log2(std::max(pit->first, min_value)) << ";" << log2(std::max(pit->second, min_value)) << "] ";
 	else
@@ -349,7 +351,7 @@
     out << "} ";
 } 
             
-void        report_death(std::list<std::pair<double,double> >* intervals, Death d, DistanceType epsilon, DistanceType birthEpsilon, Dimension skeleton_dimension)
+void        report_death(IntervalsVector& intervals, Death d, DistanceType epsilon, DistanceType birthEpsilon, Dimension skeleton_dimension)
 {
   // std::cerr << "   d = " << d;
   // if (d)
--- a/examples/homology-zigzags/dM-ZZ.cpp	Mon Jun 10 16:58:01 2013 +0200
+++ b/examples/homology-zigzags/dM-ZZ.cpp	Mon Jun 10 17:25:57 2013 +0200
@@ -73,6 +73,8 @@
                             Smplx::VertexDimensionComparison>       Complex;
 typedef     Zigzag::ZColumn                                         Boundary;
 
+typedef     std::vector<std::list<std::pair<double, double> > >     IntervalsVector;
+
 // Information we need to know when a class dies
 struct      BirthInfo
 {
@@ -84,9 +86,9 @@
 
 // Forward declarations of auxilliary functions
 // Note: min_value is used only for log-scale, so set it up to zero by default
-void write_intervals(std::ostream& out, std::list<std::pair<double,double> >* intervals, int skeleton_dimension, bool logscale, double min_value=0);
+void write_intervals(std::ostream& out, const IntervalsVector& intervals, int skeleton_dimension, bool logscale, double min_value=0);
 // void        report_death(std::ostream& out, Death d, DistanceType epsilon, Dimension skeleton_dimension);
-void        report_death(std::list<std::pair<double, double> >* intervals, Death d, DistanceType epsilon, DistanceType birthEpsilon, Dimension skeleton_dimension);
+void        report_death(IntervalsVector& intervals, Death d, DistanceType epsilon, DistanceType birthEpsilon, Dimension skeleton_dimension);
 void        make_boundary(const Smplx& s, Complex& c, const Zigzag& zz, Boundary& b);
 std::ostream&   operator<<(std::ostream& out, const BirthInfo& bi);
 void        process_command_line_options(int           argc,
@@ -134,7 +136,7 @@
     PairDistances distances(points);
     
     // Create intervals DS
-    std::list<std::pair<double, double> > intervals [skeleton_dimension];
+    IntervalsVector intervals(skeleton_dimension);
     // for (int i=0; i<skeleton_dimension; i++)
     //   intervals[i] = new std::list<std::pair<double, double> > ();
 
@@ -348,11 +350,11 @@
   return std::log(x) / LOG2;
 }
 
-void write_intervals(std::ostream& out, std::list<std::pair<double,double> >* intervals, int skeleton_dimension, bool logscale, double min_value) {
+void write_intervals(std::ostream& out, const IntervalsVector& intervals, int skeleton_dimension, bool logscale, double min_value) {
   out << "I = { ";
     for (int d = 0; d<skeleton_dimension; d++) {
       out << "[ ";
-      for (std::list<std::pair<double,double> >::iterator pit = intervals[d].begin(); pit != intervals[d].end(); pit++)
+      for (std::list<std::pair<double,double> >::const_iterator pit = intervals[d].begin(); pit != intervals[d].end(); pit++)
 	if (logscale)
 	  out << "[" << log2(std::max(pit->first, min_value)) << ";" << log2(std::max(pit->second, min_value)) << "] ";
 	else
@@ -366,7 +368,7 @@
     out << "} ";
 } 
             
-void        report_death(std::list<std::pair<double,double> >* intervals, Death d, DistanceType epsilon, DistanceType birthEpsilon, Dimension skeleton_dimension)
+void        report_death(IntervalsVector& intervals, Death d, DistanceType epsilon, DistanceType birthEpsilon, Dimension skeleton_dimension)
 {
   // std::cerr << "   d = " << d;
   // if (d)
--- a/examples/homology-zigzags/iR-ZZ.cpp	Mon Jun 10 16:58:01 2013 +0200
+++ b/examples/homology-zigzags/iR-ZZ.cpp	Mon Jun 10 17:25:57 2013 +0200
@@ -81,6 +81,8 @@
                             Smplx::VertexDimensionComparison>       Complex;
 typedef     Zigzag::ZColumn                                         Boundary;
 
+typedef     std::vector<std::list<std::pair<double, double> > >     IntervalsVector;
+
 // Information we need to know when a class dies
 struct      BirthInfo
 {
@@ -92,8 +94,8 @@
 
 // Forward declarations of auxilliary functions
 // Note: min_value is used only for log-scale, so set it up to zero by default
-void write_intervals(std::ostream& out, std::list<std::pair<double,double> >* intervals, int skeleton_dimension, bool logscale, double min_value=0);
-void        report_death(std::list<std::pair<double, double> >* intervals, Death d, DistanceType epsilon, DistanceType birthEpsilon, Dimension skeleton_dimension);
+void write_intervals(std::ostream& out, const IntervalsVector& intervals, int skeleton_dimension, bool logscale, double min_value=0);
+void        report_death(IntervalsVector& intervals, Death d, DistanceType epsilon, DistanceType birthEpsilon, Dimension skeleton_dimension);
 // void        report_death(std::ofstream& out, Death d, DistanceType epsilon, Dimension skeleton_dimension);
 void        make_boundary(const Smplx& s, Complex& c, const Zigzag& zz, Boundary& b);
 void        show_image_betti(Zigzag& zz, Dimension skeleton);
@@ -140,7 +142,7 @@
     PairDistances distances(points);
     
     // Create intervals DS
-    std::list<std::pair<double, double> > intervals [skeleton_dimension];
+    IntervalsVector intervals(skeleton_dimension);
     // for (int i=0; i<skeleton_dimension; i++)
     //   intervals[i] = new std::list<std::pair<double, double> > ();
 
@@ -400,11 +402,11 @@
 }
 
 
-void write_intervals(std::ostream& out, std::list<std::pair<double,double> >* intervals, int skeleton_dimension, bool logscale, double min_value) {
+void write_intervals(std::ostream& out, const IntervalsVector& intervals, int skeleton_dimension, bool logscale, double min_value) {
   out << "I = { ";
     for (int d = 0; d<skeleton_dimension; d++) {
       out << "[ ";
-      for (std::list<std::pair<double,double> >::iterator pit = intervals[d].begin(); pit != intervals[d].end(); pit++)
+      for (std::list<std::pair<double,double> >::const_iterator pit = intervals[d].begin(); pit != intervals[d].end(); pit++)
 	if (logscale)
 	  out << "[" << log2(std::max(pit->first, min_value)) << ";" << log2(std::max(pit->second, min_value)) << "] ";
 	else
@@ -418,7 +420,7 @@
     out << "} ";
 } 
             
-void        report_death(std::list<std::pair<double,double> >* intervals, Death d, DistanceType epsilon, DistanceType birthEpsilon, Dimension skeleton_dimension)
+void        report_death(IntervalsVector& intervals, Death d, DistanceType epsilon, DistanceType birthEpsilon, Dimension skeleton_dimension)
 {
   // std::cerr << "   d = " << d;
   // if (d)
--- a/examples/homology-zigzags/oR-ZZ.cpp	Mon Jun 10 16:58:01 2013 +0200
+++ b/examples/homology-zigzags/oR-ZZ.cpp	Mon Jun 10 17:25:57 2013 +0200
@@ -73,6 +73,8 @@
                             Smplx::VertexDimensionComparison>       Complex;
 typedef     Zigzag::ZColumn                                         Boundary;
 
+typedef     std::vector<std::list<std::pair<double, double> > >     IntervalsVector;
+
 // Information we need to know when a class dies
 struct      BirthInfo
 {
@@ -83,9 +85,9 @@
 };
 
 // Forward declarations of auxilliary functions
-void write_intervals(std::ostream& out, std::list<std::pair<double,double> >* intervals, int skeleton_dimension, bool logscale, double min_value=0);
+void write_intervals(std::ostream& out, const IntervalsVector& intervals, int skeleton_dimension, bool logscale, double min_value=0);
 // void        report_death(std::ostream& out, Death d, DistanceType epsilon, Dimension skeleton_dimension);
-void        report_death(std::list<std::pair<double, double> >* intervals, Death d, DistanceType epsilon, DistanceType birthEpsilon, Dimension skeleton_dimension);
+void        report_death(IntervalsVector& intervals, Death d, DistanceType epsilon, DistanceType birthEpsilon, Dimension skeleton_dimension);
 void        make_boundary(const Smplx& s, Complex& c, const Zigzag& zz, Boundary& b);
 std::ostream&   operator<<(std::ostream& out, const BirthInfo& bi);
 void        process_command_line_options(int           argc,
@@ -134,7 +136,7 @@
     PairDistances distances(points);
     
     // Create intervals DS
-    std::list<std::pair<double, double> > intervals [skeleton_dimension];
+    IntervalsVector intervals(skeleton_dimension);
 
     // Order vertices and epsilons (in maxmin fashion)
     VertexVector        vertices;
@@ -396,11 +398,11 @@
 }
 
 
-void write_intervals(std::ostream& out, std::list<std::pair<double,double> >* intervals, int skeleton_dimension, bool logscale, double min_value) {
+void write_intervals(std::ostream& out, const IntervalsVector& intervals, int skeleton_dimension, bool logscale, double min_value) {
   out << "I = { ";
     for (int d = 0; d<skeleton_dimension; d++) {
       out << "[ ";
-      for (std::list<std::pair<double,double> >::iterator pit = intervals[d].begin(); pit != intervals[d].end(); pit++)
+      for (std::list<std::pair<double,double> >::const_iterator pit = intervals[d].begin(); pit != intervals[d].end(); pit++)
 	if (logscale)
 	  out << "[" << log2(std::max(pit->first, min_value)) << ";" << log2(std::max(pit->second, min_value)) << "] ";
 	else
@@ -414,7 +416,7 @@
     out << "} ";
 } 
             
-void        report_death(std::list<std::pair<double,double> >* intervals, Death d, DistanceType epsilon, DistanceType birthEpsilon, Dimension skeleton_dimension)
+void        report_death(IntervalsVector& intervals, Death d, DistanceType epsilon, DistanceType birthEpsilon, Dimension skeleton_dimension)
 {
   // std::cerr << "   d = " << d;
   // if (d)
--- a/examples/homology-zigzags/rips-pairwise.cpp	Mon Jun 10 16:58:01 2013 +0200
+++ b/examples/homology-zigzags/rips-pairwise.cpp	Mon Jun 10 17:25:57 2013 +0200
@@ -57,8 +57,10 @@
 typedef         DynamicPersistenceChains<>                              Persistence;
 typedef         PersistenceDiagram<>                                    PDgm;
 
+typedef         std::vector<std::list<std::pair<double, double> > >     IntervalsVector;
+
 // Forward declarations of auxilliary functions
-void write_intervals(std::ostream& out, std::list<std::pair<double,double> >* intervals, int skeleton_dimension);
+void write_intervals(std::ostream& out, const IntervalsVector& intervals, int skeleton_dimension);
 void            program_options(int argc, char* argv[], std::string& infilename, Dimension& skeleton, DistanceType& max_distance, std::string& diagram_name);
 
 int main(int argc, char* argv[])
@@ -93,7 +95,7 @@
 
 #if 1
     // Create intervals DS
-    std::list<std::pair<double, double> > intervals [skeleton];
+    IntervalsVector intervals(skeleton);
 
     // Output cycles
     Persistence::SimplexMap<Fltr>   m = p.make_simplex_map(f);
@@ -153,11 +155,11 @@
   return std::log(x) / LOG2;
 }
 
-void write_intervals(std::ostream& out, std::list<std::pair<double,double> >* intervals, int skeleton_dimension) {
+void write_intervals(std::ostream& out, const IntervalsVector& intervals, int skeleton_dimension) {
   out << "I = { ";
     for (int d = 0; d<skeleton_dimension; d++) {
       out << "[ ";
-      for (std::list<std::pair<double,double> >::iterator pit = intervals[d].begin(); pit != intervals[d].end(); pit++) {
+      for (std::list<std::pair<double,double> >::const_iterator pit = intervals[d].begin(); pit != intervals[d].end(); pit++) {
 	if (pit->first == 0)
 	  out << "[-Inf;";
         else