Adding a constructor to python object

Help
2013-03-02
2013-05-14
  • How can I add a constructor (from python list) to python interface for ublas::vector? The following approach:

    class_<CVector>("vector")
                .def(init<size_t>())
                .def(init<list>())
                .def("__getitem__", &vector_get_item)
                .def("__setitem__", &vector_set_item)
                .def("resize", &CVector::resize)
                .def("size", &CVector::size);

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

    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.