improved selftest for Eigen::Complex -- mainly a documentation of what does not work

This commit is contained in:
Mark Borgerding 2009-10-28 23:22:10 -04:00
parent 288ba155f1
commit 7911df4b6e
2 changed files with 40 additions and 23 deletions

View File

@ -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> 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> 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<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 #endif
/* vim: set filetype=cpp et sw=2 ts=2 ai: */ /* vim: set filetype=cpp et sw=2 ts=2 ai: */

View File

@ -22,13 +22,12 @@
// License and a copy of the GNU General Public License along with // License and a copy of the GNU General Public License along with
// Eigen. If not, see <http://www.gnu.org/licenses/>. // Eigen. If not, see <http://www.gnu.org/licenses/>.
#ifdef EIGEN_TEST_FUNC #ifdef EIGEN_TEST_FUNC
#include "main.h" # include "main.h"
#else #else
#include <iostream> # include <iostream>
# define CALL_SUBTEST(x) x
#define CALL_SUBTEST(x) x # define VERIFY(x) x
#define VERIFY(x) x # define test_Complex main
#define test_Complex main
#endif #endif
#include <unsupported/Eigen/Complex> #include <unsupported/Eigen/Complex>
@ -47,26 +46,32 @@ void take_std( std::complex<T> * dst, int n )
template <typename T> template <typename T>
void syntax() void syntax()
{ {
vector< Complex<T> > a; // this works fine
a.resize( 9 ); Matrix< Complex<T>, 9, 1> a;
//Complex<T> a[9]; std::complex<T> * pa = &a[0];
Complex<T> b[9]; Complex<T> * pa2 = &a[0];
std::complex<T> * pa = &a[0]; // this works fine
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( 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);
// 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
take_std( pb,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<float>() );
//CALL_SUBTEST( syntax<double>() ); CALL_SUBTEST( syntax<double>() );
//CALL_SUBTEST( syntax<long double>() ); CALL_SUBTEST( syntax<long double>() );
} }