Personal tools
You are here: Home log c/c++ Boost Python
Document Actions

Boost Python

a boost library interfacing between c/c++ and python

2   2006-01-10 build and install Boost Graph Library - Python Bindings

Starting from 1.33.1, it's separated from boost. http://www.osl.iu.edu/~dgregor/bgl-python/

source
download development version: 'svn co https://svn.osl.iu.edu/svn/projects/viz/bgl-python'
get info
README
boost source directory
export BOOST_ROOT=/home/rcf-14/yuhuang/lib/boost/boost_1_33_1
python version
export PYTHON_VERSION=2.2
build
bjam
install boost python library
mv python/libboost_python.so* to somewhere in LD_LIBRARY_PATH
install bgl python package
mv python/boost to somewhere in PYTHONPATH
(python2.2 only)

enumerate is not available in 2.2. add following to boost/graph/docstring.py:

def enumerate(ls):
     ls_to_return = []
     for i in range(len(ls)):
             ls_to_return.append((i,ls[i]))
     return ls_to_return

3   2006-01-10 boost::noncopyable

it's a useful operative.

When there's 'fstream'-related variables in the source file, usual boost.python fails. The error message looks like:

PostFim.cc:105:   instantiated from here
/usr/include/c++/3.3/bits/ios_base.h:668: error: `std::ios_base::ios_base(const std::ios_base&)' is private
/usr/include/boost/python/object/value_holder.hpp:133: error: within this context
/usr/include/c++/3.3/streambuf: In copy constructor  `std::basic_filebuf<char, std::char_traits<char> >::basic_filebuf(const std::basic_filebuf<char, std::char_traits<char> >&)':
/usr/include/c++/3.3/streambuf:921: error:  `std::basic_streambuf<_CharT, _Traits>::basic_streambuf(const std::basic_streambuf<_CharT, _Traits>&) [with _CharT = char, _Traits = std::char_traits<char>]' is private
/usr/include/boost/python/object/value_holder.hpp:133: error: within this context

Have to put boost::noncopyable into module declaration such as _class<PostFime, boost::noncopyable>....

4   2006-01-10 compile a inherited class into python module

The two parent-child classes have to be put into one file because when loading python module, the other(parent) module won't be loaded into memory.

Another way to solve this is to separate the parent-child relationship (copy).

5   2008-04-07 make boost python module standalone

Usually, flag such as -fPIC -shared -lboost_python in g++ transforms the .o file into .so file (dynamic library). Removing -shared used to be enough to make the .o become binary executable.

But now i found out, -lpython2.5 has to be added to make .o become binary executable. Final linking flag is -fPIC -lpython2.5 -lboost_python.

6   2009-11-23 select numpy/numeric array

One example in annot/bin/graph/biclustering.cc:

BOOST_PYTHON_MODULE(biclustering)
{
      boost::python::class_<biclustering>("biclustering", init<double, int, int, int>())
              .def("data_read_in", &biclustering::data_read_in)
              .def("scoring", &biclustering::scoring)
              .def("getbicluster", &biclustering::getbicluster)
              .def("return_matrix_data", &biclustering::return_matrix_data)
              .def_readonly("maxScore", &biclustering::maxScore)
              .def_readonly("minHeight", &biclustering::minHeight)
              .def_readonly("minWidth", &biclustering::minWidth)
              .def_readonly("batchThreshold", &biclustering::batchThreshold)
      ;
      boost::python::class_<bicluster>("bicluster")
              .def_readonly("row_index_list", &bicluster::row_index_list)
              .def_readonly("column_index_list", &bicluster::column_index_list)
              .def_readonly("consensus_list", &bicluster::consensus_list)
              .def_readonly("score", &bicluster::score)
      ;
      def("set_module_and_type", &numeric::array::set_module_and_type);
}
« November 2009 »
Su Mo Tu We Th Fr Sa
1234567
89101112 1314
1516171819 20 21
22232425262728
2930
 

Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: