Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo


Adding a constructor to python object

  • How can I add a constructor (from python list) to python interface for ublas::vector? The following approach:

                .def("__getitem__", &vector_get_item)
                .def("__setitem__", &vector_set_item)
                .def("resize", &CVector::resize)
                .def("size", &CVector::size);

    class CVector: public ublas::vector<TReal> {

    CVector(const list &l) { … }

    doesn't works. The python program exits with the following message

    Boost.Python.ArgumentError: Python argument types in
        some_function(some_class, vector)
    did not match C++ signature:
        some_function(…, boost::numeric::ublas::vector<…>)

    I think that boost doesn't understand that CVector is practically the ublas::vector. Inheriting CVector from "wrapper<ublas::vector<TReal> >" solves this problem. But I need to add "boost::noncopyable" to class_<CVector> while I want to use a function that returns ublas::vector in python. Is it possible not to add "boost::noncopyable" in such case?
    Numpy bindings are not appropriate because I use ublas::vector with custom type for real numbers.