From 7911df4b6e766ecdc57ccbc233e2b454288c5b51 Mon Sep 17 00:00:00 2001 From: Mark Borgerding Date: Wed, 28 Oct 2009 23:22:10 -0400 Subject: [PATCH] improved selftest for Eigen::Complex -- mainly a documentation of what does not work --- unsupported/Eigen/Complex | 14 ++++++++++- unsupported/test/Complex.cpp | 49 ++++++++++++++++++++---------------- 2 files changed, 40 insertions(+), 23 deletions(-) diff --git a/unsupported/Eigen/Complex b/unsupported/Eigen/Complex index 065c0305d..04228c95a 100644 --- a/unsupported/Eigen/Complex +++ b/unsupported/Eigen/Complex @@ -210,8 +210,20 @@ operator<< (std::basic_ostream& ostr, const Complex& rhs) template Complex sqrt (const Complex&x){return sqrt(ei_to_std(x));} template Complex tan (const Complex&x){return tan(ei_to_std(x));} template Complex tanh (const Complex&x){return tanh(ei_to_std(x));} -} + template struct NumTraits > + { + typedef _Real Real; + typedef Complex<_Real> FloatingPoint; + enum { + IsComplex = 1, + HasFloatingPoint = NumTraits::HasFloatingPoint, + ReadCost = 2, + AddCost = 2 * NumTraits::AddCost, + MulCost = 4 * NumTraits::MulCost + 2 * NumTraits::AddCost + }; + }; +} #endif /* vim: set filetype=cpp et sw=2 ts=2 ai: */ diff --git a/unsupported/test/Complex.cpp b/unsupported/test/Complex.cpp index 6360b58e4..bedeb9f27 100644 --- a/unsupported/test/Complex.cpp +++ b/unsupported/test/Complex.cpp @@ -22,13 +22,12 @@ // License and a copy of the GNU General Public License along with // Eigen. If not, see . #ifdef EIGEN_TEST_FUNC -#include "main.h" +# include "main.h" #else -#include - -#define CALL_SUBTEST(x) x -#define VERIFY(x) x -#define test_Complex main +# include +# define CALL_SUBTEST(x) x +# define VERIFY(x) x +# define test_Complex main #endif #include @@ -47,26 +46,32 @@ void take_std( std::complex * dst, int n ) template void syntax() { - vector< Complex > a; - a.resize( 9 ); - //Complex a[9]; - Complex b[9]; - - std::complex * pa = &a[0]; // this works fine - std::complex * pb = &b[0]; // this works fine - //VERIFY() - // this does not compile: - // take_std( &a[0] , a.size() ); - + // this works fine + Matrix< Complex, 9, 1> a; + std::complex * pa = &a[0]; + Complex * pa2 = &a[0]; take_std( pa,9); + + // this does not work, but I wish it would + // take_std(&a[0];) + // this does + take_std( (std::complex *)&a[0],9); + + // this does not work, but it would be really nice + //vector< Complex > a; + // (on my gcc 4.4.1 ) + // std::vector assumes operator& returns a POD pointer + + // this works fine + Complex b[9]; + std::complex * pb = &b[0]; // this works fine + take_std( pb,9); - //take_std( static_cast *>( &a[0] ) , a.size() ); - //take_std( &b[0] , 9 ); } -int test_Complex() +void test_Complex() { CALL_SUBTEST( syntax() ); - //CALL_SUBTEST( syntax() ); - //CALL_SUBTEST( syntax() ); + CALL_SUBTEST( syntax() ); + CALL_SUBTEST( syntax() ); }