Hello everyone,
I am currently trying to wrap a C++ library[1] that optionally uses
Eigen3 to Python using SWIG. I would like to be able to expose
std::vector<>'s that contain Eigen3 vectors to python using std_vector.i.
However there is big catch:
The library uses Eigen3 as linear algebra package. Due to SSE
requirements some Eigen3 types have to use a special allocator when
storing them in a std::vector. Eigen3 comes with a handy macro that
creates a specialization of std::vector<> that allows to use
std::vector<EigenArrayType>
instead of the more verbose
std::vector<EigenArrayType, Eigen::aligned_allocator<EigenArrayType> >
Basically the macro makes a specialization of
std::vector<EigenArrayType, std::allocator<EigenArrayType> >
but uses internally the Eigen::aligned_allocator<> (see [2])
When creating a typemap like
%template(EigenArrayTypeVectorStdAlloc) std::vector<EigenArrayType>;
I get problems as SWIG has specializations of its own concerning the
allocator and therefore runs into problems when assigning allocators.
I can get it to work when I replace all occurences of
std::vector<EigenArrayType> with the more verbose version, however I
would rather not do this as this would enforce the use of Eigen3 to the
library. Instead I would like to keep nonEigenspecific std::vector<>s
as Eigen is supposed to be a optional dependency.
I have set up a test project located at:
https://bitbucket.org/MartinFelis/eigen3swig
I have also tried to create a modified version of std_vector.i to fix
this, but so far without success.
Does anyone know how one could make this work?
Best regards,
Martin
[1] RBDL, the Rigid Body Dynamics Library (https://rbdl.bitbucket.org)
[2] Specialization of std::vector<> done by the Eigen macro
EIGEN_DEFINE_STL_VECTOR_SPECIALIZATION(Vector3d):
> namespace std {
> template<> class vector<Vector3d, std::allocator<Vector3d> > : public vector<Vector3d, Eigen::aligned_allocator<Vector3d> > {
> typedef vector<Vector3d, Eigen::aligned_allocator<Vector3d> > vector_base;
> public:
> typedef Vector3d value_type;
> typedef vector_base::allocator_type allocator_type;
> typedef vector_base::size_type size_type;
> typedef vector_base::iterator iterator;
> explicit vector(const allocator_type& a = allocator_type()) : vector_base(a) {}
> template<typename InputIterator> vector(InputIterator first, InputIterator last, const allocator_type& a = allocator_type()) : vector_base(first, last, a) {}
> vector(const vector& c) : vector_base(c) {}
> explicit vector(size_type num, const value_type& val = value_type()) : vector_base(num, val) {}
> vector(iterator start, iterator end) : vector_base(start, end) {}
> vector& operator=(const vector& x) {
> vector_base::operator=(x); return *this;
> }
> };
> }

mail : martin.felis@...
phone : +49 6221 544983
office: IWR  Speyerer Str. 6  Room 319  69115 Heidelberg  Germany
