Re: [eigen] Alignment of a derived class |

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]

*To*: eigen@xxxxxxxxxxxxxxxxxxx*Subject*: Re: [eigen] Alignment of a derived class*From*: Martin Sälzle <martin.saelzle@xxxxxxx>*Date*: Sat, 21 Jul 2012 12:02:09 -0400

Am 20.07.2012 um 12:08 schrieb Gael Guennebaud: > Hi, > >> I have another question: >> >> I saw that you define >> typedef void eigen_aligned_operator_new_marker_type; >> in the macro >> EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF >> in Memory.h >> >> Do you have a structure in Eigen that checks if the typedef is defined, similar to the second example here: >> http://en.wikipedia.org/wiki/SFINAE > > no, and actually I'm not sure eigen_aligned_operator_new_marker_type > is still needed. > >> If Eigen provides this I would not have to define it myself. >> >> Basically what I want to do is to use boost::conditional to check if I have to use the aligned allocator for a vector. > > Boost offers what you need to test if > eigen_aligned_operator_new_marker_type is present. I don't remember in > which package though. > > gael > >> >> thank you, >> Martin Hi, Unfortunately I haven't found anything suitable in boost. I checked boost::enable_if but it seems it is meant to be used in a different way (please correct me if I am wrong). Maybe someone else on the mailing-list knows the package that can do test. I attached a small example. ContainerWithCheck is doing the boost::conditional check. ContainerWithoutCheck simply uses the Eigen::aligned_allocator for every input data. The question is: Is ContainerWithoutCheck <UnAligned> well defined? Because then I could skip all the SFINAE stuff. best regards Martin #include <boost/type_traits/conditional.hpp> #include <Eigen/Core> #include <Eigen/StdVector> template <class T> class HasEigenAlignedOperatorNew { private: typedef char Yes [1]; typedef char No [2]; template <class U> static Yes& test (typename U::eigen_aligned_operator_new_marker_type*); template <class> static No& test (...); public: static const bool value = sizeof (test <T> (0)) == sizeof (Yes); }; struct Aligned { Eigen::Vector4f vec4f; EIGEN_MAKE_ALIGNED_OPERATOR_NEW }; struct UnAligned { int i; }; template <class T> struct ContainerWithCheck { typedef typename boost::conditional <HasEigenAlignedOperatorNew <T>::value, std::vector <T, Eigen::aligned_allocator <T> >, std::vector <T> >::type Vector; Vector storage; }; template <class T> struct ContainerWithoutCheck { typedef std::vector <T, Eigen::aligned_allocator <T> > Vector; Vector storage; }; int main () { ContainerWithCheck <Aligned> c_with_aligned; ContainerWithCheck <UnAligned> c_with_unaligned; ContainerWithoutCheck <Aligned> c_without_aligned; ContainerWithoutCheck <UnAligned> c_without_unaligned; // Any problems here? return (0); }

**References**:**[eigen] Alignment of a derived class***From:*Martin Sälzle

**Re: [eigen] Alignment of a derived class***From:*Gael Guennebaud

**Re: [eigen] Alignment of a derived class***From:*Christoph Hertzberg

**Re: [eigen] Alignment of a derived class***From:*Gael Guennebaud

**Re: [eigen] Alignment of a derived class***From:*Martin Sälzle

**Re: [eigen] Alignment of a derived class***From:*Gael Guennebaud

**Messages sorted by:**[ date | thread ]- Prev by Date:
**Re: [eigen] Map/Block equivalence and vectorization** - Next by Date:
**[eigen] Eigen 3.1.1 released** - Previous by thread:
**Re: [eigen] Alignment of a derived class** - Next by thread:
**Re: [eigen] HELP : matlab data import**

Mail converted by MHonArc 2.6.19+ | http://listengine.tuxfamily.org/ |