[eigen] On std::complex<> default ctor |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen <eigen@xxxxxxxxxxxxxxxxxxx>
- Subject: [eigen] On std::complex<> default ctor
- From: Gael Guennebaud <gael.guennebaud@xxxxxxxxx>
- Date: Wed, 19 Jan 2011 14:12:04 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:from:date:message-id:subject:to :content-type; bh=vZEPW7lE/hCnyqy+uW8MjaO39qjOMRgviS4u6Kg6KlY=; b=ueEqPYAP/svhBzAuonsDUNd+ie7d8qbBUrS1uWwvyR3P2TIyixPDF2jCeQ1Jr3bF2Z FcbQbPIh2WI8K2HFDsvv4vjRRJOMoP0l4O/rcNgqfjvSrl5T5d0VxdptrB9MEQuheOQx rkdRD+oLZrF86VOxVXl/9TErd5V321WJyOCXA=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:from:date:message-id:subject:to:content-type; b=sWKhKD6uaSNZA9a1FmWcXjfz4tIcQTKyNv+Fyk7RlcA3rWP06JJBv2vwC/wmLwAfkc TOOj35W1B2JkwCvwSycBZ6BzwG/PgWTfcTECxFdMYTWr2xLdJrOIBdpYjjDHu+mh9u8r CFJK8Q6jzsXgNJClFoGGwHK1S6LsN/c3hTdXE=
Hi,
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.
gael