--- a/bindings/python/chain.cpp Tue Apr 14 14:38:08 2009 -0700
+++ b/bindings/python/chain.cpp Wed Apr 15 14:17:21 2009 -0700
@@ -1,15 +1,15 @@
#include <boost/python.hpp>
#include <boost/python/iterator.hpp>
-
namespace bp = boost::python;
#include "chain.h"
+namespace dp = dionysus::python;
void export_chain()
{
- bp::class_<VChain>("Chain")
- .def("__iter__", bp::iterator<VChain>())
- .def("__len__", &VChain::size)
+ bp::class_<dp::VChain>("Chain")
+ .def("__iter__", bp::iterator<dp::VChain>())
+ .def("__len__", &dp::VChain::size)
;
}
--- a/bindings/python/chain.h Tue Apr 14 14:38:08 2009 -0700
+++ b/bindings/python/chain.h Wed Apr 15 14:17:21 2009 -0700
@@ -1,4 +1,9 @@
#include <topology/chain.h>
#include "static-persistence.h"
+namespace dionysus {
+namespace python {
+
typedef SPersistence::Chain VChain;
+
+} } // namespace dionysus::python
--- a/bindings/python/filtration.cpp Tue Apr 14 14:38:08 2009 -0700
+++ b/bindings/python/filtration.cpp Wed Apr 15 14:17:21 2009 -0700
@@ -4,40 +4,41 @@
#include <iostream>
#include <boost/python.hpp>
-using namespace boost::python;
+namespace bp = boost::python;
#include "filtration.h" // defines ListFiltration, ListTraits, ListRandomAccessIterator
#include "utils.h" // defines PythonCmp
+namespace dp = dionysus::python;
-boost::shared_ptr<ListFiltration> init_from_list(list lst, object cmp)
+boost::shared_ptr<dp::ListFiltration> init_from_list(bp::list lst, bp::object cmp)
{
- boost::shared_ptr<ListFiltration> p(new ListFiltration(ListTraits::begin(lst),
- ListTraits::end(lst),
- PythonCmp(cmp)));
+ boost::shared_ptr<dp::ListFiltration> p(new dp::ListFiltration(dp::ListTraits::begin(lst),
+ dp::ListTraits::end(lst),
+ dp::PythonCmp(cmp)));
return p;
}
-FiltrationPythonIterator
-lf_begin(const ListFiltration& lf)
+dp::FiltrationPythonIterator
+lf_begin(const dp::ListFiltration& lf)
{ return lf.begin(); }
-FiltrationPythonIterator
-lf_end(const ListFiltration& lf)
+dp::FiltrationPythonIterator
+lf_end(const dp::ListFiltration& lf)
{ return lf.end(); }
unsigned
-lf_getitem(const ListFiltration& lf, unsigned i)
+lf_getitem(const dp::ListFiltration& lf, unsigned i)
{ return *(lf_begin(lf) + i); }
void export_filtration()
{
- class_<ListFiltration>("Filtration", no_init)
- .def("__init__", make_constructor(&init_from_list))
+ bp::class_<dp::ListFiltration>("Filtration", bp::no_init)
+ .def("__init__", bp::make_constructor(&init_from_list))
.def("__getitem__", &lf_getitem)
- .def("__iter__", range(&lf_begin, &lf_end))
- .def("__len__", &ListFiltration::size)
+ .def("__iter__", bp::range(&lf_begin, &lf_end))
+ .def("__len__", &dp::ListFiltration::size)
;
}
--- a/bindings/python/filtration.h Tue Apr 14 14:38:08 2009 -0700
+++ b/bindings/python/filtration.h Wed Apr 15 14:17:21 2009 -0700
@@ -7,6 +7,9 @@
namespace bp = boost::python;
+namespace dionysus {
+namespace python {
+
// Random access iterator into python's list (using integer indices)
class ListRandomAccessIterator:
public boost::iterator_adaptor<ListRandomAccessIterator, // Derived
@@ -84,4 +87,6 @@
}
};
+} } // namespace dionysus::python
+
#endif
--- a/bindings/python/rips.cpp Tue Apr 14 14:38:08 2009 -0700
+++ b/bindings/python/rips.cpp Wed Apr 15 14:17:21 2009 -0700
@@ -1,33 +1,35 @@
#include <topology/rips.h>
#include <boost/python.hpp>
+namespace bp = boost::python;
+
#include "rips.h" // defines RipsWithDistances
+namespace dp = dionysus::python;
#include <iostream>
-namespace bp = boost::python;
/* Various wrappers for exposing Rips to Python */
// Constructor from distances
-boost::shared_ptr<RipsWithDistances> init_from_distances(bp::object distances)
+boost::shared_ptr<dp::RipsWithDistances> init_from_distances(bp::object distances)
{
- boost::shared_ptr<RipsWithDistances> p(new RipsWithDistances(distances));
+ boost::shared_ptr<dp::RipsWithDistances> p(new dp::RipsWithDistances(distances));
return p;
}
void export_rips()
{
- bp::class_<RipsWithDistances>("Rips", bp::no_init)
- .def("__init__", make_constructor(&init_from_distances))
- .def("generate", &RipsWithDistances::generate)
- .def("generate", &RipsWithDistances::generate_candidates)
- .def("vertex_cofaces", &RipsWithDistances::vertex_cofaces)
- .def("vertex_cofaces", &RipsWithDistances::vertex_cofaces_candidate)
- .def("edge_cofaces", &RipsWithDistances::edge_cofaces)
- .def("edge_cofaces", &RipsWithDistances::edge_cofaces_candidates)
+ bp::class_<dp::RipsWithDistances>("Rips", bp::no_init)
+ .def("__init__", bp::make_constructor(&init_from_distances))
+ .def("generate", &dp::RipsWithDistances::generate)
+ .def("generate", &dp::RipsWithDistances::generate_candidates)
+ .def("vertex_cofaces", &dp::RipsWithDistances::vertex_cofaces)
+ .def("vertex_cofaces", &dp::RipsWithDistances::vertex_cofaces_candidate)
+ .def("edge_cofaces", &dp::RipsWithDistances::edge_cofaces)
+ .def("edge_cofaces", &dp::RipsWithDistances::edge_cofaces_candidates)
- .def("cmp", &RipsWithDistances::cmp)
- .def("cmp", &RipsWithDistances::cmp_native)
- .def("eval", &RipsWithDistances::eval)
- .def("eval", &RipsWithDistances::eval_native)
+ .def("cmp", &dp::RipsWithDistances::cmp)
+ .def("cmp", &dp::RipsWithDistances::cmp_native)
+ .def("eval", &dp::RipsWithDistances::eval)
+ .def("eval", &dp::RipsWithDistances::eval_native)
;
}
--- a/bindings/python/rips.h Tue Apr 14 14:38:08 2009 -0700
+++ b/bindings/python/rips.h Wed Apr 15 14:17:21 2009 -0700
@@ -13,6 +13,8 @@
namespace bp = boost::python;
+namespace dionysus {
+namespace python {
// This strange wrapper is necessary because Rips<...> stores only a const reference to the distances.
// Something on the C++ side of things must store the actual DistancesWrapper object, and that's the
@@ -105,4 +107,6 @@
Evaluator eval_;
};
+} } // namespace dionysus::python
+
#endif
--- a/bindings/python/simplex.cpp Tue Apr 14 14:38:08 2009 -0700
+++ b/bindings/python/simplex.cpp Wed Apr 15 14:17:21 2009 -0700
@@ -6,9 +6,10 @@
#include <boost/python/stl_iterator.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/functional/hash.hpp>
-using namespace boost::python;
+namespace bp = boost::python;
#include "simplex.h" // defines SimplexVD, Vertex, and Data
+namespace dp = dionysus::python;
/* Various wrappers for exposing Simplex to Python */
@@ -22,9 +23,9 @@
// Constructor from iterator
template<class V, class T>
-boost::shared_ptr<Simplex<V,T> > init_from_iterator(object iter)
+boost::shared_ptr<Simplex<V,T> > init_from_iterator(bp::object iter)
{
- boost::shared_ptr<Simplex<V,T> > p(new Simplex<V,T>(stl_input_iterator<V>(iter), stl_input_iterator<V>()));
+ boost::shared_ptr<Simplex<V,T> > p(new Simplex<V,T>(bp::stl_input_iterator<V>(iter), bp::stl_input_iterator<V>()));
return p;
}
@@ -53,25 +54,25 @@
void export_simplex()
{
- class_<SimplexVD>("Simplex")
- .def("__init__", make_constructor(&init_from_iterator<Vertex, Data>))
+ bp::class_<dp::SimplexVD>("Simplex")
+ .def("__init__", bp::make_constructor(&init_from_iterator<dp::Vertex, dp::Data>))
- .def("add", &SimplexVD::add)
- .add_property("boundary", range(&SimplexVD::boundary_begin, &SimplexVD::boundary_end))
- .def("contains", &SimplexVD::contains)
- .def("join", (void (SimplexVD::*)(const SimplexVD&)) &SimplexVD::join)
- .def("dimension", &SimplexVD::dimension)
+ .def("add", &dp::SimplexVD::add)
+ .add_property("boundary", bp::range(&dp::SimplexVD::boundary_begin, &dp::SimplexVD::boundary_end))
+ .def("contains", &dp::SimplexVD::contains)
+ .def("join", (void (dp::SimplexVD::*)(const dp::SimplexVD&)) &dp::SimplexVD::join)
+ .def("dimension", &dp::SimplexVD::dimension)
- .add_property("vertices", range(&vertices_begin<Vertex,Data>, &vertices_end<Vertex,Data>))
- .def(repr(self))
+ .add_property("vertices", bp::range(&vertices_begin<dp::Vertex, dp::Data>, &vertices_end<dp::Vertex, dp::Data>))
+ .def(repr(bp::self))
- .def("__hash__", &hash_simplex<Vertex, Data>)
- .def("__eq__", &eq_simplex<Vertex, Data>)
+ .def("__hash__", &hash_simplex<dp::Vertex, dp::Data>)
+ .def("__eq__", &eq_simplex<dp::Vertex, dp::Data>)
;
- class_<SimplexObject>("SimplexObject")
- .def("__getattribute__", &SimplexObject::getattribute)
+ bp::class_<dp::SimplexObject>("SimplexObject")
+ .def("__getattribute__", &dp::SimplexObject::getattribute)
;
- def("vertex_cmp", &vertex_comparison<Vertex, Data>);
+ bp::def("vertex_cmp", &vertex_comparison<dp::Vertex, dp::Data>);
}
--- a/bindings/python/simplex.h Tue Apr 14 14:38:08 2009 -0700
+++ b/bindings/python/simplex.h Wed Apr 15 14:17:21 2009 -0700
@@ -8,6 +8,9 @@
namespace bp = boost::python;
+namespace dionysus {
+namespace python {
+
/**
* SimplexVD is a base class for Python simplices (it's exposed to python as Simplex)
*
@@ -58,4 +61,6 @@
}
};
+} } // namespace dionysus::python
+
#endif
--- a/bindings/python/static-persistence.cpp Tue Apr 14 14:38:08 2009 -0700
+++ b/bindings/python/static-persistence.cpp Wed Apr 15 14:17:21 2009 -0700
@@ -3,51 +3,52 @@
#include <boost/python.hpp>
#include <boost/python/iterator.hpp>
#include <boost/python/return_internal_reference.hpp>
-using namespace boost::python;
+namespace bp = boost::python;
#include "filtration.h"
#include "static-persistence.h"
#include "chain.h"
+namespace dp = dionysus::python;
/* SPersistence */
-boost::shared_ptr<SPersistence> init_from_filtration(object f)
+boost::shared_ptr<dp::SPersistence> init_from_filtration(bp::object f)
{
- ListFiltration& lf = extract<ListFiltration&>(f);
- boost::shared_ptr<SPersistence> p(new SPersistence(lf));
+ dp::ListFiltration& lf = bp::extract<dp::ListFiltration&>(f);
+ boost::shared_ptr<dp::SPersistence> p(new dp::SPersistence(lf));
return p;
}
-boost::counting_iterator<SPersistenceIndex> py_sp_begin(SPersistence& sp) { return sp.begin(); }
-boost::counting_iterator<SPersistenceIndex> py_sp_end(SPersistence& sp) { return sp.end(); }
-unsigned distance(SPersistence& sp,
- const SPersistenceIndex& i) { return i - sp.begin(); }
+boost::counting_iterator<dp::SPersistenceIndex> py_sp_begin(dp::SPersistence& sp) { return sp.begin(); }
+boost::counting_iterator<dp::SPersistenceIndex> py_sp_end(dp::SPersistence& sp) { return sp.end(); }
+unsigned distance(dp::SPersistence& sp,
+ const dp::SPersistenceIndex& i) { return i - sp.begin(); }
/* SPersistenceIndex */
-SPersistenceIndex pair(const SPersistenceIndex& i) { return i->pair; }
-bool sign(const SPersistenceIndex& i) { return i->sign(); }
-const VChain& cycle(const SPersistenceIndex& i) { return i->cycle; }
-bool index_eq(const SPersistenceIndex& i,
- const SPersistenceIndex& j) { return i == j; }
+dp::SPersistenceIndex pair(const dp::SPersistenceIndex& i) { return i->pair; }
+bool sign(const dp::SPersistenceIndex& i) { return i->sign(); }
+const dp::VChain& cycle(const dp::SPersistenceIndex& i) { return i->cycle; }
+bool index_eq(const dp::SPersistenceIndex& i,
+ const dp::SPersistenceIndex& j) { return i == j; }
void export_static_persistence()
{
- class_<SPersistenceIndex>("SPNode")
+ bp::class_<dp::SPersistenceIndex>("SPNode")
.add_property("pair", &pair)
.def("sign", &sign)
.def("cycle", &cycle, bp::return_internal_reference<1>())
.def("__eq__", index_eq)
;
- class_<SPersistence>("StaticPersistence", no_init)
- .def("__init__", make_constructor(&init_from_filtration))
+ bp::class_<dp::SPersistence>("StaticPersistence", bp::no_init)
+ .def("__init__", bp::make_constructor(&init_from_filtration))
- .def("pair_simplices", (void (SPersistence::*)()) &SPersistence::pair_simplices)
+ .def("pair_simplices", (void (dp::SPersistence::*)()) &dp::SPersistence::pair_simplices)
.def("__call__", &distance)
- .def("__iter__", range(&py_sp_begin, &py_sp_end))
- .def("__len__", &SPersistence::size)
+ .def("__iter__", bp::range(&py_sp_begin, &py_sp_end))
+ .def("__len__", &dp::SPersistence::size)
;
}
--- a/bindings/python/static-persistence.h Tue Apr 14 14:38:08 2009 -0700
+++ b/bindings/python/static-persistence.h Wed Apr 15 14:17:21 2009 -0700
@@ -3,8 +3,13 @@
#include <topology/static-persistence.h>
+namespace dionysus {
+namespace python {
+
typedef StaticPersistence<> SPersistence;
typedef SPersistence::OrderElement SPersistenceNode;
typedef SPersistence::OrderIndex SPersistenceIndex;
+} } // namespace dionysus::python
+
#endif
--- a/bindings/python/utils.h Tue Apr 14 14:38:08 2009 -0700
+++ b/bindings/python/utils.h Wed Apr 15 14:17:21 2009 -0700
@@ -1,14 +1,22 @@
#ifndef __PYTHON_UTILS_H__
#define __PYTHON_UTILS_H__
+#include <boost/python.hpp>
+namespace bp = boost::python;
+
+namespace dionysus {
+namespace python {
+
struct PythonCmp
{
template<class T>
- bool operator()(T x1, T x2) const { return cmp_(x1, x2) < 0; }
+ bool operator()(T x1, T x2) const { return cmp_(x1, x2) < 0; }
- PythonCmp(object cmp): cmp_(cmp) {}
+ PythonCmp(bp::object cmp): cmp_(cmp) {}
- object cmp_;
+ bp::object cmp_;
};
+} } // namespace dionysus::python
+
#endif
--- a/bindings/python/zigzag-persistence.cpp Tue Apr 14 14:38:08 2009 -0700
+++ b/bindings/python/zigzag-persistence.cpp Wed Apr 15 14:17:21 2009 -0700
@@ -8,49 +8,50 @@
#include "zigzag-persistence.h" // defines ZZPersistence, IZZPersistence
#include "optional.h"
+namespace dp = dionysus::python;
// ZigzagPersistence
-bp::tuple zzp_add(ZZPersistence& zzp, bp::object bdry, BirthID birth)
+bp::tuple zzp_add(dp::ZZPersistence& zzp, bp::object bdry, dp::BirthID birth)
{
// Make ZColumn
// NB: it's extremely weird that I have to do it this way,
// but for some reason I cannot just create boundary on the stack
- boost::shared_ptr<ZZPersistence::ZColumn>
- boundary(new ZZPersistence::ZColumn(bp::stl_input_iterator<ZZPersistence::SimplexIndex>(bdry),
- bp::stl_input_iterator<ZZPersistence::SimplexIndex>()));
+ boost::shared_ptr<dp::ZZPersistence::ZColumn>
+ boundary(new dp::ZZPersistence::ZColumn(bp::stl_input_iterator<dp::ZZPersistence::SimplexIndex>(bdry),
+ bp::stl_input_iterator<dp::ZZPersistence::SimplexIndex>()));
boundary->sort(zzp.cmp);
- ZZPersistence::SimplexIndex i;
- ZZPersistence::Death d;
+ dp::ZZPersistence::SimplexIndex i;
+ dp::ZZPersistence::Death d;
boost::tie(i,d) = zzp.add(*boundary, birth);
return bp::make_tuple(i,d);
}
-ZZPersistence::Death zzp_remove(ZZPersistence& zzp, ZZPersistence::SimplexIndex s, ZZPersistence::BirthID birth)
+dp::ZZPersistence::Death zzp_remove(dp::ZZPersistence& zzp, dp::ZZPersistence::SimplexIndex s, dp::ZZPersistence::BirthID birth)
{
return zzp.remove(s, birth);
}
// ImageZigzagPersistence
-bp::tuple izzp_add(IZZPersistence& izzp, bp::object bdry, bool subcomplex, BirthID birth)
+bp::tuple izzp_add(dp::IZZPersistence& izzp, bp::object bdry, bool subcomplex, dp::BirthID birth)
{
// Make ZColumn
// NB: it's extremely weird that I have to do it this way,
// but for some reason I cannot just create boundary on the stack
- boost::shared_ptr<IZZPersistence::ZColumn>
- boundary(new IZZPersistence::ZColumn(bp::stl_input_iterator<IZZPersistence::SimplexIndex>(bdry),
- bp::stl_input_iterator<IZZPersistence::SimplexIndex>()));
+ boost::shared_ptr<dp::IZZPersistence::ZColumn>
+ boundary(new dp::IZZPersistence::ZColumn(bp::stl_input_iterator<dp::IZZPersistence::SimplexIndex>(bdry),
+ bp::stl_input_iterator<dp::IZZPersistence::SimplexIndex>()));
boundary->sort(izzp.cmp);
- IZZPersistence::SimplexIndex i;
- IZZPersistence::Death d;
+ dp::IZZPersistence::SimplexIndex i;
+ dp::IZZPersistence::Death d;
boost::tie(i,d) = izzp.add(*boundary, subcomplex, birth);
return bp::make_tuple(i,d);
}
-IZZPersistence::Death izzp_remove(IZZPersistence& izzp, IZZPersistence::SimplexIndex s, IZZPersistence::BirthID birth)
+dp::IZZPersistence::Death izzp_remove(dp::IZZPersistence& izzp, dp::IZZPersistence::SimplexIndex s, dp::IZZPersistence::BirthID birth)
{
return izzp.remove(s, birth);
}
@@ -66,20 +67,20 @@
void export_zigzag_persistence()
{
- python_optional<BirthID>();
+ python_optional<dp::BirthID>();
- bp::class_<ZZPersistence::SimplexIndex>("SimplexIndex")
- .def("order", &si_order<ZZPersistence::SimplexIndex>);
+ bp::class_<dp::ZZPersistence::SimplexIndex>("SimplexIndex")
+ .def("order", &si_order<dp::ZZPersistence::SimplexIndex>);
- bp::class_<IZZPersistence::SimplexIndex>("ISimplexIndex")
- .def("order", &si_order<IZZPersistence::SimplexIndex>);
+ bp::class_<dp::IZZPersistence::SimplexIndex>("ISimplexIndex")
+ .def("order", &si_order<dp::IZZPersistence::SimplexIndex>);
- bp::class_<ZZPersistence>("ZigzagPersistence")
+ bp::class_<dp::ZZPersistence>("ZigzagPersistence")
.def("add", &zzp_add)
.def("remove", &zzp_remove)
;
- bp::class_<IZZPersistence>("ImageZigzagPersistence")
+ bp::class_<dp::IZZPersistence>("ImageZigzagPersistence")
.def("add", &izzp_add)
.def("remove", &izzp_remove)
;
--- a/bindings/python/zigzag-persistence.h Tue Apr 14 14:38:08 2009 -0700
+++ b/bindings/python/zigzag-persistence.h Wed Apr 15 14:17:21 2009 -0700
@@ -5,6 +5,9 @@
#include <topology/image-zigzag-persistence.h>
#include <boost/python.hpp>
+namespace dionysus {
+namespace python {
+
//typedef int BirthID;
//typedef boost::python::long_ BirthID;
typedef boost::python::object BirthID;
@@ -12,4 +15,6 @@
typedef ZigzagPersistence<BirthID> ZZPersistence;
typedef ImageZigzagPersistence<BirthID> IZZPersistence;
+} } // namespace dionysus::python
+
#endif
--- a/examples/rips/rips.py Tue Apr 14 14:38:08 2009 -0700
+++ b/examples/rips/rips.py Wed Apr 15 14:17:21 2009 -0700
@@ -37,4 +37,4 @@
p = StaticPersistence(f)
p.pair_simplices()
for s in p:
- print s, s.sign()
+ print lst[f[p(s)]], s.sign()