bindings/python/static-persistence.cpp
author Dmitriy Morozov <dmitriy@mrzv.org>
Thu, 10 May 2012 14:24:40 -0700
branchdev
changeset 246 88f7806633e0
parent 232 edbbf84fde9e
child 250 021030a8f97c
permissions -rw-r--r--
Exposed init_diagrams() to Python

#include <topology/static-persistence.h>

#include <boost/python.hpp>
#include <boost/python/iterator.hpp>
#include <boost/python/return_internal_reference.hpp>
namespace bp = boost::python;

#include "filtration.h"
#include "static-persistence.h"
#include "chain.h"
namespace dp = dionysus::python;


void                                    pair_simplices(dp::SPersistence& sp)                { sp.pair_simplices(false); }


void export_static_persistence()
{
    bp::class_<dp::SPersistenceNode>("SPNode", bp::no_init)
        .def("pair",            &dp::pair<dp::SPersistenceNode>,        bp::return_internal_reference<1>())
        .add_property("cycle",  &dp::SPersistenceNode::cycle)
        .def("sign",            &dp::SPersistenceNode::sign)
        .def("unpaired",        &dp::SPersistenceNode::unpaired)
    ;

    bp::class_<dp::SPersistence>("StaticPersistence", bp::no_init)
        .def("__init__",        bp::make_constructor(&dp::init_from_filtration<dp::SPersistence>))

        .def("pair_simplices",  &pair_simplices)
        .def("__call__",        &dp::distance<dp::SPersistence, dp::SPersistenceIndex>)
        .def("make_simplex_map",&dp::SPersistence::make_simplex_map<dp::PythonFiltration>)

        .def("__iter__",        bp::range<bp::return_internal_reference<1> >(&dp::SPersistence::begin, &dp::SPersistence::end))
        .def("__len__",         &dp::SPersistence::size)
    ;

    bp::class_<dp::SPersistenceSimplexMap>("SPersistenceSimplexMap", bp::no_init)
        .def("__getitem__",     &dp::psmap_getitem<dp::SPersistenceSimplexMap, dp::SPersistenceIndex>,  bp::return_internal_reference<1>())
    ;
}