[C++-sig] [Boost::Python] Registered class not recognized when returned by reference.

Stefan Seefeld stefan at seefeld.name
Thu Jan 7 09:16:58 EST 2016


hi Eugenio,

is there any reason not to expose Matrix2D via class_<...>, rather than
define a converter ? Wouldn't that solve your problem trivially ?
(I'm not sure I understand the issue yet, but thought that the above
might be an expedient solution.)

HTH,

        Stefan

On 07.01.2016 05:43, Eugenio Bargiacchi wrote:
>
> Hello everyone,
>
> I have a member function with signature
>
> |constMatrix2D&foo const();|
>
> Which returns an internal data structure. |Matrix2D| is
>
> |usingMatrix2D=Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic,Eigen::RowMajor|Eigen::AutoAlign>;|
>
> I have explicitly set a |to_python| converter for |Matrix2D|, and I
> have exported the function with a call policy of
> |return_internal_reference|. However, when this function is called
> from Python I get
>
> |TypeError:NoPythonclassregistered
> forC++classEigen::Matrix<double,-1,-1,1,-1,-1>|
>
> This happens also if the reference is not |const|. At the same time,
> if I modify the call policy to
> |return_value_policy<copy_const_reference>()| Python can decode the
> matrix just fine. The same holds true if I return the |Matrix2D| by
> value. However I really need to have a reference to the matrix in
> order store it into other classes.
>
> How can I make Python see the data structure through the reference?
>
> The converter in case it is needed:
>
> |boost::python::list
> toPythonList(constdouble*data,size_tnum){boost::python::list
> list;for(size_ti =0;i
> <num;++i)list.append(data[i]);returnlist;}structMatrix2DToPython{staticPyObject*convert(Matrix2Dconst&m){boost::python::list
> list;for(inti =0;i
> <m.rows();++i){list.append(toPythonList(m.row(i).data(),m.cols()));}returnboost::python::incref(list.ptr());}};
> Thanks, |
> |Eugenio|
>
>
> _______________________________________________
> Cplusplus-sig mailing list
> Cplusplus-sig at python.org
> https://mail.python.org/mailman/listinfo/cplusplus-sig


-- 

      ...ich hab' noch einen Koffer in Berlin...



More information about the Cplusplus-sig mailing list