Re: std::complex standard packing requirements was Re: [eigen] FFT for Eigen

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


> 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());
    }
}



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