Fixed Python constructor of CohomologyPersistence + minor changes to cocycle.py dev
authorDmitriy Morozov <dmitriy@mrzv.org>
Tue, 12 Jan 2010 14:36:38 -0800
branchdev
changeset 190 6edd7c861bc0
parent 189 e867c6cf02ef
child 191 2d8fba6d1d58
Fixed Python constructor of CohomologyPersistence + minor changes to cocycle.py
bindings/python/cohomology-persistence.cpp
examples/cohomology/cocycle.py
--- a/bindings/python/cohomology-persistence.cpp	Mon Jan 11 10:21:37 2010 -0800
+++ b/bindings/python/cohomology-persistence.cpp	Tue Jan 12 14:36:38 2010 -0800
@@ -12,7 +12,7 @@
 
 
 // CohomPersistence
-boost::shared_ptr<dp::CohomPersistence>     init_from_prime(unsigned p = 11)
+boost::shared_ptr<dp::CohomPersistence>     init_from_prime(unsigned p)
 {
     dp::CohomPersistence::Field field(p);       // Zp
 
@@ -20,6 +20,11 @@
     return chp;
 }
 
+boost::shared_ptr<dp::CohomPersistence>     init()
+{
+    return init_from_prime(11);
+}
+
 
 bp::tuple                                   chp_add(dp::CohomPersistence& chp, 
                                                     bp::object bdry, 
@@ -80,7 +85,8 @@
         .add_property("si",             &dp::CohomPersistence::SNode::si)
     ;
 
-    bp::class_<dp::CohomPersistence>("CohomologyPersistence")
+    bp::class_<dp::CohomPersistence>("CohomologyPersistence", bp::no_init)
+        .def("__init__",        bp::make_constructor(&init))
         .def("__init__",        bp::make_constructor(&init_from_prime))
         .def("add",             &chp_add, (bp::arg("bdry"), bp::arg("birth"), bp::arg("store")=true, bp::arg("image")=true, bp::arg("coefficients")=false))
         
--- a/examples/cohomology/cocycle.py	Mon Jan 11 10:21:37 2010 -0800
+++ b/examples/cohomology/cocycle.py	Tue Jan 12 14:36:38 2010 -0800
@@ -45,7 +45,7 @@
     if not (sum((D*v)**2) < tol and sum((D.T*v)**2) < tol):
         print "Expected a harmonic cocycle:", sum((D*v)**2), sum((D.T*v)**2) 
 
-    return solution[0]        
+    return solution[0], v
 
 
 def vertex_values(solution, vertices):
@@ -77,7 +77,7 @@
     cocycle_list = read_list_file(cocycle_filename)
     vertexmap_list = read_list_file(vertexmap_filename)
 
-    solution = smooth(boundary_list, cocycle_list)
+    solution, v = smooth(boundary_list, cocycle_list)
     values = vertex_values(solution, vertexmap_list)
 
     outfn = os.path.splitext(cocycle_filename)[0] + '.val'