[eigen] On std::complex<> default ctor

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


on the forum a user is having some performance issue with a simple code as:

MatrixXcd mat(30000,30000);

which takes about 20secs because std::complex default ctor initialize
the values to zero. (He has 256GB of memory !) Here this is of course
an extreme case, but we are basically hitting a performance hit
anytime we create matrices of complexes. This behavior is also not
very consistent with our default ctor which is supposed not to
initialize the coefficients. I see two approaches to overcome this
issue and waste of time. The easiest way would be to explicitly add
exceptions for complex<float> and complex<double> as follow:

template<> inline std::complex<float>* aligned_new(size_t size)
{ return reinterpret_cast<T*>(aligned_malloc(sizeof(std::complex<float>)*size));

template<> inline std::complex<double>* aligned_new(size_t size)
{ return reinterpret_cast<T*>(aligned_malloc(sizeof(std::complex<double>)*size));

A more general approach would be to encode this information in the
NumTraits struct via a RequireInitialization enum which would be false
by default and could be enabled only for scalar types for which it is
really necessary to call their default ctor. I'm strongly in favor for
this second solution.


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