Wrapper for Eigen and getting base class name from a field of template struct

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Wrapper for Eigen and getting base class name from a field of template struct

Gökçen Eraslan
Hi everyone,

I'm playing around with Swig to see whether I can generate Eigen[1]
bindings for Go (and maybe for other languages as well) which may or may
not be useful for some people.

As a template monster, it's a bit tricky to deal with Eigen. I had to
make some workarounds to solve some annoying preprocessor issues[2] but
I got stuck at some point.

What I'd like to wrap eventually is the Matrix class[3] and some
instances of its templates. Matrix class inherits PlainObjectBase[4]:

template<typename _Scalar, int _Rows, int _Cols, int _Options, int
_MaxRows, int _MaxCols>
class Matrix
  : public PlainObjectBase<Matrix<_Scalar, _Rows, _Cols, _Options,
_MaxRows, _MaxCols> >

Wrappers of this part works fine, so the Matrix wrapper actually
inherits methods from PlainObjectBase. So far so good. However,
PlainObjectBase cannot inherit methods from its parent class because it
gets its base class name from a field of a struct template[5] like this:

template<typename Derived>
class PlainObjectBase : public internal::dense_xpr_base<Derived>::type

where dense_xpr_base is defined as:

template<typename Derived, typename XprKind = typename
struct dense_xpr_base

template<typename Derived>
struct dense_xpr_base<Derived, MatrixXpr>
  typedef MatrixBase<Derived> type;

When I wrap MatrixBase, PlainObjectBase and Matrix classes and
instantiate some of the templates properly, members and methods of
MatrixBase is not passed down to PlainObjectBase and Matrix classes,
which is indicated by this warning by Swig:

Nothing known about base class 'internal::dense_xpr_base<DenseXprXd
>::type'. Ignored.

Is it possible to instantiate this template or solve the problem in any
other way to fully inform Swig about the Matrix class hierarchy?

Here is the interface file I wrote so far:


You can (recursively) clone the repo and run make to reproduce the issue.

Best regards,

[1] https://eigen.tuxfamily.org/

Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
Swig-user mailing list
[hidden email]