Re: std::complex standard packing requirements was Re: [eigen] FFT for Eigen |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: std::complex standard packing requirements was Re: [eigen] FFT for Eigen
- From: Rhys Ulerich <rhys.ulerich@xxxxxxxxx>
- Date: Tue, 19 May 2009 16:53:29 -0500
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :from:date:message-id:subject:to:content-type :content-transfer-encoding; bh=MwRVxJxqB4of2SNOKRq/xMhpszsZnp5vc8jYOKWiOvY=; b=fXboFT4QS89cBqDQ9exf+3zYo55ZvSRe6HaPqntJ2mVaqgkIjgY/CQ7ZsvKRWTu1rD dF2h2FsTQVTkt2uDY6o3QKCRU2uYZsrA1+JMH5OUQ7bx6FjYUpyocwFeEx5U9MQNXVPE +UXFJEb/pnNdSEZzwsUXmpTjBUXX3W8VfXu/w=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; b=pibW9xXzD3QTSms2Phe0TwYNpvMhExP1dcwYpD5InWxlZQpEqNbv3UlXde0AtmZQjq 4+PRewbdO8jCsNdhO5oWlTwooW8bv8nlbFP2dfyNq6qqeMt8E4GnYvP8lmi7kfNrJZfE wELIAJTI1mXyVVYUjlbrJPGy0XlzWhZY4XSs8=
> I'd rather see them in the unit-tests, as this kind of thing could end
> up unneededly slowing compilation (for static asserts) and execution
> (normal asserts).
Not particularly sophisticated, but this may be suitable for your unit
tests. This checks some layout assumptions from a code where we're
dealing with the same memory in physical space and fourier space.
Flip the boost stuff over to whatever you like.
- Rhys
// Ensure we can use std::complex<double> as two consecutive doubles
BOOST_AUTO_TEST_CASE( shared_c_array )
{
// Assumption must hold true for any of this scheme to work
BOOST_REQUIRE_EQUAL( sizeof(complex), 2*sizeof(double) );
const std::size_t N = 6;
double carray_double[N] = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0 };
complex *carray_complex = reinterpret_cast<complex *>(carray_double);
for (std::size_t i = 0; i < N / 2; ++i) {
BOOST_CHECK_EQUAL(carray_double[2*i], carray_complex[i].real());
BOOST_CHECK_EQUAL(carray_double[2*i+1], carray_complex[i].imag());
}
for (std::size_t i = 0; i < N / 2; ++i) {
carray_complex[i] += carray_complex[0];
}
for (std::size_t i = 0; i < N / 2; ++i) {
BOOST_CHECK_EQUAL(carray_double[2*i], carray_complex[i].real());
BOOST_CHECK_EQUAL(carray_double[2*i+1], carray_complex[i].imag());
}
}