diff options
author | Mark Borgerding <mark@borgerding.net> | 2009-10-28 23:22:10 -0400 |
---|---|---|
committer | Mark Borgerding <mark@borgerding.net> | 2009-10-28 23:22:10 -0400 |
commit | 7911df4b6e766ecdc57ccbc233e2b454288c5b51 (patch) | |
tree | de1c785049c1a44eb60eb218a69b21f8526eae13 /unsupported | |
parent | 288ba155f1821a31deb70611321082083050239a (diff) |
improved selftest for Eigen::Complex -- mainly a documentation of what does not work
Diffstat (limited to 'unsupported')
-rw-r--r-- | unsupported/Eigen/Complex | 14 | ||||
-rw-r--r-- | unsupported/test/Complex.cpp | 45 |
2 files changed, 38 insertions, 21 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<charT,traits>& ostr, const Complex<T>& rhs) template<class T> Complex<T> sqrt (const Complex<T>&x){return sqrt(ei_to_std(x));} template<class T> Complex<T> tan (const Complex<T>&x){return tan(ei_to_std(x));} template<class T> Complex<T> tanh (const Complex<T>&x){return tanh(ei_to_std(x));} -} + template<typename _Real> struct NumTraits<Complex<_Real> > + { + typedef _Real Real; + typedef Complex<_Real> FloatingPoint; + enum { + IsComplex = 1, + HasFloatingPoint = NumTraits<Real>::HasFloatingPoint, + ReadCost = 2, + AddCost = 2 * NumTraits<Real>::AddCost, + MulCost = 4 * NumTraits<Real>::MulCost + 2 * NumTraits<Real>::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 <http://www.gnu.org/licenses/>. #ifdef EIGEN_TEST_FUNC -#include "main.h" +# include "main.h" #else -#include <iostream> - -#define CALL_SUBTEST(x) x -#define VERIFY(x) x -#define test_Complex main +# include <iostream> +# define CALL_SUBTEST(x) x +# define VERIFY(x) x +# define test_Complex main #endif #include <unsupported/Eigen/Complex> @@ -47,26 +46,32 @@ void take_std( std::complex<T> * dst, int n ) template <typename T> void syntax() { - vector< Complex<T> > a; - a.resize( 9 ); - //Complex<T> a[9]; - Complex<T> b[9]; + // this works fine + Matrix< Complex<T>, 9, 1> a; + std::complex<T> * pa = &a[0]; + Complex<T> * 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<T> *)&a[0],9); - std::complex<T> * pa = &a[0]; // this works fine + // this does not work, but it would be really nice + //vector< Complex<T> > a; + // (on my gcc 4.4.1 ) + // std::vector assumes operator& returns a POD pointer + + // this works fine + Complex<T> b[9]; std::complex<T> * pb = &b[0]; // this works fine - //VERIFY() - // this does not compile: - // take_std( &a[0] , a.size() ); - take_std( pa,9); take_std( pb,9); - //take_std( static_cast<std::complex<T> *>( &a[0] ) , a.size() ); - //take_std( &b[0] , 9 ); } -int test_Complex() +void test_Complex() { CALL_SUBTEST( syntax<float>() ); - //CALL_SUBTEST( syntax<double>() ); - //CALL_SUBTEST( syntax<long double>() ); + CALL_SUBTEST( syntax<double>() ); + CALL_SUBTEST( syntax<long double>() ); } |