[C++-sig] Retrieving lvalues using custom converters (numpy 1-D converters attached)
Neal Becker
ndbecker2 at gmail.com
Fri Oct 3 02:03:58 CEST 2008
Sorry, I'm still confused. Suppose I have this:
ublas::vector<double> create (int size, double init) {
return ublas::vector<double> (size, init);
}
With default return value policy, this fails. We used:
register_vector_to_python_converters< false, contiguous_vector_to_py,
default_ublas_array_traits>();
Which does _not_ copy the data and uses PyArray_SimpleNewFromData. The data is immediately destroyed and the array returned to python is garbage.
It would be nice if the function could return a shared_ptr, which python would manage. This doesn't seem to work:
boost::shared_ptr<ublas::vector<double> > create (int size, double init) {
boost::shared_ptr<ublas::vector<double> > u (new ublas::vector<double> (size, init));
return u;
}
TypeError: No to_python (by-value) converter found for C++ type: boost::shared_ptr<boost::numeric::ublas::vector<double, boost::numeric::ublas::unbounded_array<double, std::allocator<double> > > >
What do you suggest?
More information about the Cplusplus-sig
mailing list